From: Andrea Claudi Date: Tue, 21 Oct 2025 20:39:17 +0000 (+0200) Subject: nstat: convert to high-level json_print API X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=536fc07e33689d152fa094e9716296f917abc643;p=thirdparty%2Fiproute2.git nstat: convert to high-level json_print API Replace the low-level json_writer API calls with the high-level json_print API to maintain consistency with the rest of the iproute2 codebase. Signed-off-by: Andrea Claudi Signed-off-by: David Ahern --- diff --git a/misc/nstat.c b/misc/nstat.c index b2e19bde..4a9f3326 100644 --- a/misc/nstat.c +++ b/misc/nstat.c @@ -24,7 +24,7 @@ #include #include -#include +#include "json_print.h" #include "version.h" #include "utils.h" @@ -309,15 +309,13 @@ static void load_netstat(void) static void dump_kern_db(FILE *fp, int to_hist) { - json_writer_t *jw = json_output ? jsonw_new(fp) : NULL; struct nstat_ent *n, *h; h = hist_db; - if (jw) { - jsonw_start_object(jw); - jsonw_pretty(jw, pretty); - jsonw_name(jw, info_source); - jsonw_start_object(jw); + new_json_obj_plain(json_output); + if (is_json_context()) { + open_json_object(NULL); + open_json_object(info_source); } else fprintf(fp, "#%s\n", info_source); @@ -340,31 +338,28 @@ static void dump_kern_db(FILE *fp, int to_hist) } } - if (jw) - jsonw_uint_field(jw, n->id, val); + if (is_json_context()) + print_lluint(PRINT_JSON, n->id, NULL, val); else fprintf(fp, "%-32s%-16llu%6.1f\n", n->id, val, n->rate); } - if (jw) { - jsonw_end_object(jw); - - jsonw_end_object(jw); - jsonw_destroy(&jw); + if (is_json_context()) { + close_json_object(); + close_json_object(); } + delete_json_obj_plain(); } static void dump_incr_db(FILE *fp) { - json_writer_t *jw = json_output ? jsonw_new(fp) : NULL; struct nstat_ent *n, *h; h = hist_db; - if (jw) { - jsonw_start_object(jw); - jsonw_pretty(jw, pretty); - jsonw_name(jw, info_source); - jsonw_start_object(jw); + new_json_obj_plain(json_output); + if (is_json_context()) { + open_json_object(NULL); + open_json_object(info_source); } else fprintf(fp, "#%s\n", info_source); @@ -389,19 +384,18 @@ static void dump_incr_db(FILE *fp) if (!match(n->id)) continue; - if (jw) - jsonw_uint_field(jw, n->id, val); + if (is_json_context()) + print_lluint(PRINT_JSON, n->id, NULL, val); else fprintf(fp, "%-32s%-16llu%6.1f%s\n", n->id, val, n->rate, ovfl?" (overflow)":""); } - if (jw) { - jsonw_end_object(jw); - - jsonw_end_object(jw); - jsonw_destroy(&jw); + if (is_json_context()) { + close_json_object(); + close_json_object(); } + delete_json_obj_plain(); } static int children;