nhttp_str (nhttp_lib v1.0.0)
View SourceString literal codec for HPACK and QPACK.
Implements the string literal representation shared by HPACK (RFC 7541 Section 5.2) and QPACK (RFC 9204 Section 4.1.2). A string literal is encoded as:
H (1 bit) | Length (7-bit prefixed integer) | Data (Length bytes)When H=1 the data is Huffman-coded using the static table from RFC 7541 Appendix B. When H=0 the data is the raw octets.
Summary
Types
Functions
-spec decode(bitstring()) -> {ok, binary(), bitstring()} | {error, decode_error()}.
Decode a string literal from a bitstring.
Reads the H-bit, decodes the 7-bit-prefixed length, extracts that many bytes, and optionally Huffman-decodes the result. Returns the decoded string and the unconsumed remainder.
Encode a binary as a string literal.
When Huffman is true, the string is Huffman-encoded and the H-bit
is set. When false, the raw bytes are written with H=0.