]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: json: Add accessor for geting a VIR_JSON_TYPE_NUMBER as string
authorPeter Krempa <pkrempa@redhat.com>
Thu, 29 Mar 2018 18:38:35 +0000 (20:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Apr 2018 11:34:33 +0000 (13:34 +0200)
Sometimes it's desired to get a JSON number as string. Add a helper.
This will help in cases where we'd want to convert the internal type from
string to something else.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/libvirt_private.syms
src/util/virjson.c
src/util/virjson.h

index 03fe3b315f82580762300d2ddc492f61b52e3017..989411cdcaa4a97d94862d9b5a141830c12476b9 100644 (file)
@@ -2038,6 +2038,7 @@ virJSONValueGetBoolean;
 virJSONValueGetNumberDouble;
 virJSONValueGetNumberInt;
 virJSONValueGetNumberLong;
+virJSONValueGetNumberString;
 virJSONValueGetNumberUint;
 virJSONValueGetNumberUlong;
 virJSONValueGetString;
index 212c158da04ea17b1369e1faf409aea3a3e9a462..6f2b52257fa12ac1240e8da7a65205507bbd4cbf 100644 (file)
@@ -1043,6 +1043,16 @@ virJSONValueGetString(virJSONValuePtr string)
 }
 
 
+const char *
+virJSONValueGetNumberString(virJSONValuePtr number)
+{
+    if (number->type != VIR_JSON_TYPE_NUMBER)
+        return NULL;
+
+    return number->data.number;
+}
+
+
 int
 virJSONValueGetNumberInt(virJSONValuePtr number,
                          int *value)
index 017a1f20edb5faaaf11bfb6ddd70449679d0e48e..e80d10dea1a29d15a153d758960036a5508a1c97 100644 (file)
@@ -134,6 +134,7 @@ const char *virJSONValueObjectGetKey(virJSONValuePtr object, unsigned int n);
 virJSONValuePtr virJSONValueObjectGetValue(virJSONValuePtr object, unsigned int n);
 
 const char *virJSONValueGetString(virJSONValuePtr object);
+const char *virJSONValueGetNumberString(virJSONValuePtr number);
 int virJSONValueGetNumberInt(virJSONValuePtr object, int *value);
 int virJSONValueGetNumberUint(virJSONValuePtr object, unsigned int *value);
 int virJSONValueGetNumberLong(virJSONValuePtr object, long long *value);