h1_varint (h1 v0.2.0)

View Source

QUIC-style Variable-Length Integer Encoding (RFC 9000 Section 16)

Used by the HTTP 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

Adapted verbatim from erlang_h2/src/h2_varint.erl.

Summary

Functions

decode(Bin)

-spec decode(binary()) -> {ok, non_neg_integer(), binary()} | {error, term()}.

decode_with_rest(Bin)

-spec decode_with_rest(binary()) -> {ok, non_neg_integer(), binary()} | {error, term()}.

encode(N)

-spec encode(non_neg_integer()) -> binary().

encoded_size(N)

-spec encoded_size(non_neg_integer()) -> 1 | 2 | 4 | 8.