vlq

package
v0.0.0-...-d87cace Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package vlq implements Variable-length quantity encoding as used in MIDI or BER. A VLQ is essentially a base-128 representation of an unsigned integer with the addition of the eighth bit to mark continuation of bytes. VLQ is identical to LEB128 except in endianness.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](r io.ByteReader) (T, error)

Read parses an unsigned VLQ from r. The maximum allowed value is limited by the size of T.

Read will only read bytes belonging to the encoded VLQ. If r returns io.EOF on the first read, the returned error will be io.EOF as well.

Read ignores an arbitrary amount of leading zeros (encoded as 0x80 bytes). Use ReadMinimal to parse a minimally-encoded VLQ.

func ReadMinimal

func ReadMinimal[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](r io.ByteReader) (T, error)

ReadMinimal works like Read but returns an error if the VLQ is not minimally encoded (i.e. if it starts with a 0x80 byte).

func Size

func Size[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](n T) int

Size returns the number of bytes needed to encode n as a VLQ.

func Write

func Write[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](w io.ByteWriter, i T) (n int, err error)

Write encodes i as a VLQ into w. Any error returned by w is returned by this function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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