Skip to content

Commit b2ad5b9

Browse files
committed
compression: Process zstd dispatcher
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 458615c commit b2ad5b9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

include/fluent-bit/flb_compression.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#define FLB_COMPRESSION_ALGORITHM_NONE 0
2828
#define FLB_COMPRESSION_ALGORITHM_GZIP 1
29+
#define FLB_COMPRESSION_ALGORITHM_ZSTD 2
2930

3031
#define FLB_DECOMPRESSOR_STATE_FAILED -1
3132
#define FLB_DECOMPRESSOR_STATE_EXPECTING_HEADER 0

src/flb_compression.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <fluent-bit/flb_mem.h>
2222
#include <fluent-bit/flb_log.h>
2323
#include <fluent-bit/flb_gzip.h>
24+
#include <fluent-bit/flb_zstd.h>
2425
#include <fluent-bit/flb_compression.h>
2526

2627
static size_t flb_decompression_context_get_read_buffer_offset(
@@ -131,7 +132,12 @@ void flb_decompression_context_destroy(struct flb_decompression_context *context
131132
}
132133

133134
if (context->inner_context != NULL) {
134-
flb_gzip_decompression_context_destroy(context->inner_context);
135+
if (context->algorithm == FLB_COMPRESSION_ALGORITHM_GZIP) {
136+
flb_gzip_decompression_context_destroy(context->inner_context);
137+
}
138+
else if (context->algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD) {
139+
flb_zstd_decompression_context_destroy(context->inner_context);
140+
}
135141

136142
context->inner_context = NULL;
137143
}
@@ -178,6 +184,9 @@ struct flb_decompression_context *flb_decompression_context_create(int algorithm
178184
if (algorithm == FLB_COMPRESSION_ALGORITHM_GZIP) {
179185
context->inner_context = flb_gzip_decompression_context_create();
180186
}
187+
else if (algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD) {
188+
context->inner_context = flb_zstd_decompression_context_create();
189+
}
181190
else {
182191
flb_error("invalid compression algorithm : %d", algorithm);
183192

@@ -199,7 +208,12 @@ struct flb_decompression_context *flb_decompression_context_create(int algorithm
199208
context->input_buffer_size = input_buffer_size;
200209
context->read_buffer = context->read_buffer;
201210
context->algorithm = algorithm;
202-
context->state = FLB_DECOMPRESSOR_STATE_EXPECTING_HEADER;
211+
if (algorithm == FLB_COMPRESSION_ALGORITHM_GZIP) {
212+
context->state = FLB_DECOMPRESSOR_STATE_EXPECTING_HEADER;
213+
}
214+
else if (algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD) {
215+
context->state = FLB_DECOMPRESSOR_STATE_EXPECTING_BODY;
216+
}
203217

204218
return context;
205219
}
@@ -215,6 +229,12 @@ int flb_decompress(struct flb_decompression_context *context,
215229
output_length);
216230

217231
}
232+
else if (context->algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD) {
233+
return flb_zstd_decompressor_dispatch(context,
234+
output_buffer,
235+
output_length);
236+
237+
}
218238
}
219239

220240
return FLB_DECOMPRESSOR_FAILURE;

0 commit comments

Comments
 (0)