Hello,
I am trying to send bson data via socket connection. I found an API dealing with this situation at
bson api site. The API is as following
: uint8_t * bson_destroy_with_steal (bson_t *bson, bool steal, uint32_t *length)
Here is part of my program code:
// bson_t copy_b
// ... append something into copy_b;
if(©_b) {
const bson_t* pb = ©_b;
char* json_result = bson_as_canonical_extended_json(pb,NULL);
write_json(outfname, json_result);
bson_free(json_result);
uint8_t* buf = NULL;
buf = bson_destroy_with_steal(pb,true,&pb->len);
write_bson(outfname,buf);
free(buf);
buf = NULL;
I expected to get the content in uint8_t characters by using this API. I only resulted in getting a weird symbol "|" in buf. But if I use bson_as_canonical_extended_json, the content is appropriately converted to json.
part of the json_result
...
[ "2260", "10:22:06.144732", " recvmsg", [ "16", [ "msg_namelen=0" ], "0" ] ], "13407" : [ "2260", "10:22:06.144877", " recvmsg", [ "16", [ "msg_namelen=0" ], "0" ] ], "13408" : [ "2260", "10:22:06.145019", " recvmsg", [ "16", [ "msg_namelen=0" ], "0" ] ], "13409" : [ "2260", "10:22:06.162379", " recvmsg", [ "16", [ "msg_namelen=0" ], "0" ] ]
...
The content of the buf:
"|"
Could anyone tell me is there anything wrong with my code or this API? Any help is appreciated.
Regards,
Zhaoyu