121 #define SOL_JSON_SCANNER_ARRAY_LOOP_TYPE_NESTED(scanner_, token_, element_type_, status_) \
122 for (status_ = SOL_JSON_LOOP_REASON_OK; \
123 sol_json_loop_iterate_array(scanner_, token_, &status_, element_type_);)
135 #define SOL_JSON_SCANNER_ARRAY_LOOP_TYPE(scanner_, token_, element_type_, status_) \
136 for (status_ = sol_json_loop_iterate_init(scanner_, token_, SOL_JSON_TYPE_ARRAY_START); \
137 sol_json_loop_iterate_array(scanner_, token_, &status_, element_type_);)
151 #define SOL_JSON_SCANNER_ARRAY_LOOP_NESTED(scanner_, token_, status_) \
152 for (status_ = SOL_JSON_LOOP_REASON_OK; \
153 sol_json_loop_iterate_generic(scanner_, token_, SOL_JSON_TYPE_ARRAY_END, &status_);)
163 #define SOL_JSON_SCANNER_ARRAY_LOOP(scanner_, token_, status_) \
164 for (status_ = sol_json_loop_iterate_init(scanner_, token_, SOL_JSON_TYPE_ARRAY_START); \
165 sol_json_loop_iterate_generic(scanner_, token_, SOL_JSON_TYPE_ARRAY_END, &status_);)
180 #define SOL_JSON_SCANNER_OBJECT_LOOP_NESTED(scanner_, token_, key_, value_, status_) \
181 for (status_ = SOL_JSON_LOOP_REASON_OK; \
182 sol_json_loop_iterate_object(scanner_, token_, key_, value_, &status_);)
195 #define SOL_JSON_SCANNER_OBJECT_LOOP(scanner_, token_, key_, value_, status_) \
196 for (status_ = sol_json_loop_iterate_init(scanner_, token_, SOL_JSON_TYPE_OBJECT_START); \
197 sol_json_loop_iterate_object(scanner_, token_, key_, value_, &status_);)
211 scanner->
mem = (
const char *)mem;
213 scanner->
current = (
const char *)mem;
266 scanner->
mem = other->
mem;
314 const char *p = (
const char *)mem;
316 if (p < scanner->mem || p > scanner->
mem_end)
318 return p - scanner->
mem;
331 const char *p = (
const char *)mem;
333 if (strchr(
"{}[],:tfn\"", *p))
335 if (isdigit((uint8_t)*p) || *p ==
'-' || *p ==
'+')
386 return (size == len + 2) && memcmp(token->
start + 1, str, len) == 0;
400 #define SOL_JSON_TOKEN_STR_LITERAL_EQ(token_, str_) \
401 sol_json_token_str_eq(token_, str_, sizeof(str_) - 1)
439 SOL_ATTR_WARN_UNUSED_RESULT
463 if (tmp > UINT32_MAX) {
493 if (tmp > INT32_MAX) {
497 }
else if (tmp < INT32_MIN) {
1069 return slice.
data && slice.
len >= 2 &&
1070 slice.
data[0] ==
'[' &&
1071 slice.
data[1] !=
'\'';
1118 #define SOL_JSON_PATH_FOREACH(scanner, key, status) \
1119 for (status = SOL_JSON_LOOP_REASON_OK; \
1120 sol_json_path_get_next_segment(&scanner, &key_slice, &status);)
static size_t sol_json_scanner_get_size_remaining(const struct sol_json_scanner *scanner)
Returns the size of the JSON document that wasn't scanned yet.
Definition: sol-json.h:296
int sol_json_token_get_int64(const struct sol_json_token *token, int64_t *value)
Get the numeric value of the given token as an 64 bits signed integer.
static void sol_json_scanner_init_from_slice(struct sol_json_scanner *scanner, const struct sol_str_slice slice)
Initialized a JSON scanner from a struct sol_str_slice.
Definition: sol-json.h:236
'null' value
Definition: sol-json.h:91
static int sol_json_token_get_uint32(const struct sol_json_token *token, uint32_t *value)
Get the numeric value of the given token as an 32 bits unsigned integer.
Definition: sol-json.h:458
Unknown token.
Definition: sol-json.h:82
static void sol_json_scanner_init(struct sol_json_scanner *scanner, const void *mem, size_t size)
Initializes a JSON scanner.
Definition: sol-json.h:209
int sol_json_serialize_uint32(struct sol_buffer *buffer, uint32_t val)
Inserts the string of the unsigned 32-bit integer val in the end of the JSON document contained in bu...
const char * start
Token start.
Definition: sol-json.h:74
JSON Pair separator.
Definition: sol-json.h:88
static size_t sol_json_scanner_get_mem_offset(const struct sol_json_scanner *scanner, const void *mem)
Returns the offset of mem in the data managed by scanner.
Definition: sol-json.h:312
const char * end
Points to last character from path.
Definition: sol-json.h:968
int sol_json_get_value_by_path(struct sol_json_scanner *scanner, struct sol_str_slice path, struct sol_json_token *value)
Get the element referenced by the JSON Path path in a JSON Object or Array.
static void sol_json_scanner_init_from_scanner(struct sol_json_scanner *scanner, const struct sol_json_scanner *other)
Initializes a JSON scanner based on the information of a second scanner.
Definition: sol-json.h:263
int sol_json_token_get_uint64(const struct sol_json_token *token, uint64_t *value)
Get the numeric value of the given token as an 64 bits unsigned integer.
const char * mem_end
End of this portion of the JSON document.
Definition: sol-json.h:64
char * sol_json_escape_string(const char *str, struct sol_buffer *buf)
Escapes JSON special and control characters from the string content.
int sol_json_load_memdesc(const struct sol_json_token *token, const struct sol_memdesc *desc, void *memory)
Loads the members of a memory from JSON according to its description.
int sol_json_array_get_at_index(struct sol_json_scanner *scanner, uint16_t i, struct sol_json_token *value)
Get the element in position i in JSON Array contained in scanner.
int32_t sol_json_path_array_get_segment_index(struct sol_str_slice key)
Get the integer index from a JSON Path array segment.
size_t sol_json_calculate_escaped_string_len(const char *str)
Calculate the size in bytes of the escaped version of a string.
Scanner used to go through segments of a JSON Path.
Definition: sol-json.h:966
bool sol_json_scanner_skip(struct sol_json_scanner *scanner, struct sol_json_token *token)
Modifies scanner to point to token end, skipping over the token content.
Failed to parse the content.
Definition: sol-json.h:106
const char * current
Points to last visited position from path and the beginning of next segment.
Definition: sol-json.h:973
struct sol_json_token sol_json_token
Type describing a JSON token.
static bool sol_json_loop_iterate_object(struct sol_json_scanner *scanner, struct sol_json_token *token, struct sol_json_token *key, struct sol_json_token *value, enum sol_json_loop_status *reason)
Function to help iterate over a JSON object.
Definition: sol-json.h:670
bool sol_json_is_valid_type(struct sol_json_scanner *scanner, enum sol_json_type start_type)
Check if scanner content is pointing to a valid JSON element of type start_type.
static int sol_json_serialize_null(struct sol_buffer *buffer)
Inserts the string "null" in the end of the JSON document contained in buffer.
Definition: sol-json.h:839
These are common Soletta macros.
const char * current
Current point in the JSON document that needs to be processed.
Definition: sol-json.h:65
JSON Array start.
Definition: sol-json.h:85
static struct sol_buffer value
Definition: server.c:42
const char * path
The JSONPath string.
Definition: sol-json.h:967
static bool sol_json_loop_iterate_array(struct sol_json_scanner *scanner, struct sol_json_token *token, enum sol_json_loop_status *reason, enum sol_json_type element_type)
Function to help iterate over a JSON array.
Definition: sol-json.h:643
static void sol_json_token_init_from_slice(struct sol_json_token *token, const struct sol_str_slice slice)
Initialized a JSON token from a struct sol_str_slice.
Definition: sol-json.h:248
int sol_json_serialize_int64(struct sol_buffer *buffer, int64_t val)
Inserts the string of the 64-bit integer val in the end of the JSON document contained in buffer...
String slice type.
Definition: sol-str-slice.h:84
static struct sol_cert * key
Definition: server-https.c:51
These are routines that Soletta provides for its buffer implementation.
bool sol_json_scanner_get_dict_pair(struct sol_json_scanner *scanner, struct sol_json_token *key, struct sol_json_token *value)
Retrieve <key, value> pair currently pointed by scanner.
static enum sol_json_type sol_json_mem_get_type(const void *mem)
Returns the type of the token pointed by mem.
Definition: sol-json.h:329
#define SOL_ATTR_WARN_UNUSED_RESULT
Causes a warning to be emitted if a caller of the function with this attribute does not use its retur...
Definition: sol-macros.h:187
int sol_json_serialize_double(struct sol_buffer *buffer, double val)
Inserts the string of the double val in the end of the JSON document contained in buffer...
These are routines that Soletta provides for its memory description (memdesc) implementation.
Type describing a JSON token.
Definition: sol-json.h:73
char * sol_json_token_get_unescaped_string_copy(const struct sol_json_token *value)
Creates a copy of the unescaped and no-quotes string produced by sol_json_token_get_unescaped_string...
int sol_json_serialize_string(struct sol_buffer *buffer, const char *str)
Inserts the string str in the end of the JSON document contained in buffer.
int sol_json_path_scanner_init(struct sol_json_path_scanner *scanner, struct sol_str_slice path)
Initialize a JSON Path scanner with path.
int sol_json_object_get_value_by_key(struct sol_json_scanner *scanner, const struct sol_str_slice key_slice, struct sol_json_token *value)
Get the value of the JSON Object child element referenced by key_slice.
static enum sol_json_type sol_json_token_get_type(const struct sol_json_token *token)
Returns the type of the token pointed by token.
Definition: sol-json.h:348
int sol_json_token_get_double(const struct sol_json_token *token, double *value) SOL_ATTR_WARN_UNUSED_RESULT
Get the numeric value of the given token as double-precision floating point.
JSON Array end.
Definition: sol-json.h:86
int sol_buffer_append_slice(struct sol_buffer *buf, const struct sol_str_slice slice)
Appends slice into the end of buf, reallocating if necessary.
const char * data
Slice data.
Definition: sol-str-slice.h:86
struct sol_json_path_scanner sol_json_path_scanner
Scanner used to go through segments of a JSON Path.
bool sol_json_scanner_next(struct sol_json_scanner *scanner, struct sol_json_token *token)
Advance the scanner to the next JSON token.
int sol_json_serialize_uint64(struct sol_buffer *buffer, uint64_t val)
Inserts the string of the unsigned 64-bit integer val in the end of the JSON document contained in bu...
#define SOL_ATTR_NON_NULL(...)
Specifies that some function parameters should be non-null pointers.
Definition: sol-macros.h:193
int sol_json_serialize_memdesc(struct sol_buffer *buffer, const struct sol_memdesc *desc, const void *memory, bool detailed_structures)
Appends the serialization of the given memory based on its description.
#define SOL_STR_SLICE_STR(_s, _len)
Helper macro to make easier to declare a string slice from a string.
Definition: sol-str-slice.h:67
'true' value
Definition: sol-json.h:89
static bool sol_json_path_is_array_key(struct sol_str_slice slice)
Check if slice is a valid JSON Path array segment.
Definition: sol-json.h:1067
static void sol_json_scanner_init_from_token(struct sol_json_scanner *scanner, const struct sol_json_token *token)
Initializes a JSON scanner based on the information of a JSON Token.
Definition: sol-json.h:280
int sol_json_serialize_bool(struct sol_buffer *buffer, bool val)
Inserts the string of the boolean value val in the end of the JSON document contained in buffer...
const char * mem
Start of this portion of the JSON document.
Definition: sol-json.h:63
#define SOL_STR_SLICE_LITERAL(_s)
Helper macro to make easier to declare a string slice from a string literal.
Definition: sol-str-slice.h:62
Structure to track a JSON document (or a portion of it) being parsed.
Definition: sol-json.h:62
static bool sol_json_token_str_eq(const struct sol_json_token *token, const char *str, size_t len)
Checks if the string pointed by token is equal to the string str.
Definition: sol-json.h:379
JSON number token.
Definition: sol-json.h:93
static size_t sol_json_token_get_size(const struct sol_json_token *token)
Returns the token size.
Definition: sol-json.h:361
JSON Element separator.
Definition: sol-json.h:87
JSON string token.
Definition: sol-json.h:92
static bool sol_json_loop_iterate_generic(struct sol_json_scanner *scanner, struct sol_json_token *token, enum sol_json_type end_type, enum sol_json_loop_status *reason)
Function to help iterate over a generic JSON sequence.
Definition: sol-json.h:606
Data type to describe a memory region.
Definition: sol-memdesc.h:514
bool sol_json_path_get_next_segment(struct sol_json_path_scanner *scanner, struct sol_str_slice *slice, enum sol_json_loop_status *status)
Get next segment from JSON Path in scanner.
int sol_json_serialize_int32(struct sol_buffer *buffer, int32_t val)
Inserts the string of the 32-bit integer val in the end of the JSON document contained in buffer...
static int sol_json_token_get_int32(const struct sol_json_token *token, int32_t *value)
Get the numeric value of the given token as an 32 bits signed integer.
Definition: sol-json.h:488
int sol_json_token_get_unescaped_string(const struct sol_json_token *token, struct sol_buffer *buffer)
Copy to a sol_buffer the string pointed by token.
Content successfully parsed.
Definition: sol-json.h:105
These are routines that Soletta provides for its string slice implementation.
static enum sol_json_loop_status sol_json_loop_iterate_init(struct sol_json_scanner *scanner, struct sol_json_token *token, enum sol_json_type start_type)
Function to bootstrap an iteration over a JSON sequence.
Definition: sol-json.h:696
JSON Object start.
Definition: sol-json.h:83
sol_json_type
Token type enumeration.
Definition: sol-json.h:81
sol_json_loop_status
Return values used by the parser 'loop' macros.
Definition: sol-json.h:104
const char * end
Token end.
Definition: sol-json.h:75
static struct sol_str_slice sol_json_token_to_slice(const struct sol_json_token *token)
Converts a JSON token to a string slice.
Definition: sol-json.h:534
'false' value
Definition: sol-json.h:90
JSON Object end.
Definition: sol-json.h:84
A sol_buffer is a dynamic array, that can be resized if needed.
Definition: sol-buffer.h:130
struct sol_json_scanner sol_json_scanner
Structure to track a JSON document (or a portion of it) being parsed.
int sol_json_double_to_str(const double value, struct sol_buffer *buf)
Converts a double into a string suited for use in a JSON Document.
size_t len
Slice length.
Definition: sol-str-slice.h:85
static void sol_json_scanner_init_null(struct sol_json_scanner *scanner)
Initializes a JSON scanner with empty information.
Definition: sol-json.h:222