github.com/kamalshkeir/kencoding@v0.0.2-0.20230409043843-44b609a0475a/proto/uint64.go (about) 1 package proto 2 3 import "unsafe" 4 5 var uint64Codec = codec{ 6 wire: varint, 7 size: sizeOfUint64, 8 encode: encodeUint64, 9 decode: decodeUint64, 10 } 11 12 func sizeOfUint64(p unsafe.Pointer, flags flags) int { 13 if p != nil { 14 if v := *(*uint64)(p); v != 0 || flags.has(wantzero) { 15 return sizeOfVarint(v) 16 } 17 } 18 return 0 19 } 20 21 func encodeUint64(b []byte, p unsafe.Pointer, flags flags) (int, error) { 22 if p != nil { 23 if v := *(*uint64)(p); v != 0 || flags.has(wantzero) { 24 return encodeVarint(b, v) 25 } 26 } 27 return 0, nil 28 } 29 30 func decodeUint64(b []byte, p unsafe.Pointer, _ flags) (int, error) { 31 v, n, err := decodeVarint(b) 32 *(*uint64)(p) = uint64(v) 33 return n, err 34 } 35 36 var fixed64Codec = codec{ 37 wire: fixed64, 38 size: sizeOfFixed64, 39 encode: encodeFixed64, 40 decode: decodeFixed64, 41 } 42 43 func sizeOfFixed64(p unsafe.Pointer, flags flags) int { 44 if p != nil { 45 if v := *(*uint64)(p); v != 0 || flags.has(wantzero) { 46 return 8 47 } 48 } 49 return 0 50 } 51 52 func encodeFixed64(b []byte, p unsafe.Pointer, flags flags) (int, error) { 53 if p != nil { 54 if v := *(*uint64)(p); v != 0 || flags.has(wantzero) { 55 return encodeLE64(b, v) 56 } 57 } 58 return 0, nil 59 } 60 61 func decodeFixed64(b []byte, p unsafe.Pointer, _ flags) (int, error) { 62 v, n, err := decodeLE64(b) 63 *(*uint64)(p) = v 64 return n, err 65 }