QUIC encodes integers in a self-describing format where the two
most-significant bits of the first byte select the encoding length:
| 2 MSB |
Length |
Usable bits |
Range |
| 0b00 |
1 |
6 |
0 .. 63 |
| 0b01 |
2 |
14 |
0 .. 16,383 |
| 0b10 |
4 |
30 |
0 .. 1,073,741,823 |
| 0b11 |
8 |
62 |
0 .. 4,611,686,018,427,387,903 |
All multi-byte forms are big-endian. The two-bit length tag lives
in the highest two bits of the first byte; the remaining bits of
that byte are part of the value.
This module is intentionally sans-I/O: every function takes either
a buffer slice or a value and returns the other, with no socket
state. The codec is the load-bearing primitive for every other
QUIC frame: STREAM frame offsets, packet numbers, frame types,
ACK ranges -- everything is varint-encoded.
References:
- RFC 9000 §16 "Variable-Length Integer Encoding".
- aioquic
buffer.pull_uint_var / buffer.push_uint_var
(the Python reference implementation we cross-validate against).