Skip to content

vlqDecoder

const vlqDecoder: Decoder<number>

Defined in: packages/format-varint/src/vlq/vlq-decoder.ts:28

A base-128 VLQ as a streaming Decoder.

A VLQ delimits itself — the extent is only known once a byte without the continuation bit arrives — so a truncated sequence is incomplete rather than an error, and needAtLeast is deliberately omitted: a decoder that cannot see the end cannot compute a floor better than “one more byte”.

Stateless, so one instance serves every caller and reset is unnecessary.

A malformed sequence is fatal: an overlong or out-of-range value means the byte stream is not what it claimed to be, and there is no length to resynchronise past. Callers reading a VLQ from inside an already-framed region — ASN.1 tag numbers and OID arcs, where an enclosing TLV bounds the value — want readVlq instead, where running out of bytes is a malformed frame rather than a request for more input.