Coverage Report

Created: 2026-06-07 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tdengine/include/util/tcompression.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15
16
#ifndef _TD_UTIL_COMPRESSION_H_
17
#define _TD_UTIL_COMPRESSION_H_
18
19
#include "os.h"
20
#include "taos.h"
21
#include "tutil.h"
22
23
#ifdef __cplusplus
24
extern "C" {
25
#endif
26
27
// start compress flag
28
// |----l1 compAlg----|-----l2 compAlg---|---level--|
29
// |------8bit--------|------16bit-------|---8bit---|
30
0
#define COMPRESS_L1_TYPE_U32(type)       (((type) >> 24) & 0xFF)
31
0
#define COMPRESS_L2_TYPE_U32(type)       (((type) >> 8) & 0xFFFF)
32
0
#define COMPRESS_L2_TYPE_LEVEL_U32(type) ((type)&0xFF)
33
// compress flag
34
// |----l2lel--|----l2Alg---|---l1Alg--|
35
// |----2bit---|----3bit----|---3bit---|
36
#define COMPRESS_L1_TYPE_U8(type)       ((type)&0x07)
37
#define COMPRESS_L2_TYPE_U8(type)       (((type) >> 3) & 0x07)
38
#define COMPRESS_L2_TYPE_LEVEL_U8(type) (((type) >> 6) & 0x03)
39
// end compress flag
40
41
0
#define COMP_OVERFLOW_BYTES 2
42
0
#define BITS_PER_BYTE       8
43
// Masks
44
0
#define INT64MASK(_x) ((((uint64_t)1) << _x) - 1)
45
0
#define INT32MASK(_x) (((uint32_t)1 << _x) - 1)
46
0
#define INT8MASK(_x)  (((uint8_t)1 << _x) - 1)
47
48
0
#define ZIGZAG_ENCODE(T, v) (((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1))  // zigzag encode
49
0
#define ZIGZAG_DECODE(T, v) (((v) >> 1) ^ -((T)((v)&1)))                                 // zigzag decode
50
51
// Compression algorithm
52
0
#define NO_COMPRESSION 0
53
0
#define ONE_STAGE_COMP 1
54
0
#define TWO_STAGE_COMP 2
55
56
//
57
// compressed data first byte foramt
58
//   ------ 7 bit ---- | ---- 1 bit ----
59
//        algorithm           mode
60
//
61
62
// compression data mode save first byte lower 1 bit
63
0
#define MODE_NOCOMPRESS 0  // original data
64
0
#define MODE_COMPRESS   1  // compatible old compress
65
66
// compression algorithm save first byte higher 7 bit
67
0
#define ALGO_SZ_LOSSY 1  // SZ compress
68
69
0
#define HEAD_MODE(x) x % 2
70
0
#define HEAD_ALGO(x) x / 2
71
72
#ifdef TD_TSZ
73
extern bool lossyFloat;
74
extern bool lossyDouble;
75
void tsCompressInit(char *lossyColumns, float fPrecision, double dPrecision, uint32_t maxIntervals, uint32_t intervals,
76
                    int32_t ifAdtFse, const char *compressor);
77
78
void tsCompressExit();
79
80
int32_t tsCompressFloatLossyImp(const char *const input, const int32_t nelements, char *const output);
81
int32_t tsDecompressFloatLossyImp(const char *const input, int32_t compressedSize, const int32_t nelements,
82
                                  char *const output);
83
int32_t tsCompressDoubleLossyImp(const char *const input, const int32_t nelements, char *const output);
84
int32_t tsDecompressDoubleLossyImp(const char *const input, int32_t compressedSize, const int32_t nelements,
85
                                   char *const output);
86
87
static FORCE_INLINE int32_t tsCompressFloatLossy(const char *const input, int32_t inputSize, const int32_t nelements,
88
                                                 char *const output, int32_t outputSize, char algorithm,
89
0
                                                 char *const buffer, int32_t bufferSize) {
90
0
  return tsCompressFloatLossyImp(input, nelements, output);
91
0
}
Unexecuted instantiation: parTranslater.c:tsCompressFloatLossy
Unexecuted instantiation: parInsertUtil.c:tsCompressFloatLossy
Unexecuted instantiation: functionMgt.c:tsCompressFloatLossy
Unexecuted instantiation: tudf.c:tsCompressFloatLossy
Unexecuted instantiation: builtinsimpl.c:tsCompressFloatLossy
Unexecuted instantiation: tavgfunction.c:tsCompressFloatLossy
Unexecuted instantiation: tminmax.c:tsCompressFloatLossy
Unexecuted instantiation: filter.c:tsCompressFloatLossy
Unexecuted instantiation: scalar.c:tsCompressFloatLossy
Unexecuted instantiation: sclfunc.c:tsCompressFloatLossy
Unexecuted instantiation: sclvector.c:tsCompressFloatLossy
Unexecuted instantiation: nodesCloneFuncs.c:tsCompressFloatLossy
Unexecuted instantiation: nodesCodeFuncs.c:tsCompressFloatLossy
Unexecuted instantiation: nodesMsgFuncs.c:tsCompressFloatLossy
Unexecuted instantiation: nodesUtilFuncs.c:tsCompressFloatLossy
Unexecuted instantiation: geomFunc.c:tsCompressFloatLossy
Unexecuted instantiation: tdecompressavx.c:tsCompressFloatLossy
Unexecuted instantiation: tpagedbuf.c:tsCompressFloatLossy
Unexecuted instantiation: tcompression.c:tsCompressFloatLossy
Unexecuted instantiation: tcol.c:tsCompressFloatLossy
Unexecuted instantiation: tdatablock.c:tsCompressFloatLossy
Unexecuted instantiation: tdataformat.c:tsCompressFloatLossy
Unexecuted instantiation: tmisce.c:tsCompressFloatLossy
Unexecuted instantiation: ttypes.c:tsCompressFloatLossy
Unexecuted instantiation: streamMsg.c:tsCompressFloatLossy
92
93
static FORCE_INLINE int32_t tsDecompressFloatLossy(const char *const input, int32_t compressedSize,
94
                                                   const int32_t nelements, char *const output, int32_t outputSize,
95
0
                                                   char algorithm, char *const buffer, int32_t bufferSize) {
96
0
  return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
97
0
}
Unexecuted instantiation: parTranslater.c:tsDecompressFloatLossy
Unexecuted instantiation: parInsertUtil.c:tsDecompressFloatLossy
Unexecuted instantiation: functionMgt.c:tsDecompressFloatLossy
Unexecuted instantiation: tudf.c:tsDecompressFloatLossy
Unexecuted instantiation: builtinsimpl.c:tsDecompressFloatLossy
Unexecuted instantiation: tavgfunction.c:tsDecompressFloatLossy
Unexecuted instantiation: tminmax.c:tsDecompressFloatLossy
Unexecuted instantiation: filter.c:tsDecompressFloatLossy
Unexecuted instantiation: scalar.c:tsDecompressFloatLossy
Unexecuted instantiation: sclfunc.c:tsDecompressFloatLossy
Unexecuted instantiation: sclvector.c:tsDecompressFloatLossy
Unexecuted instantiation: nodesCloneFuncs.c:tsDecompressFloatLossy
Unexecuted instantiation: nodesCodeFuncs.c:tsDecompressFloatLossy
Unexecuted instantiation: nodesMsgFuncs.c:tsDecompressFloatLossy
Unexecuted instantiation: nodesUtilFuncs.c:tsDecompressFloatLossy
Unexecuted instantiation: geomFunc.c:tsDecompressFloatLossy
Unexecuted instantiation: tdecompressavx.c:tsDecompressFloatLossy
Unexecuted instantiation: tpagedbuf.c:tsDecompressFloatLossy
Unexecuted instantiation: tcompression.c:tsDecompressFloatLossy
Unexecuted instantiation: tcol.c:tsDecompressFloatLossy
Unexecuted instantiation: tdatablock.c:tsDecompressFloatLossy
Unexecuted instantiation: tdataformat.c:tsDecompressFloatLossy
Unexecuted instantiation: tmisce.c:tsDecompressFloatLossy
Unexecuted instantiation: ttypes.c:tsDecompressFloatLossy
Unexecuted instantiation: streamMsg.c:tsDecompressFloatLossy
98
99
static FORCE_INLINE int32_t tsCompressDoubleLossy(const char *const input, int32_t inputSize, const int32_t nelements,
100
                                                  char *const output, int32_t outputSize, char algorithm,
101
0
                                                  char *const buffer, int32_t bufferSize) {
102
0
  return tsCompressDoubleLossyImp(input, nelements, output);
103
0
}
Unexecuted instantiation: parTranslater.c:tsCompressDoubleLossy
Unexecuted instantiation: parInsertUtil.c:tsCompressDoubleLossy
Unexecuted instantiation: functionMgt.c:tsCompressDoubleLossy
Unexecuted instantiation: tudf.c:tsCompressDoubleLossy
Unexecuted instantiation: builtinsimpl.c:tsCompressDoubleLossy
Unexecuted instantiation: tavgfunction.c:tsCompressDoubleLossy
Unexecuted instantiation: tminmax.c:tsCompressDoubleLossy
Unexecuted instantiation: filter.c:tsCompressDoubleLossy
Unexecuted instantiation: scalar.c:tsCompressDoubleLossy
Unexecuted instantiation: sclfunc.c:tsCompressDoubleLossy
Unexecuted instantiation: sclvector.c:tsCompressDoubleLossy
Unexecuted instantiation: nodesCloneFuncs.c:tsCompressDoubleLossy
Unexecuted instantiation: nodesCodeFuncs.c:tsCompressDoubleLossy
Unexecuted instantiation: nodesMsgFuncs.c:tsCompressDoubleLossy
Unexecuted instantiation: nodesUtilFuncs.c:tsCompressDoubleLossy
Unexecuted instantiation: geomFunc.c:tsCompressDoubleLossy
Unexecuted instantiation: tdecompressavx.c:tsCompressDoubleLossy
Unexecuted instantiation: tpagedbuf.c:tsCompressDoubleLossy
Unexecuted instantiation: tcompression.c:tsCompressDoubleLossy
Unexecuted instantiation: tcol.c:tsCompressDoubleLossy
Unexecuted instantiation: tdatablock.c:tsCompressDoubleLossy
Unexecuted instantiation: tdataformat.c:tsCompressDoubleLossy
Unexecuted instantiation: tmisce.c:tsCompressDoubleLossy
Unexecuted instantiation: ttypes.c:tsCompressDoubleLossy
Unexecuted instantiation: streamMsg.c:tsCompressDoubleLossy
104
105
static FORCE_INLINE int32_t tsDecompressDoubleLossy(const char *const input, int32_t compressedSize,
106
                                                    const int32_t nelements, char *const output, int32_t outputSize,
107
0
                                                    char algorithm, char *const buffer, int32_t bufferSize) {
108
0
  return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
109
0
}
Unexecuted instantiation: parTranslater.c:tsDecompressDoubleLossy
Unexecuted instantiation: parInsertUtil.c:tsDecompressDoubleLossy
Unexecuted instantiation: functionMgt.c:tsDecompressDoubleLossy
Unexecuted instantiation: tudf.c:tsDecompressDoubleLossy
Unexecuted instantiation: builtinsimpl.c:tsDecompressDoubleLossy
Unexecuted instantiation: tavgfunction.c:tsDecompressDoubleLossy
Unexecuted instantiation: tminmax.c:tsDecompressDoubleLossy
Unexecuted instantiation: filter.c:tsDecompressDoubleLossy
Unexecuted instantiation: scalar.c:tsDecompressDoubleLossy
Unexecuted instantiation: sclfunc.c:tsDecompressDoubleLossy
Unexecuted instantiation: sclvector.c:tsDecompressDoubleLossy
Unexecuted instantiation: nodesCloneFuncs.c:tsDecompressDoubleLossy
Unexecuted instantiation: nodesCodeFuncs.c:tsDecompressDoubleLossy
Unexecuted instantiation: nodesMsgFuncs.c:tsDecompressDoubleLossy
Unexecuted instantiation: nodesUtilFuncs.c:tsDecompressDoubleLossy
Unexecuted instantiation: geomFunc.c:tsDecompressDoubleLossy
Unexecuted instantiation: tdecompressavx.c:tsDecompressDoubleLossy
Unexecuted instantiation: tpagedbuf.c:tsDecompressDoubleLossy
Unexecuted instantiation: tcompression.c:tsDecompressDoubleLossy
Unexecuted instantiation: tcol.c:tsDecompressDoubleLossy
Unexecuted instantiation: tdatablock.c:tsDecompressDoubleLossy
Unexecuted instantiation: tdataformat.c:tsDecompressDoubleLossy
Unexecuted instantiation: tmisce.c:tsDecompressDoubleLossy
Unexecuted instantiation: ttypes.c:tsDecompressDoubleLossy
Unexecuted instantiation: streamMsg.c:tsDecompressDoubleLossy
110
111
#endif
112
113
/*************************************************************************
114
 *                  REGULAR COMPRESSION
115
 *************************************************************************/
116
int32_t tsCompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
117
                            int32_t nBuf);
