hopp/codec/measure.go

23 lines
403 B
Go

package codec
// GBEUSize returns the size (in octets) of a GBEU integer.
func GBEUSize(value uint64) int {
length := 0
for {
value >>= 7
length ++
if value == 0 { return length }
}
}
// IntBytes returns the number of bytes required to hold a given unsigned
// integer.
func IntBytes(value uint64) int {
bytes := 0
for value > 0 || bytes == 0 {
value >>= 8;
bytes ++
}
return bytes
}