3 import "encoding/binary"
5 var trueBytes = []byte{1}
7 func BoolBytes(b bool) (result []byte) {
14 func AsBool(bytes []byte) bool {
15 for _, b := range bytes {
23 func Int64Bytes(n int64) []byte {
27 res := make([]byte, 8)
28 // converting int64 to uint64 is a safe operation that
30 binary.LittleEndian.PutUint64(res, uint64(n))
31 for len(res) > 0 && res[len(res)-1] == 0 {
32 res = res[:len(res)-1]
37 func AsInt64(b []byte) (int64, error) {
48 res := binary.LittleEndian.Uint64(padded[:])
49 // converting uint64 to int64 is a safe operation that
51 return int64(res), nil