Skip to content

encodeQuicVarint

encodeQuicVarint(value): Uint8Array<ArrayBuffer>

Defined in: packages/format-varint/src/quic/encode-quic-varint.ts:21

Encodes a non-negative integer as a QUIC variable-length integer (RFC 9000 §16): a two-bit length prefix in the first byte, then the value big-endian in 1, 2, 4 or 8 bytes. Always the shortest form.

Used throughout QUIC, HTTP/3 (RFC 9114) and HTTP datagrams and capsules (RFC 9297). Unlike the continuation-bit members of this package, the length is known from the first byte.

Time complexity: O(1).

number

A non-negative safe integer. QUIC allows up to 2^62 - 1; this function stops at Number.MAX_SAFE_INTEGER.

Uint8Array<ArrayBuffer>

A fresh buffer of 1, 2, 4 or 8 bytes.

When value is negative, fractional, or beyond Number.MAX_SAFE_INTEGER.