libzstd_rs_sys/lib/common/
zstd_trace.rs1use libc::size_t;
2
3use crate::lib::compress::zstd_compress::{ZSTD_CCtx, ZSTD_CCtx_params_s, ZSTD_CCtx_s};
4use crate::lib::decompress::{ZSTD_DCtx, ZSTD_DCtx_s};
5
6#[derive(Default)]
7#[repr(C)]
8pub struct ZSTD_Trace {
9 pub version: core::ffi::c_uint,
10 pub streaming: core::ffi::c_int,
11 pub dictionaryID: core::ffi::c_uint,
12 pub dictionaryIsCold: bool,
13 _padding: [u8; 3],
14 pub dictionarySize: size_t,
15 pub uncompressedSize: size_t,
16 pub compressedSize: size_t,
17 pub params: *const ZSTD_CCtx_params_s,
18 pub cctx: *const ZSTD_CCtx_s,
19 pub dctx: *const ZSTD_DCtx_s,
20}
21
22pub type ZSTD_TraceCtx = core::ffi::c_ulonglong;
23
24#[inline]
25pub(crate) fn ZSTD_trace_compress_begin(_cctx: *const ZSTD_CCtx) -> ZSTD_TraceCtx {
26 #[cfg(feature = "trace")]
27 unsafe {
28 return statics::ZSTD_trace_compress_begin(_cctx);
29 }
30
31 #[cfg(not(feature = "trace"))]
32 0
33}
34
35#[inline]
36pub(crate) fn ZSTD_trace_compress_end(_ctx: ZSTD_TraceCtx, _trace: *const ZSTD_Trace) {
37 #[cfg(feature = "trace")]
38 unsafe {
39 return statics::ZSTD_trace_compress_end(_ctx, _trace);
40 }
41}
42
43#[inline]
44pub(crate) fn ZSTD_trace_decompress_begin(_dctx: *const ZSTD_DCtx) -> ZSTD_TraceCtx {
45 #[cfg(feature = "trace")]
46 unsafe {
47 return statics::ZSTD_trace_decompress_begin(_dctx);
48 }
49
50 #[cfg(not(feature = "trace"))]
51 0
52}
53
54#[inline]
55pub(crate) fn ZSTD_trace_decompress_end(_ctx: ZSTD_TraceCtx, _trace: *const ZSTD_Trace) {
56 #[cfg(feature = "trace")]
57 unsafe {
58 return statics::ZSTD_trace_decompress_end(_ctx, _trace);
59 }
60}
61
62#[cfg(feature = "trace")]
63mod statics {
64 use super::{ZSTD_CCtx, ZSTD_Trace, ZSTD_TraceCtx};
65 use crate::lib::decompress::ZSTD_DCtx;
66
67 #[expect(
68 improper_ctypes,
69 reason = "ZSTD_CCtx contains types that are not FFI-safe. This is fine as it is opaque to C"
70 )]
71 extern "C" {
72 pub(super) fn ZSTD_trace_compress_begin(cctx: *const ZSTD_CCtx) -> ZSTD_TraceCtx;
73 pub(super) fn ZSTD_trace_compress_end(ctx: ZSTD_TraceCtx, trace: *const ZSTD_Trace);
74 pub(super) fn ZSTD_trace_decompress_begin(dctx: *const ZSTD_DCtx) -> ZSTD_TraceCtx;
75 pub(super) fn ZSTD_trace_decompress_end(ctx: ZSTD_TraceCtx, trace: *const ZSTD_Trace);
76 }
77}