out_nats: use flb_msgpack_raw_to_json_sds() instead of old ...raw_to_json_str()
@@ -78,10 +78,10 @@ static int msgpack_to_json(const void *data, size_t bytes,
char **out_json, size_t *out_size)
{
int i;
- int ret;
int map_size;
size_t off = 0;
size_t array_size = 0;
+ flb_sds_t out_buf;
msgpack_object map;
msgpack_object root;
msgpack_object m_key;
@@ -91,8 +91,6 @@ static int msgpack_to_json(const void *data, size_t bytes,
msgpack_unpacked result;
msgpack_object *obj;
struct flb_time tm;
- char *json_buf;
- size_t json_size;
/* Iterate the original buffer and perform adjustments */
msgpack_unpacked_init(&result);
@@ -137,16 +135,15 @@ static int msgpack_to_json(const void *data, size_t bytes,
}
msgpack_unpacked_destroy(&result);
- ret = flb_msgpack_raw_to_json_str(mp_sbuf.data, mp_sbuf.size,
- &json_buf, &json_size);
+ out_buf = flb_msgpack_raw_to_json_sds(mp_sbuf.data, mp_sbuf.size);
msgpack_sbuffer_destroy(&mp_sbuf);
- if (ret != 0) {
+ if (!out_buf) {
return -1;
}
- *out_json = json_buf;
- *out_size = json_size;
+ *out_json = out_buf;
+ *out_size = flb_sds_len(out_buf);
return 0;
}
@@ -160,7 +157,7 @@ void cb_nats_flush(const void *data, size_t bytes,
int ret;
size_t bytes_sent;
size_t json_len;
- char *json_msg;
+ flb_sds_t json_msg;
char *request;
int req_len;
struct flb_out_nats_config *ctx = out_context;
@@ -199,11 +196,11 @@ void cb_nats_flush(const void *data, size_t bytes,
req_len += json_len;
request[req_len++] = '\r';
request[req_len++] = '\n';
- flb_free(json_msg);
+ flb_sds_destroy(json_msg);
ret = flb_io_net_write(u_conn, request, req_len, &bytes_sent);
if (ret == -1) {
- perror("write");
+ flb_errno();
flb_free(request);
flb_upstream_conn_release(u_conn);
FLB_OUTPUT_RETURN(FLB_RETRY);
