Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions
sol-json.h File Reference

These are the parser routines that Soletta provides. More...

#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <stdint.h>
#include <sol-buffer.h>
#include <sol-macros.h>
#include <sol-str-slice.h>
#include <sol-memdesc.h>

Go to the source code of this file.

Data Structures

struct  sol_json_path_scanner
 Scanner used to go through segments of a JSON Path. More...
 
struct  sol_json_scanner
 Structure to track a JSON document (or a portion of it) being parsed. More...
 
struct  sol_json_token
 Type describing a JSON token. More...
 

Macros

#define SOL_JSON_PATH_FOREACH(scanner, key, status)
 Go through all segments of a JSON Path. More...
 
#define SOL_JSON_SCANNER_ARRAY_LOOP(scanner_, token_, status_)
 Helper macro to iterate over the elements an array in a JSON document, ignoring the elements type. More...
 
#define SOL_JSON_SCANNER_ARRAY_LOOP_NESTED(scanner_, token_, status_)
 Helper macro to iterate over the elements of a nested array in a JSON document, ignoring the elements type. More...
 
#define SOL_JSON_SCANNER_ARRAY_LOOP_TYPE(scanner_, token_, element_type_, status_)
 Helper macro to iterate over the elements of an array in a JSON document. More...
 
#define SOL_JSON_SCANNER_ARRAY_LOOP_TYPE_NESTED(scanner_, token_, element_type_, status_)
 Helper macro to iterate over the elements of a nested array in a JSON document. More...
 
#define SOL_JSON_SCANNER_OBJECT_LOOP(scanner_, token_, key_, value_, status_)
 Helper macro to iterate over the elements of an object in a JSON document. More...
 
#define SOL_JSON_SCANNER_OBJECT_LOOP_NESTED(scanner_, token_, key_, value_, status_)
 Helper macro to iterate over the elements of a nested object in a JSON document. More...
 
#define SOL_JSON_TOKEN_STR_LITERAL_EQ(token_, str_)   sol_json_token_str_eq(token_, str_, sizeof(str_) - 1)
 Helper macro to check if the string pointed by token_ is equal to a string literal. More...
 

Typedefs

typedef struct
sol_json_path_scanner 
sol_json_path_scanner
 Scanner used to go through segments of a JSON Path. More...
 
typedef struct sol_json_scanner sol_json_scanner
 Structure to track a JSON document (or a portion of it) being parsed. More...
 
typedef struct sol_json_token sol_json_token
 Type describing a JSON token. More...
 

Enumerations

enum  sol_json_loop_status { SOL_JSON_LOOP_REASON_OK = 0, SOL_JSON_LOOP_REASON_INVALID }
 Return values used by the parser 'loop' macros. More...
 
enum  sol_json_type {
  SOL_JSON_TYPE_UNKNOWN = 0, SOL_JSON_TYPE_OBJECT_START = '{', SOL_JSON_TYPE_OBJECT_END = '}', SOL_JSON_TYPE_ARRAY_START = '[',
  SOL_JSON_TYPE_ARRAY_END = ']', SOL_JSON_TYPE_ELEMENT_SEP = ',', SOL_JSON_TYPE_PAIR_SEP = ':', SOL_JSON_TYPE_TRUE = 't',
  SOL_JSON_TYPE_FALSE = 'f', SOL_JSON_TYPE_NULL = 'n', SOL_JSON_TYPE_STRING = '"', SOL_JSON_TYPE_NUMBER = '1'
}
 Token type enumeration. More...
 

Functions

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. More...
 
size_t sol_json_calculate_escaped_string_len (const char *str)
 Calculate the size in bytes of the escaped version of a string. More...
 
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. More...
 
char * sol_json_escape_string (const char *str, struct sol_buffer *buf)
 Escapes JSON special and control characters from the string content. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static enum sol_json_type sol_json_mem_get_type (const void *mem)
 Returns the type of the token pointed by mem. More...
 
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. More...
 
int32_t sol_json_path_array_get_segment_index (struct sol_str_slice key)
 Get the integer index from a JSON Path array segment. More...
 
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. More...
 
static bool sol_json_path_is_array_key (struct sol_str_slice slice)
 Check if slice is a valid JSON Path array segment. More...
 
int sol_json_path_scanner_init (struct sol_json_path_scanner *scanner, struct sol_str_slice path)
 Initialize a JSON Path scanner with path. More...
 
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. More...
 
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. More...
 
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. More...
 
static void sol_json_scanner_init (struct sol_json_scanner *scanner, const void *mem, size_t size)
 Initializes a JSON scanner. More...
 
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. More...
 
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. More...
 
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. More...
 
static void sol_json_scanner_init_null (struct sol_json_scanner *scanner)
 Initializes a JSON scanner with empty information. More...
 
bool sol_json_scanner_next (struct sol_json_scanner *scanner, struct sol_json_token *token)
 Advance the scanner to the next JSON token. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static int sol_json_serialize_null (struct sol_buffer *buffer)
 Inserts the string "null" in the end of the JSON document contained in buffer. More...
 
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. More...
 
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 buffer. More...
 
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 buffer. More...
 
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. More...
 
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. More...
 
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. More...
 
static size_t sol_json_token_get_size (const struct sol_json_token *token)
 Returns the token size. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static struct sol_str_slice sol_json_token_to_slice (const struct sol_json_token *token)
 Converts a JSON token to a string slice. More...
 

Detailed Description

These are the parser routines that Soletta provides.