118
int32_t tsDecompressTimestamp(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg,
119
                              void *pBuf, int32_t nBuf);
120
int32_t tsCompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
121
                        int32_t nBuf);
122
int32_t tsDecompressFloat(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
123
                          int32_t nBuf);
124
int32_t tsCompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
125
                         int32_t nBuf);
126
int32_t tsDecompressDouble(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
127
                           int32_t nBuf);
128
int32_t tsCompressString(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
129
                         int32_t nBuf);
130
int32_t tsDecompressString(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
131
                           int32_t nBuf);
132
int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
133
                       int32_t nBuf);
134
int32_t tsDecompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
135
                         int32_t nBuf);
136
int32_t tsCompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
137
                          int32_t nBuf);
138
int32_t tsDecompressTinyint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
139
                            int32_t nBuf);
140
int32_t tsCompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
141
                           int32_t nBuf);
142
int32_t tsDecompressSmallint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg,
143
                             void *pBuf, int32_t nBuf);
144
int32_t tsCompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
145
                      int32_t nBuf);
146
int32_t tsDecompressInt(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
147
                        int32_t nBuf);
148
int32_t tsCompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
149
                         int32_t nBuf);
150
int32_t tsDecompressBigint(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint8_t cmprAlg, void *pBuf,
151
                           int32_t nBuf);
