varint

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxLenUvarint63 is the maximum number of bytes representing an uvarint in
	// this encoding, supporting a maximum value of 2^63 (uint63), aka
	// MaxValueUvarint63.
	MaxLenUvarint63 = 9

	// MaxValueUvarint63 is the maximum encodable uint63 value.
	MaxValueUvarint63 = (1 << 63) - 1
)

Variables

View Source
var (
	ErrOverflow   = errors.New("varints larger than uint63 not supported")
	ErrUnderflow  = errors.New("varints malformed, could not reach the end")
	ErrNotMinimal = errors.New("varint not minimally encoded")
)

Functions

func FromUvarint

func FromUvarint(buf []byte) (uint64, int, error)

FromUvarint reads an unsigned varint from the beginning of buf, returns the varint, and the number of bytes read.

func PutUvarint

func PutUvarint(buf []byte, x uint64) int

PutUvarint is an alias for binary.PutUvarint.

This is provided for convenience so users of this library can avoid built-in varint functions and easily audit code for uses of those functions.

Make sure that x is smaller or equal to MaxValueUvarint63, otherwise this function will produce values that may be rejected by readers.

func ReadUvarint

func ReadUvarint(r io.ByteReader) (uint64, error)

ReadUvarint reads a unsigned varint from the given reader.

func ToUvarint

func ToUvarint(num uint64) []byte

ToUvarint converts an unsigned integer to a varint-encoded []byte

func UvarintSize

func UvarintSize(num uint64) int

UvarintSize returns the size (in bytes) of `num` encoded as a unsigned varint.

This may return a size greater than MaxUvarintLen63, which would be an illegal value, and would be rejected by readers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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