nhttp_huffman (nhttp_lib v1.0.0)
View SourceStatic Huffman encoder/decoder for HPACK (RFC 7541 Appendix B).
This module implements the static Huffman table used by HPACK for HTTP/2 header compression. The code table is optimized for HTTP header values with common ASCII characters having shorter codes.
Decoding uses a generated 4-bit (nibble) finite state machine: each state is a function clause that consumes one nibble of the input and emits decoded bytes, which the BEAM compiles to a per-state jump table. The encode function uses bit accumulation with proper EOS padding.
Summary
Types
Functions
-spec decode(Data :: binary()) -> {ok, Decoded :: binary()} | {error, decode_error()}.
Decode a complete Huffman-encoded binary.
The input is a whole number of octets terminated by EOS padding (1-7
all-ones bits) to the byte boundary, as required by RFC 7541 Section
5.2. Returns {ok, Decoded}, or {error, invalid_huffman} if the
encoding is invalid (a non-all-ones or over-long pad, or an invalid
code).
Encode a binary using the HPACK Huffman table.
The encoded binary is padded with EOS (all 1s) to the next byte boundary as required by RFC 7541 Section 5.2.