zstd优化接口。
压缩接口:
解压接口:
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
cctx |
结构体指针 |
待压缩内容初始化参数信息。 (通过开源zstd提供的ZSTD_createCCTX()函数接口进行初始化创建。通过ZSTD_CCtx_setParameter()函数接口进行参数赋值。具体可参见zstd.h头文件) |
输入 |
dst |
指针数组 |
存储压缩后内容的目标数组。 |
输入/输出 |
dstCapacity |
整型数 |
压缩后内容的字节数。 |
输入 |
src |
指针数组 |
存储待压缩内容的源数组。 |
输入 |
srcSize |
整型数 |
待压缩内容的字节数。 |
输入 |
ret |
整型数 |
成功返回压缩后的字节数,失败返回错误码。 |
输出 |
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
dst |
指针数组 |
存储解压后内容的目标数组。 |
输入/输出 |
dstCapacity |
整型数 |
解压后内容的字节数上界 |
输入 |
src |
指针数组 |
存储待解压内容的源数组。 |
输入 |
compressedSize |
整型数 |
待解压内容的字节数。 |
输入 |
ret |
整型数 |
成功返回解压后的原始内容字节数,失败返回错误码。 |
输出 |
1 | vi test.c
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdint.h> #include <stdio.h> #include <assert.h> #include <string.h> #include "/usr/ksal_zstd/zstd.h" #define BLOCK_SIZE (128 * 1024) #define DST_SIZE (1024 * 1024) uint8_t inn[BLOCK_SIZE]={0}; uint8_t outt[DST_SIZE]; uint8_t doutt[DST_SIZE]; int main(int argc, char **argv) { ZSTD_CCtx *cctx = ZSTD_createCCtx(); ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 5); size_t compressed = ZSTD_compress2(cctx, (void *)outt, DST_SIZE, (void *)inn, BLOCK_SIZE); size_t decompressed = ZSTD_decompress(doutt, DST_SIZE, outt, compressed); assert(decompressed == BLOCK_SIZE); assert(memcmp(doutt, inn, BLOCK_SIZE) == 0); ZSTD_freeCCtx(cctx); printf("compression and decompression succ!!\n"); return 0; } |
1 | gcc test.c -L/usr/ksal_zstd -l:libzstd.so -o test |
1 | LD_PRELOAD=/usr/ksal_zstd/libzstd.so ./test |
1 | compression and decompression succ!! |