out_stackdriver: use flb_msgpack_raw_to_json_sds() instead of old ...raw_to_json_str()
@@ -335,7 +335,6 @@ static int stackdriver_format(const void *data, size_t bytes,
char **out_data, size_t *out_size,
struct flb_stackdriver *ctx)
{
- int ret;
int len;
int array_size = 0;
size_t s;
@@ -348,8 +347,7 @@ static int stackdriver_format(const void *data, size_t bytes,
msgpack_unpacked result;
msgpack_sbuffer mp_sbuf;
msgpack_packer mp_pck;
- char *json_buf;
- size_t json_size;
+ flb_sds_t out_buf;
/* Count number of records */
msgpack_unpacked_init(&result);
@@ -470,18 +468,17 @@ static int stackdriver_format(const void *data, size_t bytes,
}
/* Convert from msgpack to JSON */
- 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) {
flb_error("[out_stackdriver] error formatting JSON payload");
msgpack_unpacked_destroy(&result);
return -1;
}
- *out_data = json_buf;
- *out_size = json_size;
+ *out_data = out_buf;
+ *out_size = flb_sds_len(out_buf);
return 0;
}
@@ -509,7 +506,7 @@ static void cb_stackdriver_flush(const void *data, size_t bytes,
int ret_code = FLB_RETRY;
size_t b_sent;
char *token;
- char *payload_buf;
+ flb_sds_t payload_buf;
size_t payload_size;
struct flb_stackdriver *ctx = out_context;
struct flb_upstream_conn *u_conn;
@@ -534,7 +531,7 @@ static void cb_stackdriver_flush(const void *data, size_t bytes,
if (!token) {
flb_error("[out_stackdriver] cannot retrieve oauth2 token");
flb_upstream_conn_release(u_conn);
- flb_free(payload_buf);
+ flb_sds_destroy(payload_buf);
FLB_OUTPUT_RETURN(FLB_RETRY);
}
@@ -579,7 +576,7 @@ static void cb_stackdriver_flush(const void *data, size_t bytes,
}
/* Cleanup */
- flb_free(payload_buf);
+ flb_sds_destroy(payload_buf);
flb_http_client_destroy(c);
flb_upstream_conn_release(u_conn);
