31 #if defined(ENABLE_LZ4)
41 lz4_compress_init(
struct compress_context *compctx)
48 lz4v2_compress_init(
struct compress_context *compctx)
54 lz4_compress_uninit(
struct compress_context *compctx)
59 do_lz4_compress(
struct buffer *buf,
61 struct compress_context *compctx,
71 int zlen_max = ps + COMP_EXTRA_BUFFER(ps);
84 zlen = LZ4_compress_default((
const char *)
BPTR(buf), (
char *)
BPTR(work),
BLEN(buf), zlen_max);
98 compctx->pre_compress += buf->
len;
99 compctx->post_compress += work->
len;
108 struct compress_context *compctx,
117 compressed = do_lz4_compress(buf, &work, compctx,
frame);
127 uint8_t comp_head_byte = NO_COMPRESS_BYTE_SWAP;
128 if (compressed && work.
len < buf->
len)
131 comp_head_byte = LZ4_COMPRESS_BYTE;
135 uint8_t *head =
BPTR(buf);
136 uint8_t *tail =
BEND(buf);
142 *head = comp_head_byte;
150 struct compress_context *compctx,
159 compressed = do_lz4_compress(buf, &work, compctx,
frame);
169 if (compressed && work.
len + 2 < buf->
len)
172 uint8_t *head =
BPTR(&work);
173 head[0] = COMP_ALGV2_INDICATOR_BYTE;
174 head[1] = COMP_ALGV2_LZ4_BYTE;
179 compv2_escape_data_ifneeded(buf);
184 do_lz4_decompress(
size_t zlen_max,
187 struct compress_context *compctx)
191 uncomp_len = LZ4_decompress_safe((
const char *)
BPTR(buf), (
char *)
BPTR(work), (
size_t)
BLEN(buf), zlen_max);
200 work->
len = uncomp_len;
203 compctx->pre_decompress += buf->
len;
204 compctx->post_decompress += work->
len;
211 struct compress_context *compctx,
226 uint8_t *head =
BPTR(buf);
232 if (c == LZ4_COMPRESS_BYTE)
234 do_lz4_decompress(zlen_max, &work, buf, compctx);
236 else if (c == NO_COMPRESS_BYTE_SWAP)
248 lz4v2_decompress(
struct buffer *buf,
struct buffer work,
249 struct compress_context *compctx,
263 uint8_t *head =
BPTR(buf);
267 if (c != COMP_ALGV2_INDICATOR_BYTE)
280 if (c == COMP_ALGV2_LZ4_BYTE)
283 do_lz4_decompress(zlen_max, &work, buf, compctx);
285 else if (c == COMP_ALGV2_UNCOMPRESSED_BYTE)
296 const struct compress_alg lz4_alg = {
304 const struct compress_alg lz4v2_alg = {