~/Projects/sing
git clone https://code.lsong.org/sing
Commit
- Commit
- 6045339c12d405f8906eea56e9e2ff6707057b3c
- Author
- 世界 <[email protected]>
- Date
- 2022-07-29 19:03:36 +0800 +0800
- Diffstat
common/rw/varinat.go | 9 +++++++++
Add UVariantLen
diff --git a/common/rw/varinat.go b/common/rw/varinat.go index 48040ac27d24237ab761a7b4573d6546efdcd551..9f1be44c3498ba01ba31c90a4dfdcb38ed382ae5 100644 --- a/common/rw/varinat.go +++ b/common/rw/varinat.go @@ -26,6 +26,15 @@ func ReadUVariant(reader io.Reader) (uint64, error) { return binary.ReadUvarint(ToByteReader(reader)) } +func UVariantLen(x uint64) int { + i := 0 + for x >= 0x80 { + x >>= 7 + i++ + } + return i + 1 +} + func WriteUVariant(writer io.Writer, value uint64) error { var b [8]byte return common.Error(writer.Write(b[:binary.PutUvarint(b[:], value)]))