nhttp_str (nhttp_lib v1.0.0)

View Source

String 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

Functions

Decode a string literal from a bitstring.

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.

Types

decode_error()

-type decode_error() :: incomplete | invalid_huffman.

Functions

decode/1

-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/2

-spec encode(binary(), boolean()) -> iolist().

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.