Skip to main content

libzstd_rs_sys/lib/
zstd.rs

1use core::ffi::{c_int, c_uint, c_ulonglong};
2use libc::size_t;
3
4#[cfg(doc)]
5use crate::{
6    lib::compress::zstd_compress::ZSTD_c_maxBlockSize, ZSTD_CDict, ZSTD_DCtx, ZSTD_DCtx_refDDict,
7    ZSTD_DCtx_reset, ZSTD_DCtx_setParameter, ZSTD_DDict, ZSTD_compressBound,
8    ZSTD_compress_usingDict, ZSTD_decompress, ZSTD_freeDCtx,
9};
10
11pub const ZSTD_FRAMEHEADERSIZE_MAX: core::ffi::c_int = 18;
12
13pub const ZSTD_WINDOWLOG_MAX_32: core::ffi::c_int = 30;
14pub const ZSTD_WINDOWLOG_MAX_64: core::ffi::c_int = 31;
15pub const ZSTD_WINDOWLOG_MAX: core::ffi::c_int = match size_of::<usize>() {
16    4 => ZSTD_WINDOWLOG_MAX_32,
17    8 => ZSTD_WINDOWLOG_MAX_64,
18    _ => panic!(),
19};
20/// By default, the streaming decoder will refuse any frame requiring larger than
21/// (1<<`ZSTD_WINDOWLOG_LIMIT_DEFAULT`) window size to preserve host's memory from unreasonable
22/// requirements. This limit can be overridden using [`ZSTD_DCtx_setParameter`].
23///
24/// The limit does not apply for one-pass decoders (such as [`ZSTD_decompress`]), since no
25/// additional memory is allocated.
26pub const ZSTD_WINDOWLOG_LIMIT_DEFAULT: core::ffi::c_int = 27;
27pub const ZSTD_WINDOWLOG_ABSOLUTEMIN: core::ffi::c_int = 10;
28
29pub const ZSTD_BLOCKSIZELOG_MAX: c_int = 17;
30pub const ZSTD_BLOCKSIZE_MAX: c_int = 1 << ZSTD_BLOCKSIZELOG_MAX;
31/// The minimum valid max blocksize. Maximum blocksizes smaller than this make [`ZSTD_compressBound`] inaccurate.
32pub const ZSTD_BLOCKSIZE_MAX_MIN: core::ffi::c_int = 1 << 10;
33pub const ZSTD_CLEVEL_DEFAULT: c_int = 3;
34
35pub const ZSTD_MAGICNUMBER: c_uint = 0xfd2fb528;
36pub const ZSTD_MAGIC_DICTIONARY: c_uint = 0xec30a437;
37pub const ZSTD_MAGIC_SKIPPABLE_START: c_uint = 0x184d2a50;
38pub const ZSTD_MAGIC_SKIPPABLE_MASK: c_uint = 0xfffffff0;
39
40pub const ZSTD_VERSION_MAJOR: c_uint = 1;
41pub const ZSTD_VERSION_MINOR: c_uint = 5;
42pub const ZSTD_VERSION_RELEASE: c_uint = 8;
43pub const ZSTD_VERSION_NUMBER: c_uint =
44    ZSTD_VERSION_MAJOR * 100 * 100 + ZSTD_VERSION_MINOR * 100 + ZSTD_VERSION_RELEASE;
45
46pub const ZSTD_CONTENTSIZE_UNKNOWN: c_ulonglong = (0 as c_ulonglong).wrapping_sub(1);
47pub const ZSTD_CONTENTSIZE_ERROR: c_ulonglong = (0 as c_ulonglong).wrapping_sub(2);
48pub const ZSTD_SKIPPABLEHEADERSIZE: c_uint = 8;
49
50pub type ZSTD_ErrorCode = core::ffi::c_uint;
51
52pub const ZSTD_error_maxCode: ZSTD_ErrorCode = 120;
53pub const ZSTD_error_externalSequences_invalid: ZSTD_ErrorCode = 107;
54pub const ZSTD_error_sequenceProducer_failed: ZSTD_ErrorCode = 106;
55pub const ZSTD_error_srcBuffer_wrong: ZSTD_ErrorCode = 105;
56pub const ZSTD_error_dstBuffer_wrong: ZSTD_ErrorCode = 104;
57pub const ZSTD_error_seekableIO: ZSTD_ErrorCode = 102;
58pub const ZSTD_error_frameIndex_tooLarge: ZSTD_ErrorCode = 100;
59pub const ZSTD_error_noForwardProgress_inputEmpty: ZSTD_ErrorCode = 82;
60pub const ZSTD_error_noForwardProgress_destFull: ZSTD_ErrorCode = 80;
61pub const ZSTD_error_dstBuffer_null: ZSTD_ErrorCode = 74;
62pub const ZSTD_error_srcSize_wrong: ZSTD_ErrorCode = 72;
63pub const ZSTD_error_dstSize_tooSmall: ZSTD_ErrorCode = 70;
64pub const ZSTD_error_workSpace_tooSmall: ZSTD_ErrorCode = 66;
65pub const ZSTD_error_memory_allocation: ZSTD_ErrorCode = 64;
66pub const ZSTD_error_init_missing: ZSTD_ErrorCode = 62;
67pub const ZSTD_error_stage_wrong: ZSTD_ErrorCode = 60;
68pub const ZSTD_error_stabilityCondition_notRespected: ZSTD_ErrorCode = 50;
69pub const ZSTD_error_cannotProduce_uncompressedBlock: ZSTD_ErrorCode = 49;
70pub const ZSTD_error_maxSymbolValue_tooSmall: ZSTD_ErrorCode = 48;
71pub const ZSTD_error_maxSymbolValue_tooLarge: ZSTD_ErrorCode = 46;
72pub const ZSTD_error_tableLog_tooLarge: ZSTD_ErrorCode = 44;
73pub const ZSTD_error_parameter_outOfBound: ZSTD_ErrorCode = 42;
74pub const ZSTD_error_parameter_combination_unsupported: ZSTD_ErrorCode = 41;
75pub const ZSTD_error_parameter_unsupported: ZSTD_ErrorCode = 40;
76pub const ZSTD_error_dictionaryCreation_failed: ZSTD_ErrorCode = 34;
77pub const ZSTD_error_dictionary_wrong: ZSTD_ErrorCode = 32;
78pub const ZSTD_error_dictionary_corrupted: ZSTD_ErrorCode = 30;
79pub const ZSTD_error_literals_headerWrong: ZSTD_ErrorCode = 24;
80pub const ZSTD_error_checksum_wrong: ZSTD_ErrorCode = 22;
81pub const ZSTD_error_corruption_detected: ZSTD_ErrorCode = 20;
82pub const ZSTD_error_frameParameter_windowTooLarge: ZSTD_ErrorCode = 16;
83pub const ZSTD_error_frameParameter_unsupported: ZSTD_ErrorCode = 14;
84pub const ZSTD_error_version_unsupported: ZSTD_ErrorCode = 12;
85pub const ZSTD_error_prefix_unknown: ZSTD_ErrorCode = 10;
86pub const ZSTD_error_GENERIC: ZSTD_ErrorCode = 1;
87pub const ZSTD_error_no_error: ZSTD_ErrorCode = 0;
88
89pub type ZSTD_strategy = core::ffi::c_uint;
90pub const ZSTD_btultra2: ZSTD_strategy = 9;
91pub const ZSTD_btultra: ZSTD_strategy = 8;
92pub const ZSTD_btopt: ZSTD_strategy = 7;
93pub const ZSTD_btlazy2: ZSTD_strategy = 6;
94pub const ZSTD_lazy2: ZSTD_strategy = 5;
95pub const ZSTD_lazy: ZSTD_strategy = 4;
96pub const ZSTD_greedy: ZSTD_strategy = 3;
97pub const ZSTD_dfast: ZSTD_strategy = 2;
98pub const ZSTD_fast: ZSTD_strategy = 1;
99
100#[derive(Debug, Copy, Clone, Default)]
101#[repr(C)]
102pub struct ZSTD_compressionParameters {
103    pub windowLog: core::ffi::c_uint,
104    pub chainLog: core::ffi::c_uint,
105    pub hashLog: core::ffi::c_uint,
106    pub searchLog: core::ffi::c_uint,
107    pub minMatch: core::ffi::c_uint,
108    pub targetLength: core::ffi::c_uint,
109    pub strategy: ZSTD_strategy,
110}
111
112#[derive(Debug, Copy, Clone, Default)]
113#[repr(C)]
114pub struct ZSTD_frameParameters {
115    pub contentSizeFlag: core::ffi::c_int,
116    pub checksumFlag: core::ffi::c_int,
117    pub noDictIDFlag: core::ffi::c_int,
118}
119
120#[derive(Debug, Copy, Clone, Default)]
121#[repr(C)]
122pub struct ZSTD_parameters {
123    pub cParams: ZSTD_compressionParameters,
124    pub fParams: ZSTD_frameParameters,
125}
126
127/// This enum specifies the content type of a dictionary, either [`ZSTD_dct_auto`], [`ZSTD_dct_rawContent`], or [`ZSTD_dct_fullDict`].
128pub type ZSTD_dictContentType_e = core::ffi::c_uint;
129/// Refuses to load a dictionary if it does not respect Zstandard's specification, starting with
130/// [`ZSTD_MAGIC_DICTIONARY`]
131pub const ZSTD_dct_fullDict: ZSTD_dictContentType_e = 2;
132/// Ensures dictionary is always loaded as `rawContent`, even if it starts with [`ZSTD_MAGIC_DICTIONARY`]
133pub const ZSTD_dct_rawContent: ZSTD_dictContentType_e = 1;
134/// Dictionary is "full" when starting with [`ZSTD_MAGIC_DICTIONARY`], otherwise it is "rawContent"
135pub const ZSTD_dct_auto: ZSTD_dictContentType_e = 0;
136
137/// This enum specifies the method used to load a dictionary, either [`ZSTD_dlm_byCopy`] or [`ZSTD_dlm_byRef`].
138pub type ZSTD_dictLoadMethod_e = core::ffi::c_uint;
139/// Copy dictionary content internally
140pub const ZSTD_dlm_byCopy: ZSTD_dictLoadMethod_e = 0;
141/// Reference dictionary content -- the dictionary buffer must outlive its users
142pub const ZSTD_dlm_byRef: ZSTD_dictLoadMethod_e = 1;
143
144#[derive(Copy, Clone, Default)]
145#[repr(C)]
146pub struct ZSTD_customMem {
147    pub customAlloc: ZSTD_allocFunction,
148    pub customFree: ZSTD_freeFunction,
149    pub opaque: *mut core::ffi::c_void,
150}
151pub type ZSTD_freeFunction =
152    Option<unsafe extern "C" fn(*mut core::ffi::c_void, *mut core::ffi::c_void) -> ()>;
153pub type ZSTD_allocFunction =
154    Option<unsafe extern "C" fn(*mut core::ffi::c_void, size_t) -> *mut core::ffi::c_void>;
155
156#[derive(PartialEq)]
157#[repr(transparent)]
158pub struct ZSTD_format_e(u32);
159
160impl ZSTD_format_e {
161    /// zstd frame format, specified in `zstd_compression_format.md` (default)
162    pub const ZSTD_f_zstd1: Self = Self(Format::ZSTD_f_zstd1 as u32);
163
164    /// Variant of zstd frame format, without initial 4-bytes magic number.
165    ///
166    /// Useful to save 4 bytes per generated frame.
167    ///
168    /// The decoder cannot recognize this format automatically, thus requiring this instruction.
169    pub const ZSTD_f_zstd1_magicless: Self = Self(Format::ZSTD_f_zstd1_magicless as u32);
170}
171
172impl From<ZSTD_format_e> for u32 {
173    fn from(value: ZSTD_format_e) -> Self {
174        value.0
175    }
176}
177
178#[derive(Debug, Copy, Clone, PartialEq, Eq)]
179#[repr(u32)]
180pub enum Format {
181    ZSTD_f_zstd1 = 0,
182    ZSTD_f_zstd1_magicless = 1,
183}
184
185impl Format {
186    /// This function replaces the `ZSTD_FRAMEHEADERSIZE_MIN` macro.
187    ///
188    /// Returns the minimum size of the frame header.
189    pub const fn frame_header_size_min(self) -> usize {
190        match self {
191            Format::ZSTD_f_zstd1 => 6,
192            Format::ZSTD_f_zstd1_magicless => 2,
193        }
194    }
195
196    /// This function replaces the `ZSTD_FRAMEHEADERSIZE_PREFIX` macro.
197    ///
198    /// Returns the minimum input size required to query the frame header size.
199    pub const fn starting_input_length(self) -> usize {
200        match self {
201            Format::ZSTD_f_zstd1 => 5,
202            Format::ZSTD_f_zstd1_magicless => 1,
203        }
204    }
205}
206
207impl TryFrom<ZSTD_format_e> for Format {
208    type Error = ();
209
210    fn try_from(value: ZSTD_format_e) -> Result<Self, Self::Error> {
211        match value {
212            ZSTD_format_e::ZSTD_f_zstd1 => Ok(Self::ZSTD_f_zstd1),
213            ZSTD_format_e::ZSTD_f_zstd1_magicless => Ok(Self::ZSTD_f_zstd1_magicless),
214            _ => Err(()),
215        }
216    }
217}
218
219impl TryFrom<i32> for Format {
220    type Error = ();
221
222    fn try_from(value: i32) -> Result<Self, Self::Error> {
223        match value {
224            0 => Ok(Self::ZSTD_f_zstd1),
225            1 => Ok(Self::ZSTD_f_zstd1_magicless),
226            _ => Err(()),
227        }
228    }
229}
230
231pub type ZSTD_inBuffer = ZSTD_inBuffer_s;
232#[derive(Copy, Clone)]
233#[repr(C)]
234pub struct ZSTD_inBuffer_s {
235    /// Pointer to start of input buffer
236    pub src: *const core::ffi::c_void,
237    /// Size of input buffer
238    pub size: size_t,
239    /// Position where reading stopped. Will be updated. Necessarily `0 <= pos <= size`.
240    pub pos: size_t,
241}
242
243pub type ZSTD_outBuffer = ZSTD_outBuffer_s;
244#[derive(Copy, Clone)]
245#[repr(C)]
246pub struct ZSTD_outBuffer_s {
247    /// Pointer to start of output buffer
248    pub dst: *mut core::ffi::c_void,
249    /// Size of output buffer
250    pub size: size_t,
251    /// Position where writing stopped. Will be updated. Necessarily `0 <= pos <= size`.
252    pub pos: size_t,
253}
254
255pub type ZSTD_bufferMode_e = core::ffi::c_uint;
256pub const ZSTD_bm_stable: ZSTD_bufferMode_e = 1;
257pub const ZSTD_bm_buffered: ZSTD_bufferMode_e = 0;
258
259#[repr(u32)]
260#[derive(Debug, Copy, Clone, PartialEq, Eq)]
261pub enum BufferMode {
262    Buffered,
263    Stable,
264}
265
266impl TryFrom<u32> for BufferMode {
267    type Error = ();
268
269    fn try_from(value: u32) -> Result<Self, Self::Error> {
270        match value {
271            0 => Ok(Self::Buffered),
272            1 => Ok(Self::Stable),
273            _ => Err(()),
274        }
275    }
276}
277
278#[derive(Copy, Clone)]
279#[repr(C)]
280pub struct ZSTD_frameProgression {
281    pub ingested: core::ffi::c_ulonglong,
282    pub consumed: core::ffi::c_ulonglong,
283    pub produced: core::ffi::c_ulonglong,
284    pub flushed: core::ffi::c_ulonglong,
285    pub currentJobID: core::ffi::c_uint,
286    pub nbActiveWorkers: core::ffi::c_uint,
287}
288
289pub mod experimental {
290    use crate::lib::zstd::Format;
291
292    pub const fn ZSTD_FRAMEHEADERSIZE_MIN(format: Format) -> usize {
293        if let Format::ZSTD_f_zstd1 = format {
294            6
295        } else {
296            2
297        }
298    }
299
300    pub use crate::lib::common::pool::{
301        ZSTD_createThreadPool, ZSTD_freeThreadPool, ZSTD_threadPool,
302    };
303}
304
305/// The advanced API pushes parameters one by one into an existing `ZSTD_DCtx` decompression
306/// context. Parameters are sticky, and remain valid for all following frames using the same
307/// context.
308///
309/// It's possible to reset parameters to default values using [`ZSTD_DCtx_reset`].
310#[repr(transparent)]
311#[derive(Debug, Clone, Copy, PartialEq, Eq)]
312pub struct ZSTD_dParameter(u32);
313
314impl ZSTD_dParameter {
315    pub const ZSTD_d_experimentalParam1: Self = Self(1000);
316    pub const ZSTD_d_experimentalParam2: Self = Self(1001);
317    pub const ZSTD_d_experimentalParam3: Self = Self(1002);
318    pub const ZSTD_d_experimentalParam4: Self = Self(1003);
319    pub const ZSTD_d_experimentalParam5: Self = Self(1004);
320    pub const ZSTD_d_experimentalParam6: Self = Self(1005);
321
322    /// Experimental parameter: allowing selection between [`ZSTD_format_e`] input compression formats
323    pub const ZSTD_d_format: Self = Self::ZSTD_d_experimentalParam1;
324
325    /// Experimental parameter: tells the decompressor that the [`ZSTD_outBuffer`] will ALWAYS be
326    /// the same between calls, except for the modifications that zstd makes to pos (the caller
327    /// must not modify pos). This is checked by the decompressor, and decompression will fail if
328    /// it ever changes. Therefore the `ZSTD_outBuffer` MUST be large enough to fit the entire
329    /// decompressed frame. This will be checked when the frame content size is known. The data in
330    /// the `ZSTD_outBuffer` in the range `dst..(dst + pos)` MUST not be modified during
331    /// decompression or you will get data corruption.
332    ///
333    /// When this flag is enabled zstd won't allocate an output buffer, because it can write
334    /// directly to the `ZSTD_outBuffer`, but it will still allocate an input buffer large enough
335    /// to fit any compressed block. This will also avoid the `memcpy()` from the internal output
336    /// buffer to the `ZSTD_outBuffer`. If you need to avoid the input buffer allocation use the
337    /// buffer-less streaming API.
338    ///
339    /// Note: So long as the `ZSTD_outBuffer` always points to valid memory, using this flag is
340    /// ALWAYS memory safe, and will never access out-of-bounds memory. However, decompression WILL
341    /// fail if you violate the preconditions.
342    ///
343    /// **Warning:** The data in the `ZSTD_outBuffer` in the range `dst..(dst + pos)` MUST not be
344    /// modified during decompression or you will get data corruption. This is because zstd needs
345    /// to reference data in the `ZSTD_outBuffer` to regenerate matches. Normally zstd maintains
346    /// its own buffer for this purpose, but passing this flag tells zstd to use the user provided
347    /// buffer.
348    ///
349    /// Default is 0 == disabled. Set to 1 to enable.
350    pub const ZSTD_d_stableOutBuffer: Self = Self::ZSTD_d_experimentalParam2;
351
352    /// Experimental parameter: tells the decompressor to skip checksum validation during
353    /// decompression, regardless of whether checksumming was specified during compression. This
354    /// offers some slight performance benefits, and may be useful for debugging.
355    ///
356    /// Default is 0 == disabled. Set to 1 to enable.
357    pub const ZSTD_d_forceIgnoreChecksum: Self = Self::ZSTD_d_experimentalParam3;
358
359    /// Experimental parameter: if enabled and [`ZSTD_DCtx`] is allocated on the heap, then
360    /// additional memory will be allocated to store references to multiple [`ZSTD_DDict`]. That
361    /// is, multiple calls of [`ZSTD_DCtx_refDDict`] using a given [`ZSTD_DCtx`], rather than
362    /// overwriting the previous `DDict` reference, will instead store all references. At
363    /// decompression time, the appropriate `dictID` is selected from the set of `DDict`s based on
364    /// the `dictID` in the frame.
365    ///
366    /// **Warning:** Enabling this parameter and calling [`ZSTD_DCtx_refDDict`] will trigger memory
367    /// allocation for the hash table. [`ZSTD_freeDCtx`] also frees this memory. Memory is
368    /// allocated as per `ZSTD_DCtx::customMem`.
369    ///
370    /// Although this function allocates memory for the table, the user is still responsible for
371    /// memory management of the underlying [`ZSTD_DDict`] themselves.
372    ///
373    /// Default is 0 == disabled. Set to 1 to enable.
374    pub const ZSTD_d_refMultipleDDicts: Self = Self::ZSTD_d_experimentalParam4;
375
376    /// This parameter can be used to disable Huffman assembly at runtime.
377    ///
378    /// Set to 1 to disable the Huffman assembly implementation. The default value is 0, which
379    /// allows zstd to use the Huffman assembly implementation if available.
380    pub const ZSTD_d_disableHuffmanAssembly: Self = Self::ZSTD_d_experimentalParam5;
381
382    /// Forces the decompressor to reject blocks whose content size is larger than the configured
383    /// `maxBlockSize`. When `maxBlockSize` is larger than the `windowSize`, the `windowSize` is
384    /// used instead. This saves memory on the decoder when you know all blocks are small.
385    ///
386    /// Allowed values are between 1KB and [`ZSTD_BLOCKSIZE_MAX`] (128KB).
387    /// The default is [`ZSTD_BLOCKSIZE_MAX`], and setting to 0 will set to the default.
388    ///
389    /// This option is typically used in conjunction with [`ZSTD_c_maxBlockSize`].
390    ///
391    /// **Warning:** This causes the decoder to reject otherwise valid frames that have block sizes
392    /// larger than the configured `maxBlockSize`.
393    pub const ZSTD_d_maxBlockSize: Self = Self::ZSTD_d_experimentalParam6;
394
395    /// Select a size limit (in power of 2) beyond which the streaming API will refuse to allocate
396    /// memory buffer in order to protect the host from unreasonable memory requirements.
397    ///
398    /// This parameter is only useful in streaming mode, since no internal buffer is allocated in
399    /// single-pass mode. By default, a decompression context accepts window sizes less than or
400    /// equal to (1 << [`ZSTD_WINDOWLOG_LIMIT_DEFAULT`]).
401    ///
402    /// A value of 0 means "use default maximum `windowLog`".
403    pub const ZSTD_d_windowLogMax: Self = Self(100);
404}
405
406#[repr(u8)]
407#[derive(Debug, Clone, Copy, PartialEq, Eq)]
408pub(crate) enum ForceIgnoreChecksum {
409    ValidateChecksum = 0,
410    IgnoreChecksum = 1,
411}
412
413impl TryFrom<i32> for ForceIgnoreChecksum {
414    type Error = ();
415
416    fn try_from(value: i32) -> Result<Self, Self::Error> {
417        match value {
418            0 => Ok(Self::ValidateChecksum),
419            1 => Ok(Self::IgnoreChecksum),
420            _ => Err(()),
421        }
422    }
423}
424
425#[repr(transparent)]
426#[derive(Debug, Clone, Copy, PartialEq, Eq)]
427pub struct ZSTD_cParameter(pub(crate) u32);
428
429impl ZSTD_cParameter {
430    pub const ZSTD_c_experimentalParam1: Self = Self(500);
431    pub const ZSTD_c_experimentalParam2: Self = Self(10);
432    pub const ZSTD_c_experimentalParam3: Self = Self(1000);
433    pub const ZSTD_c_experimentalParam4: Self = Self(1001);
434    pub const ZSTD_c_experimentalParam5: Self = Self(1002);
435    pub const ZSTD_c_experimentalParam7: Self = Self(1004);
436    pub const ZSTD_c_experimentalParam8: Self = Self(1005);
437    pub const ZSTD_c_experimentalParam9: Self = Self(1006);
438    pub const ZSTD_c_experimentalParam10: Self = Self(1007);
439    pub const ZSTD_c_experimentalParam11: Self = Self(1008);
440    pub const ZSTD_c_experimentalParam12: Self = Self(1009);
441    pub const ZSTD_c_experimentalParam13: Self = Self(1010);
442    pub const ZSTD_c_experimentalParam14: Self = Self(1011);
443    pub const ZSTD_c_experimentalParam15: Self = Self(1012);
444    pub const ZSTD_c_experimentalParam16: Self = Self(1013);
445    pub const ZSTD_c_experimentalParam17: Self = Self(1014);
446    pub const ZSTD_c_experimentalParam18: Self = Self(1015);
447    pub const ZSTD_c_experimentalParam19: Self = Self(1016);
448    pub const ZSTD_c_experimentalParam20: Self = Self(1017);
449
450    pub const ZSTD_c_rsyncable: Self = Self::ZSTD_c_experimentalParam1;
451    pub const ZSTD_c_format: Self = Self::ZSTD_c_experimentalParam2;
452    pub const ZSTD_c_forceMaxWindow: Self = Self::ZSTD_c_experimentalParam3;
453    pub const ZSTD_c_forceAttachDict: Self = Self::ZSTD_c_experimentalParam4;
454    pub const ZSTD_c_literalCompressionMode: Self = Self::ZSTD_c_experimentalParam5;
455    pub const ZSTD_c_srcSizeHint: Self = Self::ZSTD_c_experimentalParam7;
456    pub const ZSTD_c_enableDedicatedDictSearch: Self = Self::ZSTD_c_experimentalParam8;
457    pub const ZSTD_c_stableInBuffer: Self = Self::ZSTD_c_experimentalParam9;
458    pub const ZSTD_c_stableOutBuffer: Self = Self::ZSTD_c_experimentalParam10;
459    pub const ZSTD_c_blockDelimiters: Self = Self::ZSTD_c_experimentalParam11;
460    pub const ZSTD_c_validateSequences: Self = Self::ZSTD_c_experimentalParam12;
461    pub const ZSTD_c_blockSplitterLevel: Self = Self::ZSTD_c_experimentalParam20;
462    pub const ZSTD_c_splitAfterSequences: Self = Self::ZSTD_c_experimentalParam13;
463    pub const ZSTD_c_useRowMatchFinder: Self = Self::ZSTD_c_experimentalParam14;
464    pub const ZSTD_c_deterministicRefPrefix: Self = Self::ZSTD_c_experimentalParam15;
465    pub const ZSTD_c_prefetchCDictTables: Self = Self::ZSTD_c_experimentalParam16;
466    pub const ZSTD_c_enableSeqProducerFallback: Self = Self::ZSTD_c_experimentalParam17;
467    pub const ZSTD_c_maxBlockSize: Self = Self::ZSTD_c_experimentalParam18;
468    pub const ZSTD_c_repcodeResolution: Self = Self::ZSTD_c_experimentalParam19;
469    pub const ZSTD_c_searchForExternalRepcodes: Self = Self::ZSTD_c_experimentalParam19;
470
471    pub const ZSTD_c_compressionLevel: Self = Self(100);
472    pub const ZSTD_c_windowLog: Self = Self(101);
473    pub const ZSTD_c_hashLog: Self = Self(102);
474    pub const ZSTD_c_chainLog: Self = Self(103);
475    pub const ZSTD_c_searchLog: Self = Self(104);
476    pub const ZSTD_c_minMatch: Self = Self(105);
477    pub const ZSTD_c_targetLength: Self = Self(106);
478    pub const ZSTD_c_strategy: Self = Self(107);
479    pub const ZSTD_c_targetCBlockSize: Self = Self(130);
480    pub const ZSTD_c_enableLongDistanceMatching: Self = Self(160);
481    pub const ZSTD_c_ldmHashLog: Self = Self(161);
482    pub const ZSTD_c_ldmMinMatch: Self = Self(162);
483    pub const ZSTD_c_ldmBucketSizeLog: Self = Self(163);
484    pub const ZSTD_c_ldmHashRateLog: Self = Self(164);
485    pub const ZSTD_c_contentSizeFlag: Self = Self(200);
486    pub const ZSTD_c_checksumFlag: Self = Self(201);
487    pub const ZSTD_c_dictIDFlag: Self = Self(202);
488    pub const ZSTD_c_nbWorkers: Self = Self(400);
489    pub const ZSTD_c_jobSize: Self = Self(401);
490    pub const ZSTD_c_overlapLog: Self = Self(402);
491}
492
493#[repr(transparent)]
494#[derive(Debug, Clone, Copy, PartialEq, Eq)]
495pub struct ZSTD_ResetDirective(pub(crate) u32);
496impl ZSTD_ResetDirective {
497    pub const ZSTD_reset_session_only: Self = Self(1);
498    pub const ZSTD_reset_parameters: Self = Self(2);
499    pub const ZSTD_reset_session_and_parameters: Self = Self(3);
500}
501
502/// Note: this enum and the behavior it controls are effectively internal
503/// implementation details of the compressor. They are expected to continue
504/// to evolve and should be considered only in the context of extremely
505/// advanced performance tuning.
506///
507/// Zstd currently supports the use of a [`ZSTD_CDict`] in three ways:
508///
509/// - The contents of the `CDict` can be copied into the working context. This
510///   means that the compression can search both the dictionary and input
511///   while operating on a single set of internal tables. This makes
512///   the compression faster per byte of input. However, the initial copy of
513///   the `CDict`'s tables incurs a fixed cost at the beginning of the
514///   compression. For small compressions (< 8 KB), that copy can dominate
515///   the cost of the compression.
516///
517/// - The `CDict`'s tables can be used in-place. In this model, compression is
518///   slower per input byte, because the compressor has to search two sets of
519///   tables. However, this model incurs no start-up cost (as long as the
520///   working context's tables can be reused). For small inputs, this can be
521///   faster than copying the `CDict`'s tables.
522///
523/// - The `CDict`'s tables are not used at all, and instead we use the working
524///   context alone to reload the dictionary and use params based on the source
525///   size. See `ZSTD_compress_insertDictionary` and [`ZSTD_compress_usingDict`].
526///   This method is effective when the dictionary sizes are very small relative
527///   to the input size, and the input size is fairly large to begin with.
528///
529/// Zstd has a simple internal heuristic that selects which strategy to use
530/// at the beginning of a compression. However, if experimentation shows that
531/// Zstd is making poor choices, it is possible to override that choice with
532/// this enum.
533#[repr(transparent)]
534#[derive(Debug, Clone, Copy, PartialEq, Eq)]
535pub struct ZSTD_dictAttachPref_e(pub(crate) u32);
536impl ZSTD_dictAttachPref_e {
537    /// Use the default heuristic
538    pub const ZSTD_dictDefaultAttach: Self = Self(0);
539    /// Never copy the dictionary
540    pub const ZSTD_dictForceAttach: Self = Self(1);
541    /// Always copy the dictionary
542    pub const ZSTD_dictForceCopy: Self = Self(2);
543    /// Always reload the dictionary
544    pub const ZSTD_dictForceLoad: Self = Self(3);
545}
546
547impl TryFrom<i32> for ZSTD_dictAttachPref_e {
548    type Error = ();
549
550    fn try_from(value: i32) -> Result<Self, Self::Error> {
551        match value {
552            0 => Ok(Self::ZSTD_dictDefaultAttach),
553            1 => Ok(Self::ZSTD_dictForceAttach),
554            2 => Ok(Self::ZSTD_dictForceCopy),
555            3 => Ok(Self::ZSTD_dictForceLoad),
556            _ => Err(()),
557        }
558    }
559}
560
561/// Note: this enum controls features which are conditionally beneficial.
562///
563/// Zstd can take a decision on whether or not to enable the feature (`ZSTD_ps_auto`),
564/// or set the switch to `ZSTD_ps_enable` or `ZSTD_ps_disable` force enable/disable the feature.
565#[derive(Debug, Clone, Copy, PartialEq, Eq)]
566pub enum ZSTD_ParamSwitch_e {
567    /// Let the library automatically determine whether the feature shall be enabled
568    ZSTD_ps_auto = 0,
569    /// Force-enable the feature
570    ZSTD_ps_enable = 1,
571    /// Force-disable the feature
572    ZSTD_ps_disable = 2,
573}
574
575impl ZSTD_ParamSwitch_e {
576    pub fn to_i32(self) -> i32 {
577        self as i32
578    }
579}
580
581impl TryFrom<i32> for ZSTD_ParamSwitch_e {
582    type Error = ();
583
584    fn try_from(value: i32) -> Result<Self, Self::Error> {
585        match value {
586            0 => Ok(Self::ZSTD_ps_auto),
587            1 => Ok(Self::ZSTD_ps_enable),
588            2 => Ok(Self::ZSTD_ps_disable),
589            _ => Err(()),
590        }
591    }
592}