DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
hpack_prim.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file hpack_prim.h
6 * @brief Low-level field-coding primitives shared by HPACK and QPACK.
7 *
8 * RFC 7541 defines two primitives that RFC 9204 (QPACK) reuses verbatim: the prefix-integer
9 * coding (RFC 7541 sec 5.1) and the canonical Huffman code (RFC 7541 Appendix B, referenced by
10 * RFC 9204 sec 5). This module is the single copy of both, so HTTP/2's HPACK and HTTP/3's QPACK
11 * share one implementation and one Huffman table instead of duplicating ~1 KB of tables.
12 *
13 * Pure and host-tested (via the HPACK and QPACK codec tests). Zero heap.
14 *
15 * @author Douglas Quigg (dstroy0)
16 * @date 2026
17 */
18
19#ifndef DETERMINISTICESPASYNCWEBSERVER_HPACK_PRIM_H
20#define DETERMINISTICESPASYNCWEBSERVER_HPACK_PRIM_H
21
22#include "ServerConfig.h"
23
24#if DETWS_ENABLE_HTTP2 || DETWS_ENABLE_HTTP3
25
26#include <stddef.h>
27#include <stdint.h>
28
29/** @brief Encode a prefix-@p prefix_bits integer with the high @p flags bits set in byte 0. */
30size_t hpack_encode_int(uint8_t *out, size_t cap, uint8_t prefix_bits, uint8_t flags, uint32_t value);
31/** @brief Decode a prefix-@p prefix_bits integer; sets @p consumed / @p value. @return false if malformed. */
32bool hpack_decode_int(const uint8_t *in, size_t len, uint8_t prefix_bits, size_t *consumed, uint32_t *value);
33/** @brief Huffman-encode @p n bytes of @p s (RFC 7541 Appendix B). @return bytes written or 0 on overflow. */
34size_t hpack_huff_encode(uint8_t *out, size_t cap, const char *s, size_t n);
35/** @brief Huffman byte length of @p s without encoding (to choose Huffman vs raw). */
36size_t hpack_huff_len(const char *s, size_t n);
37/** @brief Huffman-decode @p n bytes into @p out; sets @p out_len. @return false on a bad code. */
38bool hpack_huff_decode(const uint8_t *in, size_t n, char *out, size_t cap, size_t *out_len);
39
40#endif // DETWS_ENABLE_HTTP2 || DETWS_ENABLE_HTTP3
41#endif // DETERMINISTICESPASYNCWEBSERVER_HPACK_PRIM_H
User-facing configuration for DeterministicESPAsyncWebServer.