Skip to content

Commit

Permalink
in_tail: Align 2-bytes alignments if UTF-16 encodings are enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Oct 10, 2024
1 parent 9205803 commit 4bc8502
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/in_tail/tail_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ static int multiline_load_parsers(struct flb_tail_config *ctx)
return 0;
}

static void adjust_buffer_for_2bytes_alignments(struct flb_tail_config *ctx)
{
if ((ctx->buf_max_size - 1) % 2) {
ctx->buf_max_size++;
flb_plg_info(ctx->ins, "adjusted buf_max_size to %zd", ctx->buf_max_size);
}
if ((ctx->buf_chunk_size - 1) % 2) {
ctx->buf_chunk_size++;
flb_plg_info(ctx->ins, "adjusted buf_chunk_size to %zd", ctx->buf_chunk_size);
}
}

struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
struct flb_config *config)
{
Expand Down Expand Up @@ -190,14 +202,17 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
if (tmp) {
if (strcasecmp(tmp, "auto") == 0) {
ctx->preferred_input_encoding = FLB_SIMDUTF_ENCODING_TYPE_UNICODE_AUTO;
adjust_buffer_for_2bytes_alignments(ctx);
}
else if (strcasecmp(tmp, "utf-16le") == 0 ||
strcasecmp(tmp, "utf16-le") == 0) {
ctx->preferred_input_encoding = FLB_SIMDUTF_ENCODING_TYPE_UTF16_LE;
adjust_buffer_for_2bytes_alignments(ctx);
}
else if (strcasecmp(tmp, "utf-16be") == 0 ||
strcasecmp(tmp, "utf16-be") == 0) {
ctx->preferred_input_encoding = FLB_SIMDUTF_ENCODING_TYPE_UTF16_BE;
adjust_buffer_for_2bytes_alignments(ctx);
}
else {
flb_plg_error(ctx->ins, "invalid encoding 'unicode.encoding' value");
Expand Down

0 comments on commit 4bc8502

Please sign in to comment.