28 #ifndef JSMN_PARSER_H_ 
   29 #define JSMN_PARSER_H_ 
   39 #define ASSERT_JSMN_TYPE(tok, toktype, j) \ 
   40     if ((tok)->type != toktype){ \ 
   41         log_error("Got type %d, expected %d while parsing %.50s", \ 
   42                   (tok)->type, toktype, &j[(tok)->start]); \ 
   76 #define PARSE_FN(fn_name) \ 
   77     static int fn_name(jsmntok_t **tok__, char *j__, \ 
   78                      struct json_state *in__, struct json_state **saved__) 
   81 #define GET_PARSE_OBJ() \ 
   85 #define GET_STR_TOK() \ 
   86     tok_to_str(*tok__, j__) 
   89 #define GET_INT_TOK() \ 
   90     tok_to_int(*tok__, j__) 
   93 #define GET_LONG_TOK() \ 
   94     tok_to_long(*tok__, j__) 
  103 #define PARSE_OBJ_LIST_FN(fn_name, init_fn) \ 
  104     static int fn_name(jsmntok_t **tok__, char *j__, \ 
  105                        struct json_state *in__, struct json_state **saved__) { \ 
  106         return parse_jsmn_obj_list(tok__, j__, in__, saved__, init_fn); \ 
  114 #define INIT_OBJ_FN(fn_name) \ 
  115     static struct json_state fn_name(struct json_state *in__, int index__) 
  120 #define GET_OBJ_INDEX() index__ 
  128 #define RETURN_OBJ(data__, type__) \ 
  129     struct json_state out_obj__ = { \ 
  131         .parent_type = type__ \ 
  143 #define PARSE_OBJ_FN(fn_name, parent_obj_type, parent_obj_field, new_type) \ 
  144     static int fn_name(jsmntok_t **tok__, char *j__, \ 
  145                        struct json_state *in__, struct json_state **saved__) { \ 
  146         parent_obj_type *type_out__ = in__->data; \ 
  147         struct json_state state_out__ = { \ 
  148             .data = &type_out__->parent_obj_field, \ 
  149             .parent_type = new_type, \ 
  152         if (parse_jsmn_obj(tok__, j__, &state_out__, saved__) < 0) { \ 
  164 #define START_ITER_TOK_LIST(i)  \ 
  165     int tok_size__ = (*tok__)->size; \ 
  166     for (i = 0, ++(*tok__); i< tok_size__;  ++(*tok__), i++) 
  172 #define END_ITER_TOK_LIST(i) \ 
  173     *tok__ = (*tok__) - (tok_size__ - i + 1); 
jsmn_parsing_fn parse
The function to be called when this string is seen at the appropriate place in the input JSON...
int parse_str_into_obj(char *contents, void *obj, struct key_mapping *km)
Using the provided functions, parses the JSON present in in the provided string and stores the result...
int jsmn_ignore(jsmntok_t **tok, char *j, struct json_state *in, struct json_state **saved)
Can be used as a jsmn_parsing_fn that ignores any value passed into it. 
int parse_jsmn_obj_list(jsmntok_t **tok, char *j, struct json_state *in, struct json_state **saved, jsmn_initializer init)
SHOULD NOT BE USED DIRECTLY. 
char * key
The string in the JSON file. 
int parse_file_into_obj(const char *filename, void *obj, struct key_mapping *km)
Using the provided functions, parses the JSON present in 'filename' and stores the resulting object i...
char * tok_to_str(jsmntok_t *tok, char *j)
SHOULD NOT BE USED DIRECTLT. 
Structure to hold state while parsing JSON. 
int parent_type
The type of object that is being create. 
int(* jsmn_parsing_fn)(jsmntok_t **tok, char *j, struct json_state *state, struct json_state **saved)
Typedef for a jsmn parsing function. 
Structure to map a key + state to a function. 
int parent_type
The current type, as set by a previous parsing fn. 
struct json_state(* jsmn_initializer)(struct json_state *state, int index)
Typedef for a json_state initializer, used when iterating over lists of objects. 
int tok_to_int(jsmntok_t *tok, char *j)
SHOULD NOT BE USED DIRECTLY. 
void * get_root_jsmn_obj()
Returns the initial object passed into the JSON parser. 
long tok_to_long(jsmntok_t *tok, char *j)
SHOULD NOT BE USED DIRECTLY. 
void * data
The object currently under construction. 
int parse_jsmn_obj(jsmntok_t **tok, char *j, struct json_state *in, struct json_state **saved)
SHOULD NOT BE USED DIRECTLY. 
jsmntok_t * tok
When saving state, provides a linked-list.