1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* Fluent Bit 4 * ========== 5 * Copyright (C) 2019-2021 The Fluent Bit Authors 6 * Copyright (C) 2015-2018 Treasure Data Inc. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 #ifndef FLB_MP_H 22 #define FLB_MP_H 23 24 #include <msgpack.h> 25 26 #define FLB_MP_MAP MSGPACK_OBJECT_MAP 27 #define FLB_MP_ARRAY MSGPACK_OBJECT_ARRAY 28 29 int flb_mp_count(const void *data, size_t bytes); 30 int flb_mp_validate_chunk(const void *data, size_t bytes, 31 int *out_records, size_t *processed_bytes); 32 void flb_mp_set_map_header_size(char *buf, int arr_size); 33 34 35 /* 36 * Map header handling functions 37 */ 38 struct flb_mp_map_header { 39 off_t offset; 40 size_t entries; 41 void *data; 42 }; 43 44 45 /* */ 46 struct flb_mp_accessor_match { 47 int matched; 48 msgpack_object *start_key; 49 msgpack_object *key; 50 msgpack_object *val; 51 struct flb_record_accessor *ra; 52 }; 53 54 /* A context to abstract usage of record accessor when multiple patterns exists */ 55 struct flb_mp_accessor { 56 int matches_size; 57 struct flb_mp_accessor_match *matches; 58 struct mk_list ra_list; 59 }; 60 61 int flb_mp_map_header_init(struct flb_mp_map_header *mh, msgpack_packer *mp_pck); 62 int flb_mp_map_header_append(struct flb_mp_map_header *mh); 63 void flb_mp_map_header_end(struct flb_mp_map_header *mh); 64 65 int flb_mp_array_header_init(struct flb_mp_map_header *mh, msgpack_packer *mp_pck); 66 int flb_mp_array_header_append(struct flb_mp_map_header *mh); 67 void flb_mp_array_header_end(struct flb_mp_map_header *mh); 68 69 /* mp accessor api */ 70 struct flb_mp_accessor *flb_mp_accessor_create(struct mk_list *slist_patterns); 71 void flb_mp_accessor_destroy(struct flb_mp_accessor *mpa); 72 int flb_mp_accessor_keys_remove(struct flb_mp_accessor *mpa, 73 msgpack_object *map, 74 void **out_buf, size_t *out_size); 75 76 #endif 77