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 uint64, length int) []byte {
2024-01-03 09:56:10 +00:00
byteSlice := make([]byte, length)
binary.LittleEndian.PutUint64(byteSlice, value)
2024-01-03 09:56:10 +00:00
return byteSlice
}
func DecodeEndian(byteSlice []byte) uint64 {
buffer := make([]byte, 8)
copy(buffer, byteSlice)
return binary.LittleEndian.Uint64(buffer)
2024-01-03 09:56:10 +00:00
}