1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! Zstandard (RFC 8478) — partial implementation.
//!
//! Reference: <https://datatracker.ietf.org/doc/html/rfc8478>.
//!
//! # What works
//!
//! - **Decoder**: streams Zstd frames whose data blocks are `Raw_Block`
//! (Block_Type=0), `RLE_Block` (Block_Type=1), or `Compressed_Block`
//! (Block_Type=2). The Compressed_Block path implements:
//! - All four literals encodings: Raw, RLE, Compressed (fresh Huffman
//! tree), and Treeless (reuse previous tree). Both 1-stream and
//! 4-stream Huffman bitstream layouts.
//! - Huffman tree decoding for both direct (nibble-packed) and
//! FSE-compressed weight encodings.
//! - FSE table decoding for the literal-length / offset / match-length
//! sequences. Predefined_Mode, RLE_Mode, FSE_Compressed_Mode, and
//! Repeat_Mode are all supported.
//! - LZ77 reconstruction including the "previous offsets" repeat-code
//! quirk (offset values 1..=3 alias the three most recent offsets,
//! with special handling when `literal_length == 0`).
//!
//! The frame header parser handles the full set of Frame_Header_Descriptor
//! permutations (Single_Segment_Flag, optional Window_Descriptor, optional
//! Dictionary_ID field of 0/1/2/4 bytes, optional Frame_Content_Size of
//! 0/1/2/4/8 bytes with the 2-byte FCS+256 quirk).
//!
//! - **Encoder**: emits a valid Zstd frame. Per-block, the encoder picks
//! between:
//! - `RLE_Block` (Block_Type=1) when every byte in the block is identical
//! (single payload byte; biggest win on long zero/one-byte runs).
//! - `Compressed_Block` (Block_Type=2) otherwise, with:
//! - **LZ77** match finding via a 4-byte hash-chain matcher.
//! - **Repeat offsets** (offset_value ∈ 1..=3) tracked in a ring
//! buffer carried across blocks per RFC 8478 §3.1.1.5.
//! - **Huffman literals** (RFC §4.2) — direct nibble-packed weight
//! encoding, 1-stream for blocks ≤ 1023 literals and 4-stream
//! otherwise. Emits `Compressed_Literals_Block` (fresh tree) when
//! the previous block's tree is missing or worse;
//! `Treeless_Literals_Block` when reusing the previous tree saves
//! tree-description bytes.
//! - **FSE_Compressed_Mode** for sequence tables when a custom
//! distribution measurably beats the predefined LL/OF/ML tables;
//! Predefined_Mode otherwise. The encoder does NOT currently emit
//! Repeat_Mode (per-table) or RLE_Mode for sequences.
//! - `Raw_Block` (Block_Type=0) as a fallback when neither RLE nor
//! Compressed beats the raw size.
//!
//! What we still don't do: FSE-compressed Huffman weight tables (we cap
//! the alphabet at 128 weights for direct nibble encoding), Repeat_Mode /
//! RLE_Mode for sequence FSE tables, multi-frame output, content checksum,
//! or dictionaries.
//!
//! # What does NOT work
//!
//! - **Content_Checksum_Flag** in the Frame_Header. The 4-byte trailer is the
//! low 32 bits of XXH64 over the decompressed data; we do not ship an
//! XXH64 implementation, so any frame that advertises a content checksum
//! is refused with [`crate::Error::Unsupported`].
//!
//! - **Skippable_Frame** magic numbers (`0x184D2A50..=0x184D2A5F`) are
//! detected and rejected as unsupported rather than silently skipped.
//!
//! - **Dictionary_ID != 0** frames are unsupported (no dictionary registry).
//!
//! - **Concatenated frames** are not supported — the decoder stops after the
//! last block of the first frame.
//!
//! Both halves are pure streaming: caller owns the input/output buffers and
//! the codec preserves state across `encode`/`decode` calls.
pub use Decoder;
pub use Encoder;
/// Internal helpers exposed for integration tests only. Not part of the
/// public API; subject to change without notice.
use crateAlgorithm;
/// Zero-sized marker type implementing [`Algorithm`] for Zstd.
///
/// See the [module-level documentation](self) for the supported subset and
/// known limitations.
;