naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0065-json_writer-add-new-json-handlers-null-float-with-fo.patch

36cfb7
From b4b11394d071810d694b66962e8d48cb866af473 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 25 Mar 2019 13:30:53 +0100
36cfb7
Subject: [PATCH] json_writer: add new json handlers (null, float with format,
36cfb7
 lluint, hu)
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1642479
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1641914
36cfb7
Upstream Status: iproute2.git commit 7252f16b2d191
36cfb7
36cfb7
commit 7252f16b2d1919b31f0a2ec094dd3516b1e33a55
36cfb7
Author: Julien Fortin <julien@cumulusnetworks.com>
36cfb7
Date:   Thu Aug 17 10:35:50 2017 -0700
36cfb7
36cfb7
    json_writer: add new json handlers (null, float with format, lluint, hu)
36cfb7
36cfb7
    Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
36cfb7
---
36cfb7
 include/json_writer.h |  9 +++++++++
36cfb7
 lib/json_writer.c     | 44 +++++++++++++++++++++++++++++++++++++++----
36cfb7
 2 files changed, 49 insertions(+), 4 deletions(-)
36cfb7
36cfb7
diff --git a/include/json_writer.h b/include/json_writer.h
36cfb7
index ab9a008a67994..1516aafba59df 100644
36cfb7
--- a/include/json_writer.h
36cfb7
+++ b/include/json_writer.h
36cfb7
@@ -33,20 +33,29 @@ void jsonw_pretty(json_writer_t *self, bool on);
36cfb7
 void jsonw_name(json_writer_t *self, const char *name);
36cfb7
 
36cfb7
 /* Add value  */
36cfb7
+void jsonw_printf(json_writer_t *self, const char *fmt, ...);
36cfb7
 void jsonw_string(json_writer_t *self, const char *value);
36cfb7
 void jsonw_bool(json_writer_t *self, bool value);
36cfb7
 void jsonw_float(json_writer_t *self, double number);
36cfb7
+void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num);
36cfb7
 void jsonw_uint(json_writer_t *self, uint64_t number);
36cfb7
+void jsonw_hu(json_writer_t *self, unsigned short number);
36cfb7
 void jsonw_int(json_writer_t *self, int64_t number);
36cfb7
 void jsonw_null(json_writer_t *self);
36cfb7
+void jsonw_lluint(json_writer_t *self, unsigned long long int num);
36cfb7
 
36cfb7
 /* Useful Combinations of name and value */
36cfb7
 void jsonw_string_field(json_writer_t *self, const char *prop, const char *val);
36cfb7
 void jsonw_bool_field(json_writer_t *self, const char *prop, bool value);
36cfb7
 void jsonw_float_field(json_writer_t *self, const char *prop, double num);
36cfb7
 void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num);
36cfb7
+void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num);
36cfb7
 void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num);
36cfb7
 void jsonw_null_field(json_writer_t *self, const char *prop);
36cfb7
+void jsonw_lluint_field(json_writer_t *self, const char *prop,
36cfb7
+			unsigned long long int num);
36cfb7
+void jsonw_float_field_fmt(json_writer_t *self, const char *prop,
36cfb7
+			   const char *fmt, double val);
36cfb7
 
36cfb7
 /* Collections */
36cfb7
 void jsonw_start_object(json_writer_t *self);
36cfb7
diff --git a/lib/json_writer.c b/lib/json_writer.c
36cfb7
index 9fc05e96b605f..6b77d288cce2b 100644
36cfb7
--- a/lib/json_writer.c
36cfb7
+++ b/lib/json_writer.c
36cfb7
@@ -156,7 +156,7 @@ void jsonw_name(json_writer_t *self, const char *name)
36cfb7
 		putc(' ', self->out);
36cfb7
 }
36cfb7
 
