From 4d7b3e0d809d983dcd7494d7da7627da9b49ae77 Mon Sep 17 00:00:00 2001 From: fengzero Date: Thu, 24 Oct 2024 06:17:36 +0000 Subject: [PATCH] write tags: optional name --- include/neuron/json/json.h | 1 + src/parser/neu_json_rw.c | 5 +++-- src/utils/json.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/neuron/json/json.h b/include/neuron/json/json.h index d351df28..8a1dcf1c 100644 --- a/include/neuron/json/json.h +++ b/include/neuron/json/json.h @@ -65,6 +65,7 @@ typedef enum neu_json_attribute { typedef struct neu_json_elem { neu_json_attribute_t attribute; char * name; + char * op_name; enum neu_json_type t; union neu_json_value v; uint8_t precision; diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index ecf2a08f..87a2d61b 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -440,8 +440,9 @@ static int decode_write_tags_req_json(void * json_obj, for (int i = 0; i < req->n_tag; i++) { neu_json_elem_t v_elems[] = { { - .name = "tag", - .t = NEU_JSON_STR, + .name = "tag", + .op_name = "name", + .t = NEU_JSON_STR, }, { .name = "value", diff --git a/src/utils/json.c b/src/utils/json.c index 36fc6be2..c8f73153 100644 --- a/src/utils/json.c +++ b/src/utils/json.c @@ -157,6 +157,10 @@ static int decode_object(json_t *root, neu_json_elem_t *ele) ob = root; } else { ob = json_object_get(root, ele->name); + if (ob == NULL && ele->op_name != NULL && strlen(ele->op_name) > 0 && + strlen(ele->op_name) < 32) { + ob = json_object_get(root, ele->op_name); + } } if (ob == NULL) {