github.com/kamalshkeir/kencoding@v0.0.2-0.20230409043843-44b609a0475a/proto/size.go (about) 1 package proto 2 3 import ( 4 "math/bits" 5 "unsafe" 6 ) 7 8 type sizeFunc = func(unsafe.Pointer, flags) int 9 10 func sizeOfVarint(v uint64) int { 11 return (bits.Len64(v|1) + 6) / 7 12 } 13 14 func sizeOfVarintZigZag(v int64) int { 15 return sizeOfVarint((uint64(v) << 1) ^ uint64(v>>63)) 16 } 17 18 func sizeOfVarlen(n int) int { 19 return sizeOfVarint(uint64(n)) + n 20 } 21 22 func sizeOfTag(f fieldNumber, t wireType) int { 23 return sizeOfVarint(uint64(f)<<3 | uint64(t)) 24 }