json: add JSON_TOK_ENCODED_OBJ
add support to include a already encoded object to a object Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
parent
7fef853015
commit
01c40dda1f
@ -45,6 +45,7 @@ enum json_tokens {
|
||||
JSON_TOK_FLOAT = '1',
|
||||
JSON_TOK_OPAQUE = '2',
|
||||
JSON_TOK_OBJ_ARRAY = '3',
|
||||
JSON_TOK_ENCODED_OBJ = '4',
|
||||
JSON_TOK_TRUE = 't',
|
||||
JSON_TOK_FALSE = 'f',
|
||||
JSON_TOK_NULL = 'n',
|
||||
|
||||
@ -1002,6 +1002,13 @@ static int opaque_string_encode(struct json_obj_token *opaque, json_append_bytes
|
||||
return append_bytes("\"", 1, data);
|
||||
}
|
||||
|
||||
static int encoded_obj_encode(const char **str, json_append_bytes_t append_bytes, void *data)
|
||||
{
|
||||
size_t len = strlen(*str);
|
||||
|
||||
return append_bytes(*str, len, data);
|
||||
}
|
||||
|
||||
static int bool_encode(const bool *value, json_append_bytes_t append_bytes,
|
||||
void *data)
|
||||
{
|
||||
@ -1036,6 +1043,8 @@ static int encode(const struct json_obj_descr *descr, const void *val,
|
||||
return float_ascii_encode(ptr, append_bytes, data);
|
||||
case JSON_TOK_OPAQUE:
|
||||
return opaque_string_encode(ptr, append_bytes, data);
|
||||
case JSON_TOK_ENCODED_OBJ:
|
||||
return encoded_obj_encode(ptr, append_bytes, data);
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user