blob: f7bb9d3970fa8b8da9738dfba29ecf2b4def103f [file] [log] [blame]
Damjan Marionfe45f8f2022-05-20 16:01:22 +02001/* 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
8u8 *
9format_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
23u8 *
24format_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}