diff options
author | Ole Troan <ot@cisco.com> | 2018-11-28 11:36:05 +0100 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2018-12-13 12:11:50 +0000 |
commit | 413f4a5b2123c1625d615315db293a080078482b (patch) | |
tree | 6cfd8376c1d84b93793b062731ec9594487dc95e /src/vat | |
parent | 6f666ad99ae1e384aa851af5e0feed3d2a25e709 (diff) |
API: Use string type instead of u8.
The new string type is modelled after string in proto3.
It is always variable length.
Change-Id: I64884067e28a80072c8dac31b7c7c82d6e306051
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vat')
-rw-r--r-- | src/vat/api_format.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 7f4dabeffa1..25d2dd3112a 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -1105,7 +1105,7 @@ vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp) { vat_main_t *vam = &vat_main; i32 retval = ntohl (mp->retval); - u32 length = ntohl (mp->length); + u32 length = vl_api_string_len (&mp->reply); vec_reset_length (vam->cmd_reply); @@ -1113,7 +1113,8 @@ vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp) if (retval == 0) { vec_validate (vam->cmd_reply, length); - clib_memcpy ((char *) (vam->cmd_reply), mp->reply, length); + clib_memcpy ((char *) (vam->cmd_reply), + vl_api_from_api_string (&mp->reply), length); vam->cmd_reply[length] = 0; } vam->result_ready = 1; @@ -1129,7 +1130,8 @@ vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp) vat_json_init_object (&node); vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_string_copy (&node, "reply", mp->reply); + vat_json_object_add_string_copy (&node, "reply", + vl_api_from_api_string (&mp->reply)); vat_json_print (vam->ofp, &node); vat_json_free (&node); @@ -1300,10 +1302,18 @@ static void vl_api_show_version_reply_t_handler if (retval >= 0) { - errmsg (" program: %s", mp->program); - errmsg (" version: %s", mp->version); - errmsg (" build date: %s", mp->build_date); - errmsg ("build directory: %s", mp->build_directory); + char *p = (char *) &mp->program; + errmsg (" program: %s\n", + vl_api_from_api_string ((vl_api_string_t *) p)); + p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32); + errmsg (" version: %s\n", + vl_api_from_api_string ((vl_api_string_t *) p)); + p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32); + errmsg (" build date: %s\n", + vl_api_from_api_string ((vl_api_string_t *) p)); + p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32); + errmsg ("build directory: %s\n", + vl_api_from_api_string ((vl_api_string_t *) p)); } vam->retval = retval; vam->result_ready = 1; @@ -1317,11 +1327,22 @@ static void vl_api_show_version_reply_t_handler_json vat_json_init_object (&node); vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_string_copy (&node, "program", mp->program); - vat_json_object_add_string_copy (&node, "version", mp->version); - vat_json_object_add_string_copy (&node, "build_date", mp->build_date); + char *p = (char *) &mp->program; + vat_json_object_add_string_copy (&node, "program", + vl_api_from_api_string ((vl_api_string_t *) + p)); + p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32); + vat_json_object_add_string_copy (&node, "version", + vl_api_from_api_string ((vl_api_string_t *) + p)); + p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32); + vat_json_object_add_string_copy (&node, "build_date", + vl_api_from_api_string ((vl_api_string_t *) + p)); + p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32); vat_json_object_add_string_copy (&node, "build_directory", - mp->build_directory); + vl_api_from_api_string ((vl_api_string_t *) + p)); vat_json_print (vam->ofp, &node); vat_json_free (&node); @@ -6339,8 +6360,7 @@ exec_inband (vat_main_t * vam) */ u32 len = vec_len (vam->input->buffer); M2 (CLI_INBAND, mp, len); - clib_memcpy (mp->cmd, vam->input->buffer, len); - mp->length = htonl (len); + vl_api_to_api_string (len, (const char *) vam->input->buffer, &mp->cmd); S (mp); W (ret); |