Skip to content

Commit 01c40dd

Browse files
maass-hamburgnashif
authored andcommitted
json: add JSON_TOK_ENCODED_OBJ
add support to include a already encoded object to a object Signed-off-by: Fin Maaß <[email protected]>
1 parent 7fef853 commit 01c40dd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/zephyr/data/json.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum json_tokens {
4545
JSON_TOK_FLOAT = '1',
4646
JSON_TOK_OPAQUE = '2',
4747
JSON_TOK_OBJ_ARRAY = '3',
48+
JSON_TOK_ENCODED_OBJ = '4',
4849
JSON_TOK_TRUE = 't',
4950
JSON_TOK_FALSE = 'f',
5051
JSON_TOK_NULL = 'n',

lib/utils/json.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,13 @@ static int opaque_string_encode(struct json_obj_token *opaque, json_append_bytes
10021002
return append_bytes("\"", 1, data);
10031003
}
10041004

1005+
static int encoded_obj_encode(const char **str, json_append_bytes_t append_bytes, void *data)
1006+
{
1007+
size_t len = strlen(*str);
1008+
1009+
return append_bytes(*str, len, data);
1010+
}
1011+
10051012
static int bool_encode(const bool *value, json_append_bytes_t append_bytes,
10061013
void *data)
10071014
{
@@ -1036,6 +1043,8 @@ static int encode(const struct json_obj_descr *descr, const void *val,
10361043
return float_ascii_encode(ptr, append_bytes, data);
10371044
case JSON_TOK_OPAQUE:
10381045
return opaque_string_encode(ptr, append_bytes, data);
1046+
case JSON_TOK_ENCODED_OBJ:
1047+
return encoded_obj_encode(ptr, append_bytes, data);
10391048
default:
10401049
return -EINVAL;
10411050
}

0 commit comments

Comments
 (0)