h2_varint (h2 v0.6.0)
View SourceQUIC-style Variable-Length Integer Encoding (RFC 9000 Section 16)
Used by HTTP/3 and the Capsule Protocol (RFC 9297). Integers use a variable-length encoding with 1, 2, 4, or 8 bytes. The two most significant bits indicate the encoding length.
2MSB | Length | Usable Bits | Range -----|--------|-------------|------------------ 00 | 1 | 6 | 0-63 01 | 2 | 14 | 0-16383 10 | 4 | 30 | 0-1073741823 11 | 8 | 62 | 0-4611686018427387903
Summary
Functions
Decode a QUIC variable-length integer from binary. Returns {ok, Value, Rest} or {error, Reason}.
Decode with explicit rest return.
Encode an integer to QUIC variable-length format.
Return the encoded size of an integer in bytes.
Functions
-spec decode(binary()) -> {ok, non_neg_integer(), binary()} | {error, term()}.
Decode a QUIC variable-length integer from binary. Returns {ok, Value, Rest} or {error, Reason}.
-spec decode_with_rest(binary()) -> {ok, non_neg_integer(), binary()} | {error, term()}.
Decode with explicit rest return.
-spec encode(non_neg_integer()) -> binary().
Encode an integer to QUIC variable-length format.
-spec encoded_size(non_neg_integer()) -> 1 | 2 | 4 | 8.
Return the encoded size of an integer in bytes.