2020#include <fluent-bit.h>
2121#include <fluent-bit/flb_pack_json.h>
2222
23- int flb_pack_json_ext (const char * json , size_t len ,
24- char * * out_buf , size_t * out_size ,
25- int * out_root_type ,
26- struct flb_pack_opts * opts )
23+ static int flb_pack_json_ext_internal (const char * json , size_t len ,
24+ char * * out_buf , size_t * out_size ,
25+ int * out_root_type , int * out_records ,
26+ size_t * consumed ,
27+ struct flb_pack_opts * opts ,
28+ int require_records )
2729{
2830 int backend ;
2931 struct flb_pack_state * state = NULL ;
@@ -42,23 +44,54 @@ int flb_pack_json_ext(const char *json, size_t len,
4244 }
4345
4446 if (backend == FLB_PACK_JSON_BACKEND_JSMN ) {
45- /* jsmn */
4647 if (state ) {
4748 /* state for incremental reads */
49+ if (require_records ) {
50+ return -1 ;
51+ }
52+
4853 return flb_pack_json_state (json , len , out_buf , out_size , state );
4954 }
50- else {
51- /* jsmn (no state) */
52- return flb_pack_json (json , len , out_buf , out_size ,
53- out_root_type , NULL );
55+
56+ if ( require_records ) {
57+ return flb_pack_json_recs (json , len , out_buf , out_size ,
58+ out_root_type , out_records , consumed );
5459 }
60+
61+ return flb_pack_json (json , len , out_buf , out_size ,
62+ out_root_type , NULL );
5563 }
5664 else if (backend == FLB_PACK_JSON_BACKEND_YYJSON ) {
57- /* yyjson */
65+ if (require_records ) {
66+ return flb_pack_json_recs_yyjson (json , len , out_buf , out_size ,
67+ out_root_type , out_records ,
68+ consumed );
69+ }
70+
5871 return flb_pack_json_yyjson (json , len , out_buf , out_size ,
5972 out_root_type , NULL );
6073 }
6174
6275 /* unknown backend */
6376 return -1 ;
6477}
78+
79+ int flb_pack_json_ext (const char * json , size_t len ,
80+ char * * out_buf , size_t * out_size ,
81+ int * out_root_type ,
82+ struct flb_pack_opts * opts )
83+ {
84+ return flb_pack_json_ext_internal (json , len , out_buf , out_size ,
85+ out_root_type , NULL , NULL ,
86+ opts , FLB_FALSE );
87+ }
88+
89+ int flb_pack_json_recs_ext (const char * json , size_t len ,
90+ char * * out_buf , size_t * out_size ,
91+ int * out_root_type , int * out_records ,
92+ size_t * consumed , struct flb_pack_opts * opts )
93+ {
94+ return flb_pack_json_ext_internal (json , len , out_buf , out_size ,
95+ out_root_type , out_records ,
96+ consumed , opts , FLB_TRUE );
97+ }
0 commit comments