Improve: Enable zstd multi-thread compression for client

This commit is contained in:
yuanyuanxiang
2025-08-13 04:54:33 +08:00
parent 303b5ef824
commit e779fb0b51
8 changed files with 95 additions and 7 deletions

31
common/zstd_wrapper.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef ZSTD_WRAPPER_H
#define ZSTD_WRAPPER_H
#include "zstd/zstd.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* 智能压缩函数(自动选择单线程/多线程)
* @param cctx 压缩上下文(需提前创建)
* @param dst 输出缓冲区
* @param dstCapacity 输出缓冲区大小
* @param src 输入数据
* @param srcSize 输入数据大小
* @param threshold 触发多线程的最小数据大小(建议 >= 1MB
* @return 压缩后的数据大小(错误码通过 ZSTD_isError() 检查)
*/
size_t zstd_compress_auto(
ZSTD_CCtx* cctx,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize,
size_t threshold
);
#ifdef __cplusplus
}
#endif
#endif // ZSTD_WRAPPER_H