libs5-go/utils/endian.go

17 lines
342 B
Go
Raw Normal View History

2024-01-03 09:56:10 +00:00
package utils
import "encoding/binary"
func EncodeEndian(value uint32, length int) []byte {
byteSlice := make([]byte, length)
binary.LittleEndian.PutUint32(byteSlice, value)
return byteSlice
}
func DecodeEndian(byteSlice []byte) uint32 {
buffer := make([]byte, 4)
copy(buffer, byteSlice)
return binary.LittleEndian.Uint32(buffer)
2024-01-03 09:56:10 +00:00
}