152
// for internal usage
153
int32_t getWordLength(char type);
154
155
int32_t tsDecompressIntImpl_Hw(const char *const input, const int32_t nelements, char *const output, const char type);
156
int32_t tsDecompressFloatImpAvx2(const char *input, int32_t nelements, char *output);
157
int32_t tsDecompressDoubleImpAvx2(const char *input, int32_t nelements, char *output);
158
int32_t tsDecompressTimestampAvx2(const char *input, int32_t nelements, char *output, bool bigEndian);
159
int32_t tsDecompressTimestampAvx512(const char *const input, const int32_t nelements, char *const output,
160
                                    bool bigEndian);
161
162
/*************************************************************************
163
 *                  REGULAR COMPRESSION 2
164
 *************************************************************************/
165
int32_t tsCompressTimestamp2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
166
                             void *pBuf, int32_t nBuf);
167
int32_t tsDecompressTimestamp2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
168
                               void *pBuf, int32_t nBuf);
169
int32_t tsCompressFloat2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
170
                         int32_t nBuf);
171
int32_t tsDecompressFloat2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
172
                           int32_t nBuf);
173
int32_t tsCompressDouble2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
174
                          int32_t nBuf);
175
int32_t tsDecompressDouble2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
176
                            void *pBuf, int32_t nBuf);
