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