quic_qpack_huffman (quic v1.3.1)

View Source

Huffman encoding and decoding for QPACK (RFC 9204).

RFC 7541 Appendix B defines the Huffman code table used by both HPACK (HTTP/2) and QPACK (HTTP/3). This module provides encoding and decoding functions.

Summary

Functions

Decode a Huffman-encoded binary. Returns the decoded binary string. Note: This function does not validate EOS padding per RFC 7541 Section 5.2. Use decode_safe/1 for strict validation.

Decode a Huffman-encoded binary with strict validation. Returns {ok, Decoded} on success, {error, Reason} on failure. Per RFC 7541 Section 5.2: - Padding MUST be the most-significant bits of EOS symbol (all 1s) - Padding MUST NOT be more than 7 bits - A string literal containing EOS MUST be treated as decoding error

Encode a binary string using Huffman coding. Returns the Huffman-encoded binary, padded with EOS bits.

Calculate the size in bytes of Huffman-encoded data. Useful for deciding whether Huffman encoding is beneficial.

Functions

decode(Data)

-spec decode(binary()) -> binary().

Decode a Huffman-encoded binary. Returns the decoded binary string. Note: This function does not validate EOS padding per RFC 7541 Section 5.2. Use decode_safe/1 for strict validation.

decode_safe(Data)

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

Decode a Huffman-encoded binary with strict validation. Returns {ok, Decoded} on success, {error, Reason} on failure. Per RFC 7541 Section 5.2: - Padding MUST be the most-significant bits of EOS symbol (all 1s) - Padding MUST NOT be more than 7 bits - A string literal containing EOS MUST be treated as decoding error

encode(Data)

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

Encode a binary string using Huffman coding. Returns the Huffman-encoded binary, padded with EOS bits.

encoded_size(Data)

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

Calculate the size in bytes of Huffman-encoded data. Useful for deciding whether Huffman encoding is beneficial.