177
int32_t tsCompressString2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
178
                          int32_t nBuf);
179
int32_t tsDecompressString2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
180
                            void *pBuf, int32_t nBuf);
181
int32_t tsCompressBool2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
182
                        int32_t nBuf);
183
int32_t tsDecompressBool2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
184
                          int32_t nBuf);
185
int32_t tsCompressTinyint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
186
                           int32_t nBuf);
187
int32_t tsDecompressTinyint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
188
                             void *pBuf, int32_t nBuf);
189
int32_t tsCompressSmallint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
190
                            void *pBuf, int32_t nBuf);
191
int32_t tsDecompressSmallint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
192
                              void *pBuf, int32_t nBuf);
193
int32_t tsCompressInt2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
194
                       int32_t nBuf);
195
int32_t tsDecompressInt2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
196
                         int32_t nBuf);
197
int32_t tsCompressBigint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg, void *pBuf,
198
                          int32_t nBuf);
199
int32_t tsDecompressBigint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
200
                            void *pBuf, int32_t nBuf);
201
int32_t tsCompressDecimal64(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
202
                            void *pBuf, int32_t nBuf);
203
int32_t tsDecompressDecimal64(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
204
                              void *pBuf, int32_t nBuf);
205
int32_t tsCompressDecimal128(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
206
                             void *pBuf, int32_t nBuf);
207
int32_t tsDecompressDecimal128(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t nOut, uint32_t cmprAlg,
208
                               void *pBuf, int32_t nBuf);
209
210
/*************************************************************************
211
 *                  STREAM COMPRESSION
212
 *************************************************************************/
