Skip to content

readVlq

readVlq(reader): number

Defined in: packages/format-varint/src/vlq/read-vlq.ts:34

Reads one base-128 VLQ from reader, advancing it past the bytes consumed.

Allocates nothing: the cursor carries the position, so a caller decoding a run of values (an OID’s arcs, a MIDI track’s delta times) pays one ByteReader for the run rather than one result object per value.

Rejects an overlong encoding — a leading 0x80 byte, whose payload group is zero — because X.690 §8.19.2 requires the fewest possible octets, and an accepted overlong form would let two byte sequences mean the same number.

Time complexity: O(log₁₂₈ value).

ByteReader

Cursor positioned at the first byte of the encoding.

number

The decoded value, from 0 to Number.MAX_SAFE_INTEGER.

When the bytes run out while a continuation bit is still set.

When the encoding is overlong.

When the value is too large for a number. X.660 puts no ceiling on an OID arc, so such an encoding is well-formed and readBigVlq reads it — the limit is this function’s return type, not the data.