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};
20pub 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;
31pub 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
127pub type ZSTD_dictContentType_e = core::ffi::c_uint;
129pub const ZSTD_dct_fullDict: ZSTD_dictContentType_e = 2;
132pub const ZSTD_dct_rawContent: ZSTD_dictContentType_e = 1;
134pub const ZSTD_dct_auto: ZSTD_dictContentType_e = 0;
136
137pub type ZSTD_dictLoadMethod_e = core::ffi::c_uint;
139pub const ZSTD_dlm_byCopy: ZSTD_dictLoadMethod_e = 0;
141pub 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 pub const ZSTD_f_zstd1: Self = Self(Format::ZSTD_f_zstd1 as u32);
163
164 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 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 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 pub src: *const core::ffi::c_void,
237 pub size: size_t,
239 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 pub dst: *mut core::ffi::c_void,
249 pub size: size_t,
251 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#[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 pub const ZSTD_d_format: Self = Self::ZSTD_d_experimentalParam1;
324
325 pub const ZSTD_d_stableOutBuffer: Self = Self::ZSTD_d_experimentalParam2;
351
352 pub const ZSTD_d_forceIgnoreChecksum: Self = Self::ZSTD_d_experimentalParam3;
358
359 pub const ZSTD_d_refMultipleDDicts: Self = Self::ZSTD_d_experimentalParam4;
375
376 pub const ZSTD_d_disableHuffmanAssembly: Self = Self::ZSTD_d_experimentalParam5;
381
382 pub const ZSTD_d_maxBlockSize: Self = Self::ZSTD_d_experimentalParam6;
394
395 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#[repr(transparent)]
534#[derive(Debug, Clone, Copy, PartialEq, Eq)]
535pub struct ZSTD_dictAttachPref_e(pub(crate) u32);
536impl ZSTD_dictAttachPref_e {
537 pub const ZSTD_dictDefaultAttach: Self = Self(0);
539 pub const ZSTD_dictForceAttach: Self = Self(1);
541 pub const ZSTD_dictForceCopy: Self = Self(2);
543 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#[derive(Debug, Clone, Copy, PartialEq, Eq)]
566pub enum ZSTD_ParamSwitch_e {
567 ZSTD_ps_auto = 0,
569 ZSTD_ps_enable = 1,
571 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}