36cfb7
-static void jsonw_printf(json_writer_t *self, const char *fmt, ...)
36cfb7
+void jsonw_printf(json_writer_t *self, const char *fmt, ...)
36cfb7
 {
36cfb7
 	va_list ap;
36cfb7
 
36cfb7
@@ -199,23 +199,38 @@ void jsonw_bool(json_writer_t *self, bool val)
36cfb7
 	jsonw_printf(self, "%s", val ? "true" : "false");
36cfb7
 }
36cfb7
 
36cfb7
-#ifdef notused
36cfb7
 void jsonw_null(json_writer_t *self)
36cfb7
 {
36cfb7
 	jsonw_printf(self, "null");
36cfb7
 }
36cfb7
 
36cfb7
+void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num)
36cfb7
+{
36cfb7
+	jsonw_printf(self, fmt, num);
36cfb7
+}
36cfb7
+
36cfb7
+#ifdef notused
36cfb7
 void jsonw_float(json_writer_t *self, double num)
36cfb7
 {
36cfb7
 	jsonw_printf(self, "%g", num);
36cfb7
 }
36cfb7
 #endif
36cfb7
 
36cfb7
+void jsonw_hu(json_writer_t *self, unsigned short num)
36cfb7
+{
36cfb7
+	jsonw_printf(self, "%hu", num);
36cfb7
+}
36cfb7
+
36cfb7
 void jsonw_uint(json_writer_t *self, uint64_t num)
36cfb7
 {
36cfb7
 	jsonw_printf(self, "%"PRIu64, num);
36cfb7
 }
36cfb7
 
36cfb7
+void jsonw_lluint(json_writer_t *self, unsigned long long int num)
36cfb7
+{
36cfb7
+	jsonw_printf(self, "%llu", num);
36cfb7
+}
36cfb7
+
36cfb7
 void jsonw_int(json_writer_t *self, int64_t num)
36cfb7
 {
36cfb7
 	jsonw_printf(self, "%"PRId64, num);
36cfb7
@@ -242,25 +257,46 @@ void jsonw_float_field(json_writer_t *self, const char *prop, double val)
36cfb7
 }
36cfb7
 #endif
36cfb7
 
36cfb7
+void jsonw_float_field_fmt(json_writer_t *self,
36cfb7
+			   const char *prop,
36cfb7
+			   const char *fmt,
36cfb7
+			   double val)
36cfb7
+{
36cfb7
+	jsonw_name(self, prop);
36cfb7
+	jsonw_float_fmt(self, fmt, val);
36cfb7
+}
36cfb7
+
36cfb7
 void jsonw_uint_field(json_writer_t *self, const char *prop, uint64_t num)
36cfb7
 {
36cfb7
 	jsonw_name(self, prop);
36cfb7
 	jsonw_uint(self, num);
36cfb7
 }
36cfb7
 
36cfb7
+void jsonw_hu_field(json_writer_t *self, const char *prop, unsigned short num)
36cfb7
+{
36cfb7
+	jsonw_name(self, prop);
36cfb7
+	jsonw_hu(self, num);
36cfb7
+}
36cfb7
+
36cfb7
+void jsonw_lluint_field(json_writer_t *self,
36cfb7
+			const char *prop,
36cfb7
+			unsigned long long int num)
36cfb7
+{
36cfb7
+	jsonw_name(self, prop);
36cfb7
+	jsonw_lluint(self, num);
36cfb7
+}
36cfb7
+
36cfb7
 void jsonw_int_field(json_writer_t *self, const char *prop, int64_t num)
36cfb7
 {
36cfb7
 	jsonw_name(self, prop);
36cfb7
 	jsonw_int(self, num);
36cfb7
 }
36cfb7
 
36cfb7
-#ifdef notused
36cfb7
 void jsonw_null_field(json_writer_t *self, const char *prop)
36cfb7
 {
36cfb7
 	jsonw_name(self, prop);
36cfb7
 	jsonw_null(self);
36cfb7
 }
36cfb7
-#endif
36cfb7
 
36cfb7
 #ifdef TEST
36cfb7
 int main(int argc, char **argv)
36cfb7
-- 
e138d9
2.21.0
36cfb7