Skip to content

Commit 10e0f91

Browse files
committed
build: flb_unicode: Add proxy component of calling simdutf stuffs
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 839cd73 commit 10e0f91

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

include/fluent-bit/flb_unicode.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2024 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#ifndef FLB_UNICODE
21+
#define FLB_UNICODE
22+
23+
#include <stddef.h>
24+
25+
#ifdef FLB_HAVE_UNICODE_ENCODER
26+
#include <fluent-bit/simdutf/flb_simdutf_connector.h>
27+
28+
#define FLB_UNICODE_CONVERT_OK FLB_SIMDUTF_CONNECTOR_CONVERT_OK
29+
#define FLB_UNICODE_CONVERT_NOP FLB_SIMDUTF_CONNECTOR_CONVERT_NOP
30+
#define FLB_UNICODE_CONVERT_UNSUPPORTED FLB_SIMDUTF_CONNECTOR_CONVERT_UNSUPPORTED
31+
#define FLB_UNICODE_CONVERT_ERROR FLB_SIMDUTF_CONNECTOR_CONVERT_ERROR
32+
33+
enum flb_unicode_endocing_type {
34+
FLB_UNICODE_ENCODING_UTF8 = FLB_SIMDUTF_ENCODING_TYPE_UTF8, /* BOM 0xef 0xbb 0xbf */
35+
FLB_UNICODE_ENCODING_UTF16_LE = FLB_SIMDUTF_ENCODING_TYPE_UTF16_LE, /* BOM 0xff 0xfe */
36+
FLB_UNICODE_ENCODING_UTF16_BE = FLB_SIMDUTF_ENCODING_TYPE_UTF16_BE, /* BOM 0xfe 0xff */
37+
FLB_UNICODE_ENCODING_UTF32_LE = FLB_SIMDUTF_ENCODING_TYPE_UTF32_LE, /* BOM 0xff 0xfe 0x00 0x00 */
38+
FLB_UNICODE_ENCODING_UTF32_BE = FLB_SIMDUTF_ENCODING_TYPE_UTF32_BE, /* BOM 0x00 0x00 0xfe 0xff */
39+
FLB_UNICODE_ENCODING_Latin1 = FLB_SIMDUTF_ENCODING_TYPE_Latin1,
40+
41+
FLB_UNICODE_ENCODING_UNSPECIFIED = FLB_SIMDUTF_ENCODING_TYPE_UNSPECIFIED,
42+
FLB_UNICODE_ENCODING_AUTO = FLB_SIMDUTF_ENCODING_TYPE_UNICODE_AUTO, /* Automatically detecting flag*/
43+
};
44+
45+
#else
46+
47+
#define FLB_UNICODE_CONVERT_OK 0
48+
#define FLB_UNICODE_CONVERT_UNSUPPORTED -2
49+
50+
#endif
51+
52+
/* Mainly converting from UTF-16LE/BE to UTF-8 */
53+
int flb_unicode_convert(int preferred_encoding, const char *input, size_t length,
54+
char **output, size_t *out_size);
55+
int flb_unicode_validate(const char *record, size_t size);
56+
57+
#endif

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ endif()
346346

347347
if(FLB_UNICODE_ENCODER)
348348
add_subdirectory(simdutf)
349+
set(src
350+
${src}
351+
"flb_unicode.c"
352+
)
349353
endif()
350354

351355
# WAMRC compiler

src/flb_unicode.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2024 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
21+
#include <fluent-bit/flb_unicode.h>
22+
#include <stddef.h>
23+
24+
int flb_unicode_convert(int preferred_encoding, const char *input, size_t length,
25+
char **output, size_t *out_size)
26+
{
27+
#ifdef FLB_HAVE_UNICODE_ENCODER
28+
return flb_simdutf_connector_convert_from_unicode(preferred_encoding, input, length,
29+
output, out_size);
30+
#else
31+
return FLB_UNICODE_CONVERT_UNSUPPORTED;
32+
#endif
33+
}
34+
35+
int flb_unicode_validate(const char *record, size_t size)
36+
{
37+
#ifdef FLB_HAVE_UNICODE_ENCODER
38+
return flb_simdutf_connector_validate_utf8(record, size);
39+
#else
40+
return -1;
41+
#endif
42+
}

0 commit comments

Comments
 (0)