Skip to content

Commit

Permalink
Merge pull request #2016 from hxy7yx/main-2
Browse files Browse the repository at this point in the history
fix(write): write *.0
  • Loading branch information
fengzeroz committed May 24, 2024
2 parents 7461693 + eb243d6 commit 75ef81e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/parser/neu_json_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int neu_json_encode_read_resp(void *json_object, void *param)
neu_json_read_resp_tag_t *p_tag = resp->tags;
for (int i = 0; i < resp->n_tag; i++) {
neu_json_elem_t tag_elems[2 + NEU_TAG_META_SIZE] = { 0 };
int if_precision = 0;

tag_elems[0].name = "name";
tag_elems[0].t = NEU_JSON_STR;
Expand All @@ -57,16 +58,24 @@ int neu_json_encode_read_resp(void *json_object, void *param)
tag_elems[1].t = p_tag->t;
tag_elems[1].v = p_tag->value;
tag_elems[1].precision = p_tag->precision;

if (p_tag->t == NEU_JSON_FLOAT || p_tag->t == NEU_JSON_DOUBLE) {
if_precision = 1;
tag_elems[2].name = "precision";
tag_elems[2].t = NEU_JSON_INT;
tag_elems[2].v.val_int =
p_tag->precision > 0 ? p_tag->precision : 1;
}
}

for (int k = 0; k < p_tag->n_meta; k++) {
tag_elems[2 + k].name = p_tag->metas[k].name;
tag_elems[2 + k].t = p_tag->metas[k].t;
tag_elems[2 + k].v = p_tag->metas[k].value;
tag_elems[if_precision + 2 + k].name = p_tag->metas[k].name;
tag_elems[if_precision + 2 + k].t = p_tag->metas[k].t;
tag_elems[if_precision + 2 + k].v = p_tag->metas[k].value;
}

tag_array =
neu_json_encode_array(tag_array, tag_elems, 2 + p_tag->n_meta);
tag_array = neu_json_encode_array(tag_array, tag_elems,
2 + if_precision + p_tag->n_meta);
p_tag++;
}

Expand Down Expand Up @@ -185,7 +194,17 @@ int decode_write_req_json(void *json_obj, neu_json_write_req_t *req)
.name = "value",
.t = NEU_JSON_VALUE,
},
{
.name = "precision",
.t = NEU_JSON_INT,
.attribute = NEU_JSON_ATTRIBUTE_OPTIONAL,
},
};

if (req_elems[4].v.val_int > 0) {
req_elems[3].t = NEU_JSON_DOUBLE;
}

ret = neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_elems),
req_elems);
if (ret != 0) {
Expand Down

0 comments on commit 75ef81e

Please sign in to comment.