Documentation
¶
Overview ¶
Package varint implements ULEB128 (Unsigned Little Endian Base 128) and ZigZag encoding/decoding for arbitrary-precision integers (*big.Int) and standard integer types (uint64, int64). ULEB128 is a variable-length encoding for unsigned integers. ZigZag encoding maps signed integers to unsigned integers so they can be efficiently encoded using ULEB128.
Index ¶
- func UnsignedBytesNeeded(n *big.Int) int
- func UnsignedDecode(buf []byte, offset int) (result *big.Int, length int, err error)
- func UnsignedDecodeToUint64(buf []byte, offset int) (result uint64, length int, err error)
- func UnsignedEncode(n *big.Int) []byte
- func UnsignedEncodeInto(n *big.Int, buf []byte, offset int) int
- func UnsignedEncodeUint64(val uint64) []byte
- func ZigZagDecode(buf []byte, offset int) (result *big.Int, length int, err error)
- func ZigZagDecodeToInt64(buf []byte, offset int) (result int64, length int, err error)
- func ZigZagEncode(n *big.Int) []byte
- func ZigZagEncodeInt64(val int64) []byte
- func ZigZagEncodeInto(n *big.Int, buf []byte, offset int) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnsignedBytesNeeded ¶
UnsignedBytesNeeded calculates the number of bytes required to ULEB128 encode n.
func UnsignedDecode ¶
UnsignedDecode ULEB128 decodes a number from buf starting at offset. It returns the decoded number, the number of bytes read, and an error if any.
func UnsignedDecodeToUint64 ¶
UnsignedDecodeToUint64 ULEB128 decodes to a uint64. Returns an error if the decoded value overflows uint64.
func UnsignedEncode ¶
UnsignedEncode ULEB128 encodes n into a new byte slice.
func UnsignedEncodeInto ¶
UnsignedEncodeInto ULEB128 encodes n into the provided buffer buf starting at offset. It returns the number of bytes written. Panics if the buffer is too small. Callers should ensure buf has enough space, e.g., by using UnsignedBytesNeeded.
func UnsignedEncodeUint64 ¶
UnsignedEncodeUint64 ULEB128 encodes a uint64.
func ZigZagDecode ¶
ZigZagDecode decodes a ZigZag-ULEB128 encoded number from buf. Returns the decoded signed number, bytes read, and an error.
func ZigZagDecodeToInt64 ¶
ZigZagDecodeToInt64 decodes a ZigZag-ULEB128 encoded number to int64. Returns an error if the decoded value overflows int64.
func ZigZagEncode ¶
ZigZagEncode encodes a signed integer n using ZigZag and ULEB128.
func ZigZagEncodeInt64 ¶
ZigZagEncodeInt64 encodes an int64 using ZigZag and ULEB128.
Types ¶
This section is empty.