Search Apps Documentation Source Content File Folder Download Copy Actions Download

encoding.gno

0.46 Kb · 21 lines
 1package encoding
 2
 3import "encoding/binary"
 4
 5// Uint64ToBigEndian - marshals uint64 to a bigendian byte slice so it can be
 6// sorted
 7func Uint64ToBigEndian(i uint64) []byte {
 8	b := make([]byte, 8)
 9	binary.BigEndian.PutUint64(b, i)
10	return b
11}
12
13// BigEndianToUint64 returns an uint64 from big endian encoded bytes. If
14// encoding is empty, zero is returned.
15func BigEndianToUint64(bz []byte) uint64 {
16	if len(bz) == 0 {
17		return 0
18	}
19
20	return binary.BigEndian.Uint64(bz)
21}