diff --git a/lib/deprecated/zbuff_common.c b/lib/deprecated/zbuff_common.c index 5a2f2db35..26b312d19 100644 --- a/lib/deprecated/zbuff_common.c +++ b/lib/deprecated/zbuff_common.c @@ -1,26 +1 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - -/*-************************************* -* Dependencies -***************************************/ -#include "../common/error_private.h" -#include "zbuff.h" - -/*-**************************************** -* ZBUFF Error Management (deprecated) -******************************************/ - -/*! ZBUFF_isError() : -* tells if a return value is an error code */ -unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); } -/*! ZBUFF_getErrorName() : -* provides error code string from function result (useful for debugging) */ -const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); } +/* ZBUFF compatibility symbols are implemented by rust/src/zbuff.rs. */ diff --git a/lib/deprecated/zbuff_compress.c b/lib/deprecated/zbuff_compress.c index 1d8682150..26b312d19 100644 --- a/lib/deprecated/zbuff_compress.c +++ b/lib/deprecated/zbuff_compress.c @@ -1,167 +1 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - - - -/* ************************************* -* Dependencies -***************************************/ -#define ZBUFF_STATIC_LINKING_ONLY -#include "zbuff.h" -#include "../common/error_private.h" - - -/*-*********************************************************** -* Streaming compression -* -* A ZBUFF_CCtx object is required to track streaming operation. -* Use ZBUFF_createCCtx() and ZBUFF_freeCCtx() to create/release resources. -* Use ZBUFF_compressInit() to start a new compression operation. -* ZBUFF_CCtx objects can be reused multiple times. -* -* Use ZBUFF_compressContinue() repetitively to consume your input. -* *srcSizePtr and *dstCapacityPtr can be any size. -* The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr. -* Note that it may not consume the entire input, in which case it's up to the caller to call again the function with remaining input. -* The content of dst will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters or change dst . -* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency) -* or an error code, which can be tested using ZBUFF_isError(). -* -* ZBUFF_compressFlush() can be used to instruct ZBUFF to compress and output whatever remains within its buffer. -* Note that it will not output more than *dstCapacityPtr. -* Therefore, some content might still be left into its internal buffer if dst buffer is too small. -* @return : nb of bytes still present into internal buffer (0 if it's empty) -* or an error code, which can be tested using ZBUFF_isError(). -* -* ZBUFF_compressEnd() instructs to finish a frame. -* It will perform a flush and write frame epilogue. -* Similar to ZBUFF_compressFlush(), it may not be able to output the entire internal buffer content if *dstCapacityPtr is too small. -* @return : nb of bytes still present into internal buffer (0 if it's empty) -* or an error code, which can be tested using ZBUFF_isError(). -* -* Hint : recommended buffer sizes (not compulsory) -* input : ZSTD_BLOCKSIZE_MAX (128 KB), internal unit size, it improves latency to use this value. -* output : ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + ZBUFF_endFrameSize : ensures it's always possible to write/flush/end a full block at best speed. -* ***********************************************************/ - -ZBUFF_CCtx* ZBUFF_createCCtx(void) -{ - return ZSTD_createCStream(); -} - -ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem) -{ - return ZSTD_createCStream_advanced(customMem); -} - -size_t ZBUFF_freeCCtx(ZBUFF_CCtx* zbc) -{ - return ZSTD_freeCStream(zbc); -} - - -/* ====== Initialization ====== */ - -size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc, - const void* dict, size_t dictSize, - ZSTD_parameters params, unsigned long long pledgedSrcSize) -{ - if (pledgedSrcSize==0) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* preserve "0 == unknown" behavior */ - FORWARD_IF_ERROR(ZSTD_CCtx_reset(zbc, ZSTD_reset_session_only), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setPledgedSrcSize(zbc, pledgedSrcSize), ""); - - FORWARD_IF_ERROR(ZSTD_checkCParams(params.cParams), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_windowLog, params.cParams.windowLog), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_hashLog, params.cParams.hashLog), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_chainLog, params.cParams.chainLog), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_searchLog, params.cParams.searchLog), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_minMatch, params.cParams.minMatch), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_targetLength, params.cParams.targetLength), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_strategy, params.cParams.strategy), ""); - - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_contentSizeFlag, params.fParams.contentSizeFlag), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_checksumFlag, params.fParams.checksumFlag), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_dictIDFlag, params.fParams.noDictIDFlag), ""); - - FORWARD_IF_ERROR(ZSTD_CCtx_loadDictionary(zbc, dict, dictSize), ""); - return 0; -} - -size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* zbc, const void* dict, size_t dictSize, int compressionLevel) -{ - FORWARD_IF_ERROR(ZSTD_CCtx_reset(zbc, ZSTD_reset_session_only), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_compressionLevel, compressionLevel), ""); - FORWARD_IF_ERROR(ZSTD_CCtx_loadDictionary(zbc, dict, dictSize), ""); - return 0; -} - -size_t ZBUFF_compressInit(ZBUFF_CCtx* zbc, int compressionLevel) -{ - return ZSTD_initCStream(zbc, compressionLevel); -} - -/* ====== Compression ====== */ - - -size_t ZBUFF_compressContinue(ZBUFF_CCtx* zbc, - void* dst, size_t* dstCapacityPtr, - const void* src, size_t* srcSizePtr) -{ - size_t result; - ZSTD_outBuffer outBuff; - ZSTD_inBuffer inBuff; - outBuff.dst = dst; - outBuff.pos = 0; - outBuff.size = *dstCapacityPtr; - inBuff.src = src; - inBuff.pos = 0; - inBuff.size = *srcSizePtr; - result = ZSTD_compressStream(zbc, &outBuff, &inBuff); - *dstCapacityPtr = outBuff.pos; - *srcSizePtr = inBuff.pos; - return result; -} - - - -/* ====== Finalize ====== */ - -size_t ZBUFF_compressFlush(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr) -{ - size_t result; - ZSTD_outBuffer outBuff; - outBuff.dst = dst; - outBuff.pos = 0; - outBuff.size = *dstCapacityPtr; - result = ZSTD_flushStream(zbc, &outBuff); - *dstCapacityPtr = outBuff.pos; - return result; -} - - -size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr) -{ - size_t result; - ZSTD_outBuffer outBuff; - outBuff.dst = dst; - outBuff.pos = 0; - outBuff.size = *dstCapacityPtr; - result = ZSTD_endStream(zbc, &outBuff); - *dstCapacityPtr = outBuff.pos; - return result; -} - - - -/* ************************************* -* Tool functions -***************************************/ -size_t ZBUFF_recommendedCInSize(void) { return ZSTD_CStreamInSize(); } -size_t ZBUFF_recommendedCOutSize(void) { return ZSTD_CStreamOutSize(); } +/* ZBUFF compatibility symbols are implemented by rust/src/zbuff.rs. */ diff --git a/lib/deprecated/zbuff_decompress.c b/lib/deprecated/zbuff_decompress.c index 12a66af74..26b312d19 100644 --- a/lib/deprecated/zbuff_decompress.c +++ b/lib/deprecated/zbuff_decompress.c @@ -1,77 +1 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * All rights reserved. - * - * This source code is licensed under both the BSD-style license (found in the - * LICENSE file in the root directory of this source tree) and the GPLv2 (found - * in the COPYING file in the root directory of this source tree). - * You may select, at your option, one of the above-listed licenses. - */ - - - -/* ************************************* -* Dependencies -***************************************/ -#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* suppress warning on ZSTD_initDStream_usingDict */ -#include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */ -#define ZBUFF_STATIC_LINKING_ONLY -#include "zbuff.h" - - -ZBUFF_DCtx* ZBUFF_createDCtx(void) -{ - return ZSTD_createDStream(); -} - -ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem) -{ - return ZSTD_createDStream_advanced(customMem); -} - -size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd) -{ - return ZSTD_freeDStream(zbd); -} - - -/* *** Initialization *** */ - -size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize) -{ - return ZSTD_initDStream_usingDict(zbd, dict, dictSize); -} - -size_t ZBUFF_decompressInit(ZBUFF_DCtx* zbd) -{ - return ZSTD_initDStream(zbd); -} - - -/* *** Decompression *** */ - -size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd, - void* dst, size_t* dstCapacityPtr, - const void* src, size_t* srcSizePtr) -{ - ZSTD_outBuffer outBuff; - ZSTD_inBuffer inBuff; - size_t result; - outBuff.dst = dst; - outBuff.pos = 0; - outBuff.size = *dstCapacityPtr; - inBuff.src = src; - inBuff.pos = 0; - inBuff.size = *srcSizePtr; - result = ZSTD_decompressStream(zbd, &outBuff, &inBuff); - *dstCapacityPtr = outBuff.pos; - *srcSizePtr = inBuff.pos; - return result; -} - - -/* ************************************* -* Tool functions -***************************************/ -size_t ZBUFF_recommendedDInSize(void) { return ZSTD_DStreamInSize(); } -size_t ZBUFF_recommendedDOutSize(void) { return ZSTD_DStreamOutSize(); } +/* ZBUFF compatibility symbols are implemented by rust/src/zbuff.rs. */ diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 437e25ed6..7b30d4504 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -23,6 +23,7 @@ pub mod mem; pub mod pool; pub mod threading; pub mod xxhash; +pub mod zbuff; pub mod zstd_common; #[cfg(feature = "compression")] pub mod zstd_compress; diff --git a/rust/src/zbuff.rs b/rust/src/zbuff.rs new file mode 100644 index 000000000..a23572b4b --- /dev/null +++ b/rust/src/zbuff.rs @@ -0,0 +1,363 @@ +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(clippy::missing_safety_doc)] +#![allow(clippy::too_many_arguments)] + +//! Deprecated buffered streaming compatibility wrappers. +//! +//! `ZBUFF_*` is an old spelling of the public `ZSTD_*Stream` API. The +//! wrappers deliberately keep the stream contexts opaque and forward to the +//! current implementation, so this module has no dependency on private +//! compressor or decompressor context layouts. + +use std::ffi::{c_char, c_int, c_void}; + +#[repr(C)] +pub struct ZBUFF_CCtx { + _private: [u8; 0], +} + +pub type ZBUFF_DCtx = ZBUFF_CCtx; + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct ZBUFF_customMem { + customAlloc: Option *mut c_void>, + customFree: Option, + opaque: *mut c_void, +} + +#[repr(C)] +#[derive(Clone, Copy)] +struct ZBUFF_compressionParameters { + windowLog: u32, + chainLog: u32, + hashLog: u32, + searchLog: u32, + minMatch: u32, + targetLength: u32, + strategy: c_int, +} + +#[repr(C)] +#[derive(Clone, Copy)] +struct ZBUFF_frameParameters { + contentSizeFlag: c_int, + checksumFlag: c_int, + noDictIDFlag: c_int, +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct ZBUFF_parameters { + cParams: ZBUFF_compressionParameters, + fParams: ZBUFF_frameParameters, +} + +#[repr(C)] +#[derive(Clone, Copy)] +struct ZBUFF_inBuffer { + src: *const c_void, + size: usize, + pos: usize, +} + +#[repr(C)] +#[derive(Clone, Copy)] +struct ZBUFF_outBuffer { + dst: *mut c_void, + size: usize, + pos: usize, +} + +#[cfg(feature = "compression")] +extern "C" { + fn ZSTD_createCStream() -> *mut ZBUFF_CCtx; + fn ZSTD_createCStream_advanced(customMem: ZBUFF_customMem) -> *mut ZBUFF_CCtx; + fn ZSTD_freeCStream(zcs: *mut ZBUFF_CCtx) -> usize; + fn ZSTD_CCtx_reset(zcs: *mut ZBUFF_CCtx, reset: c_int) -> usize; + fn ZSTD_CCtx_setPledgedSrcSize(zcs: *mut ZBUFF_CCtx, pledgedSrcSize: u64) -> usize; + fn ZSTD_checkCParams(params: ZBUFF_compressionParameters) -> usize; + fn ZSTD_CCtx_setCParams(zcs: *mut ZBUFF_CCtx, params: ZBUFF_compressionParameters) -> usize; + fn ZSTD_CCtx_setFParams(zcs: *mut ZBUFF_CCtx, params: ZBUFF_frameParameters) -> usize; + fn ZSTD_CCtx_setParameter(zcs: *mut ZBUFF_CCtx, param: c_int, value: c_int) -> usize; + fn ZSTD_CCtx_loadDictionary( + zcs: *mut ZBUFF_CCtx, + dict: *const c_void, + dictSize: usize, + ) -> usize; + fn ZSTD_initCStream(zcs: *mut ZBUFF_CCtx, compressionLevel: c_int) -> usize; + fn ZSTD_compressStream( + zcs: *mut ZBUFF_CCtx, + output: *mut ZBUFF_outBuffer, + input: *mut ZBUFF_inBuffer, + ) -> usize; + fn ZSTD_flushStream(zcs: *mut ZBUFF_CCtx, output: *mut ZBUFF_outBuffer) -> usize; + fn ZSTD_endStream(zcs: *mut ZBUFF_CCtx, output: *mut ZBUFF_outBuffer) -> usize; + fn ZSTD_CStreamInSize() -> usize; + fn ZSTD_CStreamOutSize() -> usize; +} + +#[cfg(feature = "decompression")] +extern "C" { + fn ZSTD_createDStream() -> *mut ZBUFF_DCtx; + fn ZSTD_createDStream_advanced(customMem: ZBUFF_customMem) -> *mut ZBUFF_DCtx; + fn ZSTD_freeDStream(zds: *mut ZBUFF_DCtx) -> usize; + fn ZSTD_initDStream(zds: *mut ZBUFF_DCtx) -> usize; + fn ZSTD_initDStream_usingDict( + zds: *mut ZBUFF_DCtx, + dict: *const c_void, + dictSize: usize, + ) -> usize; + fn ZSTD_decompressStream( + zds: *mut ZBUFF_DCtx, + output: *mut ZBUFF_outBuffer, + input: *mut ZBUFF_inBuffer, + ) -> usize; + fn ZSTD_DStreamInSize() -> usize; + fn ZSTD_DStreamOutSize() -> usize; +} + +extern "C" { + fn ZSTD_isError(code: usize) -> u32; + fn ZSTD_getErrorName(code: usize) -> *const c_char; +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_createCCtx() -> *mut ZBUFF_CCtx { + unsafe { ZSTD_createCStream() } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_createCCtx_advanced(customMem: ZBUFF_customMem) -> *mut ZBUFF_CCtx { + unsafe { ZSTD_createCStream_advanced(customMem) } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_freeCCtx(zbc: *mut ZBUFF_CCtx) -> usize { + unsafe { ZSTD_freeCStream(zbc) } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_compressInit_advanced( + zbc: *mut ZBUFF_CCtx, + dict: *const c_void, + dictSize: usize, + params: ZBUFF_parameters, + pledgedSrcSize: u64, +) -> usize { + let pledgedSrcSize = if pledgedSrcSize == 0 { + u64::MAX + } else { + pledgedSrcSize + }; + let result = unsafe { ZSTD_CCtx_reset(zbc, 1) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + let result = unsafe { ZSTD_CCtx_setPledgedSrcSize(zbc, pledgedSrcSize) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + let result = unsafe { ZSTD_checkCParams(params.cParams) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + let result = unsafe { ZSTD_CCtx_setFParams(zbc, params.fParams) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + let result = unsafe { ZSTD_CCtx_setCParams(zbc, params.cParams) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + unsafe { ZSTD_CCtx_loadDictionary(zbc, dict, dictSize) } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_compressInitDictionary( + zbc: *mut ZBUFF_CCtx, + dict: *const c_void, + dictSize: usize, + compressionLevel: c_int, +) -> usize { + let result = unsafe { ZSTD_CCtx_reset(zbc, 1) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + let result = unsafe { ZSTD_CCtx_setParameter(zbc, 100, compressionLevel) }; + if unsafe { ZSTD_isError(result) } != 0 { + return result; + } + unsafe { ZSTD_CCtx_loadDictionary(zbc, dict, dictSize) } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_compressInit( + zbc: *mut ZBUFF_CCtx, + compressionLevel: c_int, +) -> usize { + unsafe { ZSTD_initCStream(zbc, compressionLevel) } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_compressContinue( + zbc: *mut ZBUFF_CCtx, + dst: *mut c_void, + dstCapacityPtr: *mut usize, + src: *const c_void, + srcSizePtr: *mut usize, +) -> usize { + let mut output = ZBUFF_outBuffer { + dst, + pos: 0, + size: unsafe { *dstCapacityPtr }, + }; + let mut input = ZBUFF_inBuffer { + src, + pos: 0, + size: unsafe { *srcSizePtr }, + }; + let result = unsafe { ZSTD_compressStream(zbc, &mut output, &mut input) }; + unsafe { + *dstCapacityPtr = output.pos; + *srcSizePtr = input.pos; + } + result +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_compressFlush( + zbc: *mut ZBUFF_CCtx, + dst: *mut c_void, + dstCapacityPtr: *mut usize, +) -> usize { + let mut output = ZBUFF_outBuffer { + dst, + pos: 0, + size: unsafe { *dstCapacityPtr }, + }; + let result = unsafe { ZSTD_flushStream(zbc, &mut output) }; + unsafe { *dstCapacityPtr = output.pos }; + result +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_compressEnd( + zbc: *mut ZBUFF_CCtx, + dst: *mut c_void, + dstCapacityPtr: *mut usize, +) -> usize { + let mut output = ZBUFF_outBuffer { + dst, + pos: 0, + size: unsafe { *dstCapacityPtr }, + }; + let result = unsafe { ZSTD_endStream(zbc, &mut output) }; + unsafe { *dstCapacityPtr = output.pos }; + result +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub extern "C" fn ZBUFF_recommendedCInSize() -> usize { + unsafe { ZSTD_CStreamInSize() } +} + +#[cfg(feature = "compression")] +#[no_mangle] +pub extern "C" fn ZBUFF_recommendedCOutSize() -> usize { + unsafe { ZSTD_CStreamOutSize() } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_createDCtx() -> *mut ZBUFF_DCtx { + unsafe { ZSTD_createDStream() } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_createDCtx_advanced(customMem: ZBUFF_customMem) -> *mut ZBUFF_DCtx { + unsafe { ZSTD_createDStream_advanced(customMem) } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_freeDCtx(zbd: *mut ZBUFF_DCtx) -> usize { + unsafe { ZSTD_freeDStream(zbd) } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_decompressInitDictionary( + zbd: *mut ZBUFF_DCtx, + dict: *const c_void, + dictSize: usize, +) -> usize { + unsafe { ZSTD_initDStream_usingDict(zbd, dict, dictSize) } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_decompressInit(zbd: *mut ZBUFF_DCtx) -> usize { + unsafe { ZSTD_initDStream(zbd) } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_decompressContinue( + zbd: *mut ZBUFF_DCtx, + dst: *mut c_void, + dstCapacityPtr: *mut usize, + src: *const c_void, + srcSizePtr: *mut usize, +) -> usize { + let mut output = ZBUFF_outBuffer { + dst, + pos: 0, + size: unsafe { *dstCapacityPtr }, + }; + let mut input = ZBUFF_inBuffer { + src, + pos: 0, + size: unsafe { *srcSizePtr }, + }; + let result = unsafe { ZSTD_decompressStream(zbd, &mut output, &mut input) }; + unsafe { + *dstCapacityPtr = output.pos; + *srcSizePtr = input.pos; + } + result +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub extern "C" fn ZBUFF_recommendedDInSize() -> usize { + unsafe { ZSTD_DStreamInSize() } +} + +#[cfg(feature = "decompression")] +#[no_mangle] +pub extern "C" fn ZBUFF_recommendedDOutSize() -> usize { + unsafe { ZSTD_DStreamOutSize() } +} + +#[no_mangle] +pub extern "C" fn ZBUFF_isError(code: usize) -> u32 { + unsafe { ZSTD_isError(code) } +} + +#[no_mangle] +pub unsafe extern "C" fn ZBUFF_getErrorName(code: usize) -> *const c_char { + unsafe { ZSTD_getErrorName(code) } +}