diff options
author | Damjan Marion <damarion@cisco.com> | 2022-05-20 16:01:22 +0200 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2022-09-26 08:14:29 +0000 |
commit | fe45f8f5afbf34d68cf992cc32b12432a82cdb38 (patch) | |
tree | ae8126e78d184022ef97007e64ac1f3350537a40 /src/vlibapi/api_format.c | |
parent | b70497124840fb6d9e8e5cf7239a41cb2bc7013c (diff) |
api: replace print functions wth format
Type: improvement
Change-Id: I7f7050c19453a69a7fb6c5e62f8f57db847d9144
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlibapi/api_format.c')
-rw-r--r-- | src/vlibapi/api_format.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/vlibapi/api_format.c b/src/vlibapi/api_format.c new file mode 100644 index 00000000000..f7bb9d3970f --- /dev/null +++ b/src/vlibapi/api_format.c @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright(c) 2022 Cisco Systems, Inc. + */ + +#include <vppinfra/format.h> +#include <vlibapi/api.h> + +u8 * +format_vl_api_msg_text (u8 *s, va_list *args) +{ + api_main_t *am = va_arg (*args, api_main_t *); + u32 msg_id = va_arg (*args, u32); + void *msg = va_arg (*args, void *); + vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id); + + if (m->format_fn) + s = format (s, "%U", m->format_fn, msg); + else + s = format (s, "[format handler missing for `%s`]", m->name); + return s; +} + +u8 * +format_vl_api_msg_json (u8 *s, va_list *args) +{ + api_main_t *am = va_arg (*args, api_main_t *); + u32 msg_id = va_arg (*args, u32); + void *msg = va_arg (*args, void *); + vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id); + + cJSON *o = m->tojson_handler (msg); + char *out = cJSON_Print (o); + + s = format (s, "%s", out); + + cJSON_Delete (o); + cJSON_free (out); + return s; +} |