ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
hpack_prim.h File Reference

Low-level field-coding primitives shared by HPACK and QPACK. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  HpackPrimNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Functions

 PROTOCORE_NS_LAYOUT (HpackPrimNs, encode_int, decode_int, huff_encode, huff_len, huff_decode, decode_str, encode_str)
 
size_t protocore_hpack_prim_encode_int (uint8_t *work, uint8_t *out, size_t cap, uint8_t prefix_bits, uint8_t flags, uint32_t value)
 A prefix-prefix_bits integer with the high flags bits set in byte 0.
 
proto_bool protocore_hpack_prim_decode_int (uint8_t *work, const uint8_t *in, size_t len, uint8_t prefix_bits, size_t *consumed, uint32_t *value)
 The same integer back; sets consumed and value, false if malformed.
 
size_t protocore_hpack_prim_huff_encode (uint8_t *work, uint8_t *out, size_t cap, const char *s, size_t n)
 Huffman-encode n bytes of s (RFC 7541 Appendix B); bytes written,.
 
size_t protocore_hpack_prim_huff_len (uint8_t *work, const char *s, size_t n)
 The Huffman byte length of s without encoding it, which is what.
 
proto_bool protocore_hpack_prim_huff_decode (uint8_t *work, const uint8_t *in, size_t n, char *out, size_t cap, size_t *out_len)
 Huffman-decode n bytes into out; sets out_len, false on a bad code.
 
proto_bool protocore_hpack_prim_decode_str (uint8_t *work, const uint8_t *block, size_t len, size_t *pos, char *out, size_t cap, size_t *out_len)
 A length-prefixed string literal (H bit at 0x80 + a 7-bit length .
 
size_t protocore_hpack_prim_encode_str (uint8_t *work, uint8_t *out, size_t cap, const char *s, size_t n)
 The same literal out, Huffman-coded when that is the shorter of the .
 

Variables

PROTOCORE_NS HpackPrimNs HpackPrim PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

Low-level field-coding primitives shared by HPACK and QPACK.

RFC 7541 defines two primitives that RFC 9204 (QPACK) reuses verbatim: the prefix-integer coding (RFC 7541 sec 5.1) and the canonical Huffman code (RFC 7541 Appendix B, referenced by RFC 9204 sec 5). This module is the single copy of both, so HTTP/2's HPACK and HTTP/3's QPACK share one implementation and one Huffman table instead of duplicating ~1 KB of tables.

Pure and host-tested (via the HPACK and QPACK codec tests). Zero heap.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file hpack_prim.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( HpackPrimNs  ,
encode_int  ,
decode_int  ,
huff_encode  ,
huff_len  ,
huff_decode  ,
decode_str  ,
encode_str   
)

◆ protocore_hpack_prim_encode_int()

size_t protocore_hpack_prim_encode_int ( uint8_t *  work,
uint8_t *  out,
size_t  cap,
uint8_t  prefix_bits,
uint8_t  flags,
uint32_t  value 
)

A prefix-prefix_bits integer with the high flags bits set in byte 0.

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
outOut
capCap
prefix_bitsPrefix bits
flagsFlags
valueValue
Returns
The size_t.

◆ protocore_hpack_prim_decode_int()

proto_bool protocore_hpack_prim_decode_int ( uint8_t *  work,
const uint8_t *  in,
size_t  len,
uint8_t  prefix_bits,
size_t *  consumed,
uint32_t *  value 
)

The same integer back; sets consumed and value, false if malformed.

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
inIn
lenLen
prefix_bitsPrefix bits
consumedConsumed
valueValue
Returns
PROTO_TRUE on success.

◆ protocore_hpack_prim_huff_encode()

size_t protocore_hpack_prim_huff_encode ( uint8_t *  work,
uint8_t *  out,
size_t  cap,
const char *  s,
size_t  n 
)

Huffman-encode n bytes of s (RFC 7541 Appendix B); bytes written,.

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
outOut
capCap
sS
nN
Returns
The size_t.

◆ protocore_hpack_prim_huff_len()

size_t protocore_hpack_prim_huff_len ( uint8_t *  work,
const char *  s,
size_t  n 
)

The Huffman byte length of s without encoding it, which is what.

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
sS
nN
Returns
The size_t.

◆ protocore_hpack_prim_huff_decode()

proto_bool protocore_hpack_prim_huff_decode ( uint8_t *  work,
const uint8_t *  in,
size_t  n,
char *  out,
size_t  cap,
size_t *  out_len 
)

Huffman-decode n bytes into out; sets out_len, false on a bad code.

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
inIn
nN
outOut
capCap
out_lenOut len
Returns
PROTO_TRUE on success.

◆ protocore_hpack_prim_decode_str()

proto_bool protocore_hpack_prim_decode_str ( uint8_t *  work,
const uint8_t *  block,
size_t  len,
size_t *  pos,
char *  out,
size_t  cap,
size_t *  out_len 
)

A length-prefixed string literal (H bit at 0x80 + a 7-bit length .

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
blockBlock
lenLen
posPos
outOut
capCap
out_lenOut len
Returns
PROTO_TRUE on success.

◆ protocore_hpack_prim_encode_str()

size_t protocore_hpack_prim_encode_str ( uint8_t *  work,
uint8_t *  out,
size_t  cap,
const char *  s,
size_t  n 
)

The same literal out, Huffman-coded when that is the shorter of the .

Parameters
workPROTOCORE_HPACK_PRIM_BORROW bytes the caller took. Not held past the call.
outOut
capCap
sS
nN
Returns
The size_t.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS HpackPrimNs HpackPrim PROTOCORE_UNUSED
Initial value:
proto_bool protocore_hpack_prim_decode_int(uint8_t *work, const uint8_t *in, size_t len, uint8_t prefix_bits, size_t *consumed, uint32_t *value)
The same integer back; sets consumed and value, false if malformed.
size_t protocore_hpack_prim_huff_len(uint8_t *work, const char *s, size_t n)
The Huffman byte length of s without encoding it, which is what.
proto_bool protocore_hpack_prim_decode_str(uint8_t *work, const uint8_t *block, size_t len, size_t *pos, char *out, size_t cap, size_t *out_len)
A length-prefixed string literal (H bit at 0x80 + a 7-bit length .
size_t protocore_hpack_prim_huff_encode(uint8_t *work, uint8_t *out, size_t cap, const char *s, size_t n)
Huffman-encode n bytes of s (RFC 7541 Appendix B); bytes written,.
size_t protocore_hpack_prim_encode_str(uint8_t *work, uint8_t *out, size_t cap, const char *s, size_t n)
The same literal out, Huffman-coded when that is the shorter of the .
size_t protocore_hpack_prim_encode_int(uint8_t *work, uint8_t *out, size_t cap, uint8_t prefix_bits, uint8_t flags, uint32_t value)
A prefix-prefix_bits integer with the high flags bits set in byte 0.
proto_bool protocore_hpack_prim_huff_decode(uint8_t *work, const uint8_t *in, size_t n, char *out, size_t cap, size_t *out_len)
Huffman-decode n bytes into out; sets out_len, false on a bad code.

Module namespace.

Definition at line 126 of file hpack_prim.h.