Skip to main content

structured_zstd/decoding/
mod.rs

1//! RFC 8878 Zstandard decoder.
2//!
3//! Three entry points are exposed, each with progressively lower-level
4//! control:
5//!
6//! * [`StreamingDecoder`] — implements [`crate::io::Read`] over a compressed
7//!   byte stream, transparently parsing the frame header and concatenated
8//!   frames. The typical choice for application code.
9//! * [`FrameDecoder`] — single-frame interface; use when the caller manages
10//!   the input buffer manually (zero-copy slices, network framing, etc).
11//! * [`DictionaryHandle`] — pre-parsed dictionary handle. Parse the
12//!   dictionary bytes once with [`DictionaryHandle::decode_dict`] and reuse
13//!   the handle across every subsequent decode; saves the per-frame
14//!   dictionary parse cost when the same dictionary is used many times in a
15//!   row.
16//!
17//! Both decoders expose dictionary-aware constructors / methods,
18//! though the exact naming differs:
19//!
20//! * [`StreamingDecoder::new_with_dictionary_handle`] /
21//!   [`StreamingDecoder::new_with_dictionary_bytes`]
22//! * [`FrameDecoder::decode_all_with_dict_handle`] /
23//!   [`FrameDecoder::decode_all_with_dict_bytes`]
24//!
25//! The `_handle` variants reuse a previously parsed
26//! [`DictionaryHandle`]; the `_bytes` variants parse the dictionary
27//! per call (suitable for one-off decodes).
28//!
29//! Errors surface through [`errors::FrameDecoderError`] and the per-decoder
30//! error types in the [`errors`] submodule.
31
32pub mod errors;
33mod frame_decoder;
34mod streaming_decoder;
35
36pub use dictionary::{Dictionary, DictionaryHandle};
37pub use frame_decoder::{BlockDecodingStrategy, FrameDecoder};
38pub use streaming_decoder::StreamingDecoder;
39
40pub(crate) mod block_decoder;
41pub(crate) mod buffer_backend;
42pub(crate) mod decode_buffer;
43pub(crate) mod dictionary;
44pub(crate) mod exec_sequence_inline;
45// FlatBuf is the compile-time-monomorphised "frame fits in window"
46// backend selected via `DecodeBuffer<FlatBuf>`. `FrameDecoder`'s
47// `DecoderScratchKind` picks it when the frame header has
48// `Single_Segment_flag` set; the ring backend remains the default
49// for multi-segment frames. See backlog item #132 for the wiring
50// rationale.
51pub(crate) mod flat_buf;
52pub(crate) mod frame;
53pub(crate) mod literals_section_decoder;
54pub(crate) mod prefetch;
55mod ringbuffer;
56#[allow(dead_code)]
57pub(crate) mod scratch;
58pub(crate) mod sequence_execution;
59pub(crate) mod sequence_section_decoder;
60pub(crate) mod simd_copy;
61// `UserSliceBackend` is the compile-time-monomorphised backend that
62// writes directly into the caller's `&mut [u8]` output slice, used
63// by the `FrameDecoder::decode_all` direct-decode path. It
64// eliminates the `FlatBuf` drain copy + anonymous-page-fault cost
65// on large literal sections. Wiring happens via
66// `DecodeBuffer<UserSliceBackend<'a>>`; the lifetime binds the
67// backend to the caller's slice for the call duration.
68pub(crate) mod user_slice_buf;
69
70#[cfg(feature = "bench_internals")]
71pub(crate) use self::simd_copy::copy_bytes_overshooting_for_bench;