Damjan Marion | fe45f8f | 2022-05-20 16:01:22 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2022 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #include <vppinfra/format.h> |
| 6 | #include <vlibapi/api.h> |
| 7 | |
| 8 | u8 * |
| 9 | format_vl_api_msg_text (u8 *s, va_list *args) |
| 10 | { |
| 11 | api_main_t *am = va_arg (*args, api_main_t *); |
| 12 | u32 msg_id = va_arg (*args, u32); |
| 13 | void *msg = va_arg (*args, void *); |
| 14 | vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id); |
| 15 | |
| 16 | if (m->format_fn) |
| 17 | s = format (s, "%U", m->format_fn, msg); |
| 18 | else |
| 19 | s = format (s, "[format handler missing for `%s`]", m->name); |
| 20 | return s; |
| 21 | } |
| 22 | |
| 23 | u8 * |
| 24 | format_vl_api_msg_json (u8 *s, va_list *args) |
| 25 | { |
| 26 | api_main_t *am = va_arg (*args, api_main_t *); |
| 27 | u32 msg_id = va_arg (*args, u32); |
| 28 | void *msg = va_arg (*args, void *); |
| 29 | vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id); |
| 30 | |
| 31 | cJSON *o = m->tojson_handler (msg); |
| 32 | char *out = cJSON_Print (o); |
| 33 | |
| 34 | s = format (s, "%s", out); |
| 35 | |
| 36 | cJSON_Delete (o); |
| 37 | cJSON_free (out); |
| 38 | return s; |
| 39 | } |