summaryrefslogtreecommitdiffstats
path: root/src/vat2/jsonconvert.c
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2020-12-04 13:15:30 +0100
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2020-12-11 22:54:09 +0000
commit793be46324453e5326eb37a13ffb82f92b1f55b1 (patch)
tree4a7932b5ccfce018a97c8e75e8a9aa1c16f18e15 /src/vat2/jsonconvert.c
parent6c8cdf78b47494f98ac0d6dac8c736467f4afc55 (diff)
api: fromjson/tojson enum flag support
Represent enum flags as JSON arrays (as these can have multiple values). Add unit tests. Type: improvement Change-Id: I680c5b6f76ef6f05f360e2f3b9c4cbb927e15d7d Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vat2/jsonconvert.c')
-rw-r--r--src/vat2/jsonconvert.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/vat2/jsonconvert.c b/src/vat2/jsonconvert.c
index 3aeaeedb2f7..ec066287035 100644
--- a/src/vat2/jsonconvert.c
+++ b/src/vat2/jsonconvert.c
@@ -314,12 +314,12 @@ void *vl_api_address_t_fromjson(void *mp, int *len, cJSON *o, vl_api_address_t *
char *p = cJSON_GetStringValue(o);
if (!p) return 0;
unformat_init_string (&input, p, strlen(p));
- if (a->af == ADDRESS_IP4)
- unformat(&input, "%U", unformat_ip4_address, &a->un.ip4);
- else if (a->af == ADDRESS_IP6)
- unformat(&input, "%U", unformat_ip6_address, &a->un.ip6);
+ if (unformat (&input, "%U", unformat_ip4_address, &a->un.ip4))
+ a->af = ADDRESS_IP4;
+ else if (unformat (&input, "%U", unformat_ip6_address, &a->un.ip6))
+ a->af = ADDRESS_IP6;
else
- return 0;
+ return (0);
return mp;
}
@@ -328,14 +328,17 @@ void *vl_api_prefix_t_fromjson(void *mp, int *len, cJSON *o, vl_api_prefix_t *a)
unformat_input_t input;
char *p = cJSON_GetStringValue(o);
+
if (!p) return 0;
unformat_init_string (&input, p, strlen(p));
- if (a->address.af == ADDRESS_IP4)
- unformat(&input, "%U/%d", unformat_ip4_address, &a->address.un.ip4, &a->len);
- else if (a->address.af == ADDRESS_IP6)
- unformat(&input, "%U/%d", unformat_ip6_address, &a->address.un.ip6, &a->len);
+ int plen;
+ if (unformat (&input, "%U/%d", unformat_ip4_address, &a->address.un.ip4, &plen))
+ a->address.af = ADDRESS_IP4;
+ else if (unformat (&input, "%U/%d", unformat_ip6_address, &a->address.un.ip6, &plen))
+ a->address.af = ADDRESS_IP6;
else
- return 0;
+ return (0);
+ a->len = plen;
return mp;
}