Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef included_json_convert_h |
| 17 | #define included_json_convert_h |
| 18 | |
| 19 | #include <stdbool.h> |
| 20 | #include <vppinfra/cJSON.h> |
| 21 | #include <vnet/ethernet/mac_address.h> |
| 22 | #include <vnet/ip/ip6_packet.h> |
| 23 | #include <vnet/ip/ip_types.api_types.h> |
| 24 | #include <vnet/ethernet/ethernet_types.api_types.h> |
| 25 | |
| 26 | #define foreach_type_fromjson \ |
| 27 | _ (i8) \ |
| 28 | _ (u8) \ |
| 29 | _ (i16) \ |
| 30 | _ (u16) \ |
| 31 | _ (i32) \ |
| 32 | _ (u32) \ |
| 33 | _ (u64) \ |
| 34 | _ (f64) |
| 35 | |
| 36 | #define _(T) CJSON_PUBLIC (int) vl_api_##T##_fromjson (cJSON *o, T *d); |
| 37 | foreach_type_fromjson |
| 38 | #undef _ |
| 39 | |
| 40 | /* Prototypes */ |
| 41 | CJSON_PUBLIC (int) vl_api_bool_fromjson (cJSON *o, bool *d); |
| 42 | CJSON_PUBLIC (int) |
| 43 | vl_api_ip4_address_t_fromjson (void **mp, int *len, cJSON *o, |
| 44 | vl_api_ip4_address_t *a); |
| 45 | CJSON_PUBLIC (int) |
| 46 | vl_api_ip4_prefix_t_fromjson (void **mp, int *len, cJSON *o, |
| 47 | vl_api_ip4_prefix_t *a); |
| 48 | CJSON_PUBLIC (int) |
| 49 | vl_api_ip4_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, |
| 50 | vl_api_ip4_prefix_t *a); |
| 51 | CJSON_PUBLIC (int) |
| 52 | vl_api_ip6_address_t_fromjson (void **mp, int *len, cJSON *o, |
| 53 | vl_api_ip6_address_t *a); |
| 54 | CJSON_PUBLIC (int) |
| 55 | vl_api_ip6_prefix_t_fromjson (void **mp, int *len, cJSON *o, |
| 56 | vl_api_ip6_prefix_t *a); |
| 57 | CJSON_PUBLIC (int) |
| 58 | vl_api_ip6_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, |
| 59 | vl_api_ip6_prefix_t *a); |
| 60 | CJSON_PUBLIC (int) |
| 61 | vl_api_address_t_fromjson (void **mp, int *len, cJSON *o, vl_api_address_t *a); |
| 62 | CJSON_PUBLIC (int) |
| 63 | vl_api_prefix_t_fromjson (void **mp, int *len, cJSON *o, vl_api_prefix_t *a); |
| 64 | CJSON_PUBLIC (int) |
| 65 | vl_api_address_with_prefix_t_fromjson (void **mp, int *len, cJSON *o, |
| 66 | vl_api_prefix_t *a); |
| 67 | CJSON_PUBLIC (int) |
| 68 | vl_api_mac_address_t_fromjson (void **mp, int *len, cJSON *o, |
| 69 | vl_api_mac_address_t *a); |
| 70 | |
| 71 | CJSON_PUBLIC (uword) |
| 72 | unformat_ip4_address (unformat_input_t *input, va_list *args); |
| 73 | CJSON_PUBLIC (uword) |
| 74 | unformat_ip6_address (unformat_input_t *input, va_list *args); |
| 75 | CJSON_PUBLIC (u8 *) format_ip6_address (u8 *s, va_list *args); |
| 76 | CJSON_PUBLIC (uword) |
| 77 | unformat_mac_address (unformat_input_t *input, va_list *args); |
| 78 | CJSON_PUBLIC (u8 *) format_ip4_address (u8 *s, va_list *args); |
| 79 | CJSON_PUBLIC (uword) |
| 80 | unformat_vl_api_timedelta_t (unformat_input_t *input, va_list *args); |
| 81 | CJSON_PUBLIC (uword) |
| 82 | unformat_vl_api_timestamp_t (unformat_input_t *input, va_list *args); |
| 83 | CJSON_PUBLIC (uword) |
| 84 | unformat_vl_api_gbp_scope_t (unformat_input_t *input, va_list *args); |
| 85 | |
Filip Tehlar | 36217e3 | 2021-07-23 08:51:10 +0000 | [diff] [blame] | 86 | CJSON_PUBLIC (void) |
| 87 | vl_api_string_cJSON_AddToObject (cJSON *const object, const char *const name, |
| 88 | vl_api_string_t *astr); |
| 89 | |
| 90 | CJSON_PUBLIC (u8 *) u8string_fromjson (cJSON *o, char *fieldname); |
| 91 | CJSON_PUBLIC (int) u8string_fromjson2 (cJSON *o, char *fieldname, u8 *data); |
| 92 | CJSON_PUBLIC (int) vl_api_u8_string_fromjson (cJSON *o, u8 *s, int len); |
| 93 | |
| 94 | #define foreach_type_tojson \ |
| 95 | _ (ip4_address) \ |
| 96 | _ (ip4_prefix) \ |
| 97 | _ (ip6_address) \ |
| 98 | _ (ip6_prefix) \ |
| 99 | _ (address) \ |
| 100 | _ (prefix) \ |
| 101 | _ (mac_address) |
| 102 | |
| 103 | #define _(T) CJSON_PUBLIC (cJSON *) vl_api_##T##_t_tojson (vl_api_##T##_t *); |
| 104 | foreach_type_tojson |
| 105 | #undef _ |
| 106 | |
| 107 | CJSON_PUBLIC (cJSON *) |
| 108 | vl_api_ip4_address_with_prefix_t_tojson (vl_api_ip4_prefix_t *a); |
| 109 | CJSON_PUBLIC (cJSON *) |
| 110 | vl_api_ip6_address_with_prefix_t_tojson (vl_api_ip6_prefix_t *a); |
| 111 | CJSON_PUBLIC (cJSON *) |
| 112 | vl_api_address_with_prefix_t_tojson (vl_api_prefix_t *a); |
| 113 | |
| 114 | #endif |