213
typedef struct SCompressor SCompressor;
214
215
int32_t tCompressorCreate(SCompressor **ppCmprsor);
216
int32_t tCompressorDestroy(SCompressor *pCmprsor);
217
int32_t tCompressStart(SCompressor *pCmprsor, int8_t type, int8_t cmprAlg);
218
int32_t tCompressEnd(SCompressor *pCmprsor, const uint8_t **ppOut, int32_t *nOut, int32_t *nOrigin);
219
int32_t tCompress(SCompressor *pCmprsor, const void *pData, int64_t nData);
220
221
typedef int32_t (*__data_compress_init)(char *lossyColumns, float fPrecision, double dPrecision, uint32_t maxIntervals,
222
                                        uint32_t intervals, int32_t ifAdtFse, const char *compressor);
223
typedef int32_t (*__data_compress_l1_fn_t)(const char *const input, const int32_t nelements, char *const output,
224
                                           const char type);
225
typedef int32_t (*__data_decompress_l1_fn_t)(const char *const input, int32_t ninput, const int32_t nelements,
226
                                             char *const output, const char type);
227
228
typedef int32_t (*__data_compress_l2_fn_t)(const char *const input, const int32_t nelements, char *const output,
229
                                           int32_t outputSize, const char type, int8_t level);
230
typedef int32_t (*__data_decompress_l2_fn_t)(const char *const input, const int32_t nelements, char *const output,
231
                                             int32_t outputSize, const char type);
232
233
typedef struct {
234
  char                     *name;
235
  __data_compress_init      initFn;
236
  __data_compress_l1_fn_t   comprFn;
237
  __data_decompress_l1_fn_t decomprFn;
238
} TCmprL1FnSet;
239
240
typedef struct {
241
  char                     *name;
242
  __data_compress_init      initFn;
243
  __data_compress_l2_fn_t   comprFn;
244
  __data_decompress_l2_fn_t decomprFn;
245
} TCmprL2FnSet;
246
247
typedef enum {
248
  L1_UNKNOWN = 0,
249
  L1_SIMPLE_8B,
250
  L1_XOR,
251
  L1_RLE,
252
  L1_DELTAD,
253
  L1_BSS,
254
  L1_DISABLED = 0xFF,
255
} TCmprL1Type;
256
257
typedef enum {
258
  L2_UNKNOWN = 0,
259
  L2_LZ4,
260
  L2_ZLIB,
261
  L2_ZSTD,
262
  L2_TSZ,
263
  L2_XZ,
264
  L2_DISABLED = 0xFF,
265
} TCmprL2Type;
266
267
typedef enum {
268
  L2_LVL_NOCHANGE = 0,
269
  L2_LVL_LOW,
270
  L2_LVL_MEDIUM,
271
  L2_LVL_HIGH,
272
  L2_LVL_DISABLED = 0xFF,
273
} TCmprLvlType;
274
275
typedef struct {
276
  char   *name;
277
  uint8_t lvl[3];  // l[0] = 'low', l[1] = 'mid', l[2] = 'high'
278
} TCmprLvlSet;
279
280
void tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t *level);
281
282
#define DEFINE_VAR(cmprAlg)                   \
283
0
  uint8_t l1 = COMPRESS_L1_TYPE_U32(cmprAlg); \
284
0
  uint8_t l2 = COMPRESS_L2_TYPE_U32(cmprAlg); \
285
0
  uint8_t lvl = COMPRESS_L2_TYPE_LEVEL_U32(cmprAlg);
286
287
#define SET_COMPRESS(l1, l2, lvl, cmpr) \
288
0
  do {                                  \
289
0
    (cmpr) &= 0x00FFFFFF;               \
290
0
    (cmpr) |= ((l1) << 24);             \
291
0
    (cmpr) &= 0xFF0000FF;               \
292
0
    (cmpr) |= ((l2) << 8);              \
293
0
    (cmpr) &= 0xFFFFFF00;               \
294
0
    (cmpr) |= (lvl);                    \
295
0
  } while (0)
296
int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, uint8_t lvlDisabled, uint8_t lvlDefault,
297
                       uint32_t *dst);
298
#ifdef __cplusplus
299
}
300
#endif
301
302
int32_t plainCompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
303
int32_t plainDecompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
304
305
int32_t lz4CompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
306
int32_t lz4DecompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
307
308
int32_t zlibCompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
309
int32_t zlibDecompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
310
311
int32_t zstdCompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
312
int32_t zstdDecompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
313
314
int32_t xzCompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
315
int32_t xzDecompressImpl(void *src, int32_t srcSize, void *dst, int32_t *dstSize);
316
317
#endif /*_TD_UTIL_COMPRESSION_H_*/