Skip to main content

Module varint

Module varint 

Source
Expand description

QUIC variable-length integers (RFC 9000 §16).

Used for the header_len field of the stream preamble. The two most significant bits of the first byte select the encoding length, so the representable range is 0..=2^62-1.

Encoding always uses the shortest form. Decoding accepts any form, including non-minimal ones, exactly as RFC 9000 requires: a peer that pads its length field is unusual but not hostile, and rejecting it would be an interoperability bug rather than a defence.

Enums§

VarintError
Why a varint could not be encoded or decoded.

Constants§

MAX
Largest value a QUIC varint can carry.
MAX_ENCODED_LEN
Longest possible encoding, in bytes.

Functions§

decode_varint
Decodes a varint from the front of input.
encode_varint
Appends value to out in its shortest QUIC varint form.
varint_len
Number of bytes encode_varint will write for value.
write_varint
Writes value into the front of out in its shortest QUIC varint form, and reports how many bytes it took.