DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
deflate.h File Reference

Bounded RFC 1951 DEFLATE compressor (DEFLATE) - no heap. More...

#include "ServerConfig.h"
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Detailed Description

Bounded RFC 1951 DEFLATE compressor (DEFLATE) - no heap.

The outbound counterpart to inflate.* : a small, host-testable DEFLATE used by WebSocket permessage-deflate (RFC 7692) to compress server-to-client messages. It emits a single fixed-Huffman block (no dynamic tables to build) with LZ77 back-references found over a bounded sliding window, then byte-aligns with an empty stored block and removes the trailing 0x00 0x00 0xff 0xff per RFC 7692 sec 7.2.1 - so the result is a ready-to-frame permessage-deflate payload. The peer's INFLATE re-appends that marker before decompressing (our own RX path does exactly that, see websocket.cpp).

Matching reads from the source buffer itself - there is no kept window across messages, which is correct for no_context_takeover (the mode the handshake negotiates) and bounds memory: distances never exceed DEFLATE_WINDOW and the only working memory is a caller-supplied scratch (DEFLATE_SCRATCH_SIZE bytes, borrowed from the per-dispatch arena, like inflate).

Fixed (not dynamic) Huffman keeps the encoder tiny and deterministic; it never builds an optimal tree, so the ratio is modest, but for the small JSON/text frames this serves it still shrinks the wire while costing no dedicated buffer. If the output would not be smaller than the input the caller simply sends the message uncompressed (the per-message RSV1 flag makes that legal).

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file deflate.h.