Skip to main content

libzstd_rs_sys/lib/common/
zstd_trace.rs

1use 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#[repr(C)]
7pub struct ZSTD_Trace {
8    pub version: core::ffi::c_uint,
9    pub streaming: core::ffi::c_int,
10    pub dictionaryID: core::ffi::c_uint,
11    pub dictionaryIsCold: core::ffi::c_int,
12    pub dictionarySize: size_t,
13    pub uncompressedSize: size_t,
14    pub compressedSize: size_t,
15    pub params: *const ZSTD_CCtx_params_s,
16    pub cctx: *const ZSTD_CCtx_s,
17    pub dctx: *const ZSTD_DCtx_s,
18}
19
20pub type ZSTD_TraceCtx = core::ffi::c_ulonglong;
21
22#[inline]
23pub(crate) fn ZSTD_trace_compress_begin(_cctx: *const ZSTD_CCtx) -> ZSTD_TraceCtx {
24    #[cfg(feature = "trace")]
25    unsafe {
26        return statics::ZSTD_trace_compress_begin(_cctx);
27    }
28
29    #[cfg(not(feature = "trace"))]
30    0
31}
32
33#[inline]
34pub(crate) fn ZSTD_trace_compress_end(_ctx: ZSTD_TraceCtx, _trace: *const ZSTD_Trace) {
35    #[cfg(feature = "trace")]
36    unsafe {
37        return statics::ZSTD_trace_compress_end(_ctx, _trace);
38    }
39}
40
41#[inline]
42pub(crate) fn ZSTD_trace_decompress_begin(_dctx: *const ZSTD_DCtx) -> ZSTD_TraceCtx {
43    #[cfg(feature = "trace")]
44    unsafe {
45        return statics::ZSTD_trace_decompress_begin(_dctx);
46    }
47
48    #[cfg(not(feature = "trace"))]
49    0
50}
51
52#[inline]
53pub(crate) fn ZSTD_trace_decompress_end(_ctx: ZSTD_TraceCtx, _trace: *const ZSTD_Trace) {
54    #[cfg(feature = "trace")]
55    unsafe {
56        return statics::ZSTD_trace_decompress_end(_ctx, _trace);
57    }
58}
59
60#[cfg(feature = "trace")]
61mod statics {
62    use super::{ZSTD_CCtx, ZSTD_Trace, ZSTD_TraceCtx};
63    use crate::lib::decompress::ZSTD_DCtx;
64
65    extern "C" {
66        pub(super) fn ZSTD_trace_compress_begin(cctx: *const ZSTD_CCtx) -> ZSTD_TraceCtx;
67        pub(super) fn ZSTD_trace_compress_end(ctx: ZSTD_TraceCtx, trace: *const ZSTD_Trace);
68        pub(super) fn ZSTD_trace_decompress_begin(dctx: *const ZSTD_DCtx) -> ZSTD_TraceCtx;
69        pub(super) fn ZSTD_trace_decompress_end(ctx: ZSTD_TraceCtx, trace: *const ZSTD_Trace);
70    }
71}