Skip to main content

Module compression

Module compression 

Source
Expand description

Client-side helpers for the Codec compression contract.

Rust twin of codecai.compression (Python): the server emits Codec-Zstd-Dict: sha256:<hex> on every zstd response, the client validates that header against locally-loaded dicts before decompressing. See spec/PROTOCOL.md “Codec-Zstd-Dict response header” (stable since v0.2) for the full contract.

The actual zstd decompression is intentionally out of scope here — callers usually already have an HTTP stack and pick their own zstd binding (zstd crate, zstd-safe, an FFI wrapper, etc.). This module just gives you the small piece that’s specific to Codec: matching a response’s declared dict hash to the dict you’ve loaded, with the case-insensitive header lookup and fail-fast semantics the spec mandates.

Wrong-dict decompression produces garbage bytes that downstream msgpack / protobuf parsers will silently misinterpret — fail fast at the dict-select boundary instead.

Enums§

CodecZstdDictError
Raised when the server’s Codec-Zstd-Dict header doesn’t match any dict the client has loaded, or is missing on a zstd response.
ZstdDictDiscoveryError
Errors raised by the v0.5 zstd-dictionary discovery surface.

Functions§

discover_zstd_dict
Async variant of discover_zstd_dict_blocking. Requires a Tokio runtime.
discover_zstd_dict_blocking
Synchronously resolve a zstd dictionary via .well-known/codec/dicts/<hex>.zstd (v0.5+).
hash_zstd_dict
Compute the canonical Codec-Zstd-Dict hash for dict_bytes.
select_zstd_dict_for_response
Pick the zstd dict to decompress this response with.
well_known_dict_url
Per-dict document URL for an origin + sha256 hash (v0.5+).