5#include "libmy/my_alloc.h"
8num_to_str(
int num,
int size,
char * ptr) {
13 ptr[ndx] =
'0' + digit;
21vnum_to_str(uint64_t num,
char *ptr) {
23 size_t ndx, left, ndigits = 0;
34 ptr[ndx] =
'0' + digit;
46declare_json_value(
struct nmsg_strbuf *sb,
const char *name,
bool is_first) {
58append_json_value_string(
struct nmsg_strbuf *sb,
const char *val,
size_t vlen) {
66append_json_value_string_noescape(
struct nmsg_strbuf *sb,
const char *val,
size_t vlen) {
73append_json_value_int(
struct nmsg_strbuf *sb, uint64_t val) {
77 nlen = vnum_to_str(val, numbuf);
82append_json_value_bool(
struct nmsg_strbuf *sb,
bool val) {
91append_json_value_double(
struct nmsg_strbuf *sb,
double val) {
92 char dubbuf[64], *endp;
95 dlen = snprintf(dubbuf,
sizeof(dubbuf),
"%.18f", val);
96 dubbuf[
sizeof(dubbuf)-1] = 0;
99 endp = dubbuf + dlen - 1;
100 while (*endp !=
'\0' && endp > dubbuf) {
101 if (*endp !=
'0' || *(endp-1) ==
'.')
nmsg_res nmsg_strbuf_append_str_json(struct nmsg_strbuf *sb, const char *str, size_t len)
Append to a string buffer.
nmsg_res nmsg_strbuf_append_str(struct nmsg_strbuf *sb, const char *str, size_t len)
Append to a string buffer.