pack: allow json record to format without a 'date key'
@@ -715,13 +715,11 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
msgpack_sbuffer tmp_sbuf;
msgpack_packer tmp_pck;
msgpack_object *obj;
+ msgpack_object *k;
+ msgpack_object *v;
struct tm tm;
struct flb_time tms;
- if (!date_key) {
- return NULL;
- }
-
/* Iterate the original buffer and perform adjustments */
records = flb_mp_count(data, bytes);
if (records <= 0) {
@@ -770,8 +768,15 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
/* Get the record/map */
map = root.via.array.ptr[1];
map_size = map.via.map.size;
+
+ if (date_key != NULL) {
msgpack_pack_map(&tmp_pck, map_size + 1);
+ }
+ else {
+ msgpack_pack_map(&tmp_pck, map_size);
+ }
+ if (date_key != NULL) {
/* Append date key */
msgpack_pack_str(&tmp_pck, flb_sds_len(date_key));
msgpack_pack_str_body(&tmp_pck, date_key, flb_sds_len(date_key));
@@ -799,12 +804,12 @@ flb_sds_t flb_pack_msgpack_to_json_format(const char *data, uint64_t bytes,
msgpack_pack_uint64(&tmp_pck, (long long unsigned)(tms.tm.tv_sec));
break;
}
+ }
/* Append remaining keys/values */
for (i = 0; i < map_size; i++) {
- msgpack_object *k = &map.via.map.ptr[i].key;
- msgpack_object *v = &map.via.map.ptr[i].val;
-
+ k = &map.via.map.ptr[i].key;
+ v = &map.via.map.ptr[i].val;
msgpack_pack_object(&tmp_pck, *k);
msgpack_pack_object(&tmp_pck, *v);
}
