varint

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnsignedBytesNeeded

func UnsignedBytesNeeded(n *big.Int) int

UnsignedBytesNeeded calculates the number of bytes required to ULEB128 encode n.

func UnsignedDecode

func UnsignedDecode(buf []byte, offset int) (result *big.Int, length int, err error)

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

func UnsignedDecodeToUint64(buf []byte, offset int) (result uint64, length int, err error)

UnsignedDecodeToUint64 ULEB128 decodes to a uint64. Returns an error if the decoded value overflows uint64.

func UnsignedEncode

func UnsignedEncode(n *big.Int) []byte

UnsignedEncode ULEB128 encodes n into a new byte slice.

func UnsignedEncodeInto

func UnsignedEncodeInto(n *big.Int, buf []byte, offset int) int

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

func UnsignedEncodeUint64(val uint64) []byte

UnsignedEncodeUint64 ULEB128 encodes a uint64.

func ZigZagDecode

func ZigZagDecode(buf []byte, offset int) (result *big.Int, length int, err error)

ZigZagDecode decodes a ZigZag-ULEB128 encoded number from buf. Returns the decoded signed number, bytes read, and an error.

func ZigZagDecodeToInt64

func ZigZagDecodeToInt64(buf []byte, offset int) (result int64, length int, err error)

ZigZagDecodeToInt64 decodes a ZigZag-ULEB128 encoded number to int64. Returns an error if the decoded value overflows int64.

func ZigZagEncode

func ZigZagEncode(n *big.Int) []byte

ZigZagEncode encodes a signed integer n using ZigZag and ULEB128.

func ZigZagEncodeInt64

func ZigZagEncodeInt64(val int64) []byte

ZigZagEncodeInt64 encodes an int64 using ZigZag and ULEB128.

func ZigZagEncodeInto

func ZigZagEncodeInto(n *big.Int, buf []byte, offset int) int

ZigZagEncodeInto encodes a signed integer n into buf using ZigZag and ULEB128. Returns the number of bytes written. Panics if the buffer is too small.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL