|
ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
|
Bounded RFC 1951 DEFLATE compressor (DEFLATE) - no heap. More...
#include "protocore_config.h"Go to the source code of this file.
Classes | |
| struct | DeflateNs |
| Dispatch table. Addressed by offset, so the layout is asserted below. More... | |
Macros | |
| #define | DEFLATE_SCRATCH_SIZE 4096 |
| Working-memory bytes deflate_raw() needs (hash chains + code tables). | |
Typedefs | |
| typedef enum PROTO_ENUM_PACKED | DeflateResult |
| deflate_raw() return codes (mirror ::InflateResult). | |
Enumerations | |
| enum | PROTO_ENUM_PACKED { DEFLATE_OK = 0 , DEFLATE_ERR_OVERFLOW = -2 , DEFLATE_ERR_SCRATCH = -3 } |
| deflate_raw() return codes (mirror ::InflateResult). More... | |
Functions | |
| PROTOCORE_NS_LAYOUT (DeflateNs, raw) | |
| DeflateResult | protocore_deflate_raw (uint8_t *work, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap, size_t *out_len, void *scratch, size_t scratch_len) |
| Compress src into a raw permessage-deflate payload (RFC 7692): a . | |
Variables | |
| PROTOCORE_NS DeflateNs Deflate | PROTOCORE_UNUSED = {.raw = protocore_deflate_raw} |
| Module namespace. | |
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).
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.
Definition in file deflate.h.
| #define DEFLATE_SCRATCH_SIZE 4096 |
| typedef enum PROTO_ENUM_PACKED DeflateResult |
deflate_raw() return codes (mirror ::InflateResult).
| enum PROTO_ENUM_PACKED |
| PROTOCORE_NS_LAYOUT | ( | DeflateNs | , |
| raw | |||
| ) |
| DeflateResult protocore_deflate_raw | ( | uint8_t * | work, |
| const uint8_t * | src, | ||
| size_t | src_len, | ||
| uint8_t * | dst, | ||
| size_t | dst_cap, | ||
| size_t * | out_len, | ||
| void * | scratch, | ||
| size_t | scratch_len | ||
| ) |
Compress src into a raw permessage-deflate payload (RFC 7692): a .
| work | PROTOCORE_DEFLATE_BORROW bytes the caller took. Not held past the call. |
| src | Src |
| src_len | Src len |
| dst | Dst |
| dst_cap | Dst cap |
| out_len | Out len |
| scratch | Scratch |
| scratch_len | Scratch len |
| PROTOCORE_NS DeflateNs Deflate PROTOCORE_UNUSED = {.raw = protocore_deflate_raw} |