1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

util: json: Add accessor for geting a VIR_JSON_TYPE_NUMBER as string

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>
This commit is contained in:
Peter Krempa 2018-03-29 20:38:35 +02:00
parent 0f0ad1116c
commit 1cbe6aa220
3 changed files with 12 additions and 0 deletions

View File

@ -2038,6 +2038,7 @@ virJSONValueGetBoolean;
virJSONValueGetNumberDouble;
virJSONValueGetNumberInt;
virJSONValueGetNumberLong;
virJSONValueGetNumberString;
virJSONValueGetNumberUint;
virJSONValueGetNumberUlong;
virJSONValueGetString;

View 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)

View 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);