"[\"bbbb\"]}}");
}
+static int
+test_dict_with_dict_values(void)
+{
+ struct rte_tel_data *dict_of_dicts = rte_tel_data_alloc();
+ rte_tel_data_start_dict(dict_of_dicts);
+
+ struct rte_tel_data *child_data = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data, RTE_TEL_STRING_VAL);
+
+ struct rte_tel_data *child_data2 = rte_tel_data_alloc();
+ rte_tel_data_start_array(child_data2, RTE_TEL_STRING_VAL);
+
+ memset(&response_data, 0, sizeof(response_data));
+ rte_tel_data_start_dict(&response_data);
+
+ rte_tel_data_add_array_string(child_data, "aaaa");
+ rte_tel_data_add_array_string(child_data2, "bbbb");
+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_0",
+ child_data, 0);
+ rte_tel_data_add_dict_container(dict_of_dicts, "dict_1",
+ child_data2, 0);
+ rte_tel_data_add_dict_container(&response_data, "dict_of_dicts",
+ dict_of_dicts, 0);
+
+ return TEST_OUTPUT("{\"/test\":{\"dict_of_dicts\":{\"dict_0\":"
+ "[\"aaaa\"],\"dict_1\":[\"bbbb\"]}}}");
+}
+
static int
test_array_with_array_string_values(void)
{
test_dict_with_array_int_values,
test_dict_with_array_u64_values,
test_dict_with_array_string_values,
+ test_dict_with_dict_values,
test_array_with_array_int_values,
test_array_with_array_u64_values,
test_array_with_array_string_values };
#include "telemetry_internal.h"
#define MAX_CMD_LEN 56
-#define MAX_HELP_LEN 64
#define MAX_OUTPUT_LEN (1024 * 16)
#define MAX_CONNECTIONS 10
struct cmd_callback {
char cmd[MAX_CMD_LEN];
telemetry_cb fn;
- char help[MAX_HELP_LEN];
+ char help[RTE_TEL_MAX_STRING_LEN];
};
#ifndef RTE_EXEC_ENV_WINDOWS
int i = 0;
if (strlen(cmd) >= MAX_CMD_LEN || fn == NULL || cmd[0] != '/'
- || strlen(help) >= MAX_HELP_LEN)
+ || strlen(help) >= RTE_TEL_MAX_STRING_LEN)
return -EINVAL;
rte_spinlock_lock(&callback_sl);
strlcpy(callbacks[i].cmd, cmd, MAX_CMD_LEN);
callbacks[i].fn = fn;
- strlcpy(callbacks[i].help, help, MAX_HELP_LEN);
+ strlcpy(callbacks[i].help, help, RTE_TEL_MAX_STRING_LEN);
num_callbacks++;
rte_spinlock_unlock(&callback_sl);
size_t used = 0;
unsigned int i;
- if (d->type != RTE_TEL_ARRAY_U64 && d->type != RTE_TEL_ARRAY_INT
- && d->type != RTE_TEL_ARRAY_STRING)
+ if (d->type != RTE_TEL_DICT && d->type != RTE_TEL_ARRAY_U64 &&
+ d->type != RTE_TEL_ARRAY_INT && d->type != RTE_TEL_ARRAY_STRING)
return snprintf(out_buf, buf_len, "null");
used = rte_tel_json_empty_array(out_buf, buf_len, 0);
used = rte_tel_json_add_array_string(out_buf,
buf_len, used,
d->data.array[i].sval);
+ if (d->type == RTE_TEL_DICT)
+ for (i = 0; i < d->data_len; i++) {
+ const struct tel_dict_entry *v = &d->data.dict[i];
+ switch (v->type) {
+ case RTE_TEL_STRING_VAL:
+ used = rte_tel_json_add_obj_str(out_buf,
+ buf_len, used,
+ v->name, v->value.sval);
+ break;
+ case RTE_TEL_INT_VAL:
+ used = rte_tel_json_add_obj_int(out_buf,
+ buf_len, used,
+ v->name, v->value.ival);
+ break;
+ case RTE_TEL_U64_VAL:
+ used = rte_tel_json_add_obj_u64(out_buf,
+ buf_len, used,
+ v->name, v->value.u64val);
+ break;
+ case RTE_TEL_CONTAINER:
+ {
+ char temp[buf_len];
+ const struct container *cont =
+ &v->value.container;
+ if (container_to_json(cont->data,
+ temp, buf_len) != 0)
+ used = rte_tel_json_add_obj_json(
+ out_buf,
+ buf_len, used,
+ v->name, temp);
+ if (!cont->keep)
+ rte_tel_data_free(cont->data);
+ break;
+ }
+ }
+ }
+
return used;
}