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 ¶
- func Read[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](r io.ByteReader) (T, error)
- func ReadMinimal[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](r io.ByteReader) (T, error)
- func Size[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](n T) int
- func Write[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](w io.ByteWriter, i T) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Read ¶
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 ¶
ReadMinimal works like Read but returns an error if the VLQ is not minimally encoded (i.e. if it starts with a 0x80 byte).
Types ¶
This section is empty.