X-Git-Url: https://gerrit.fd.io/r/gitweb?p=vpp.git;a=blobdiff_plain;f=src%2Fvppinfra%2Fjsonformat.c;fp=src%2Fvat2%2Fjsonconvert.c;h=17b3ee9d3f816d38f11611539348e8099a318647;hp=1437b90688a76c4d5d23b26bc909830ffac3d926;hb=36217e3ca;hpb=3459ece6da90627b161e2128b5926f1e58e7db65 diff --git a/src/vat2/jsonconvert.c b/src/vppinfra/jsonformat.c similarity index 95% rename from src/vat2/jsonconvert.c rename to src/vppinfra/jsonformat.c index 1437b90688a..17b3ee9d3f8 100644 --- a/src/vat2/jsonconvert.c +++ b/src/vppinfra/jsonformat.c @@ -18,19 +18,21 @@ #include #include #include -#include "jsonconvert.h" - -#define _(T) \ -int vl_api_ ##T## _fromjson(cJSON *o, T *d) \ -{ \ - if (!cJSON_IsNumber(o)) return -1; \ - memcpy(d, &o->valueint, sizeof(T)); \ - return 0; \ -} - foreach_vat2_fromjson +#include "jsonformat.h" + +#define _(T) \ + int vl_api_##T##_fromjson (cJSON *o, T *d) \ + { \ + if (!cJSON_IsNumber (o)) \ + return -1; \ + d[0] = (T) cJSON_GetNumberValue (o); \ + return 0; \ + } +foreach_type_fromjson #undef _ -int vl_api_bool_fromjson(cJSON *o, bool *d) + int + vl_api_bool_fromjson (cJSON *o, bool *d) { if (!cJSON_IsBool(o)) return -1; *d = o->valueint ? true : false; @@ -437,13 +439,6 @@ vl_api_c_string_to_api_string (const char *buf, vl_api_string_t * str) return len + sizeof (u32); } -u8 * -format_vl_api_interface_index_t (u8 *s, va_list *args) -{ - u32 *a = va_arg (*args, u32 *); - return format (s, "%u", *a); -} - void vl_api_string_cJSON_AddToObject(cJSON * const object, const char * const name, vl_api_string_t *astr) { @@ -490,10 +485,6 @@ unformat_vl_api_timestamp_t(unformat_input_t * input, va_list * args) { return 0; } -u8 *format_vl_api_gbp_scope_t(u8 * s, va_list * args) -{ - return 0; -} uword unformat_vl_api_gbp_scope_t(unformat_input_t * input, va_list * args) { return 0; @@ -527,5 +518,5 @@ format_vl_api_mac_address_t (u8 * s, va_list * args) vec_free(s); \ return o; \ } -foreach_vat2_tojson +foreach_type_tojson #undef _