jkii
Data Structures | Typedefs | Enumerations | Functions
jkii.h File Reference

This is a file defining Kii JSON APIs. More...

#include <jsmn.h>

Go to the source code of this file.

Data Structures

struct  jkii_resource_t
 
struct  jkii_field_t
 

Typedefs

typedef jsmntok_t jkii_token_t
 
typedef struct jkii_resource_t jkii_resource_t
 
typedef jkii_resource_t *(* JKII_CB_RESOURCE_ALLOC) (size_t required_size)
 
typedef void(* JKII_CB_RESOURCE_FREE) (jkii_resource_t *resource)
 
typedef enum jkii_boolean_t jkii_boolean_t
 
typedef enum jkii_parse_err_t jkii_parse_err_t
 
typedef enum jkii_field_err_t jkii_field_err_t
 
typedef enum jkii_field_type_t jkii_field_type_t
 
typedef struct jkii_field_t jkii_field_t
 

Enumerations

enum  jkii_boolean_t { JKII_FALSE, JKII_TRUE }
 
enum  jkii_parse_err_t {
  JKII_ERR_OK, JKII_ERR_PARTIAL, JKII_ERR_ROOT_TYPE, JKII_ERR_TOKENS_SHORTAGE,
  JKII_ERR_INVALID_INPUT, JKII_ERR_ALLOCATION
}
 
enum  jkii_field_err_t {
  JKII_FIELD_ERR_OK, JKII_FIELD_ERR_TYPE_MISMATCH, JKII_FIELD_ERR_NOT_FOUND, JKII_FIELD_ERR_COPY,
  JKII_FIELD_ERR_NUM_OVERFLOW, JKII_FIELD_ERR_NUM_UNDERFLOW
}
 
enum  jkii_field_type_t {
  JKII_FIELD_TYPE_ANY, JKII_FIELD_TYPE_INTEGER, JKII_FIELD_TYPE_LONG, JKII_FIELD_TYPE_DOUBLE,
  JKII_FIELD_TYPE_BOOLEAN, JKII_FIELD_TYPE_NULL, JKII_FIELD_TYPE_STRING, JKII_FIELD_TYPE_OBJECT,
  JKII_FIELD_TYPE_ARRAY
}
 

Functions

jkii_parse_err_t jkii_parse (const char *json_string, size_t json_string_len, jkii_field_t *fields, jkii_resource_t *resource)
 
jkii_parse_err_t jkii_parse_with_allocator (const char *json_string, size_t json_string_len, jkii_field_t *fields, JKII_CB_RESOURCE_ALLOC cb_alloc, JKII_CB_RESOURCE_FREE cb_free)
 

Detailed Description

This is a file defining Kii JSON APIs.

Typedef Documentation

◆ jkii_boolean_t

Boolean type

◆ JKII_CB_RESOURCE_ALLOC

typedef jkii_resource_t*(* JKII_CB_RESOURCE_ALLOC) (size_t required_size)

Resource allocator for jkii_resource_t.

Parameters
[in]required_sizerequired token size.
Returns
jkii_resource_t instance of NULL if failed to allocate resource.

◆ JKII_CB_RESOURCE_FREE

typedef void(* JKII_CB_RESOURCE_FREE) (jkii_resource_t *resource)

◆ jkii_field_err_t

Field parsing result. Assigned to jkii_field_t::result.

◆ jkii_field_t

typedef struct jkii_field_t jkii_field_t

JSON parsed field data.

Input of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

Array of jkii_field_t is passed to jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*).

End point of the array is specified by jkii_field_t::name and jkii_field_t::path. If both of jkii_field_t::name and jkii_field_t::path are NULL, jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*) consider that it is the end point of the passed array.

◆ jkii_field_type_t

Type of parsed JSON field. This value is assigned to jkii_field_t::type.

◆ jkii_parse_err_t

Return value of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*)

◆ jkii_resource_t

Resource used by KII JSON library. Fields of this struct determines max number of tokens inside json can be parsed.

◆ jkii_token_t

typedef jsmntok_t jkii_token_t

JSON token data to parse JSON string.

Enumeration Type Documentation

◆ jkii_boolean_t

Boolean type

Enumerator
JKII_FALSE 
JKII_TRUE 

◆ jkii_field_err_t

Field parsing result. Assigned to jkii_field_t::result.

Enumerator
JKII_FIELD_ERR_OK 

Field parsing is success.

JKII_FIELD_ERR_TYPE_MISMATCH 

Type of field specified jkii_field_t::type is mismatch.

JKII_FIELD_ERR_NOT_FOUND 

Field specified by jkii_field_t::name is not found.

JKII_FIELD_ERR_COPY 

Coping string to jkii_field_t::field_copy::string is failed. jkii_field_t::field_copy_buff_size may shorter than actual length.

JKII_FIELD_ERR_NUM_OVERFLOW 

Coping int, long or double value to jkii_field_t::field_copy::int_value, jkii_field_t::field_copy::long_value or jkii_field_t::field_copy::double_value is failed. value is overflowed.

JKII_FIELD_ERR_NUM_UNDERFLOW 

Coping int, long or double value to jkii_field_t::field_copy::int_value, jkii_field_t::field_copy::long_value or jkii_field_t::field_copy::double_value is failed. value is underflowed.

◆ jkii_field_type_t

Type of parsed JSON field. This value is assigned to jkii_field_t::type.

Enumerator
JKII_FIELD_TYPE_ANY 

This value denotes any JSON types. If this value is set to jkii_field_t::type, then jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*) ignore type checking.

JKII_FIELD_TYPE_INTEGER 

This values denotes an signed interger value. Maximum is INT_MAX and Minimum is INT_MIN.

JKII_FIELD_TYPE_LONG 

This values denotes an signed interger value. Maximum is LONG_MAX and Minimum is LONG_MIN.

JKII_FIELD_TYPE_DOUBLE 

This value denotes an double value.

JKII_FIELD_TYPE_BOOLEAN 

This value denotes jkii_boolean_t value.

JKII_FIELD_TYPE_NULL 

This value denotes denotes NULL value.

JKII_FIELD_TYPE_STRING 

This value denotes JSON string.

JKII_FIELD_TYPE_OBJECT 

This value denotes JSON object.

JKII_FIELD_TYPE_ARRAY 

This value denotes JSON array.

◆ jkii_parse_err_t

Return value of jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*)

Enumerator
JKII_ERR_OK 

JSON string is successfully parsed and all jkii_field_t variables are successfully set. i.e., all jkii_field_t type fields are JKII_FIELD_ERR_OK.

JKII_ERR_PARTIAL 

JSON string is successfully parsed but some jkii_field_t variables are failed. i.e., some jkii_field_t type fields are not JKII_FIELD_ERR_OK.

JKII_ERR_ROOT_TYPE 

JSON string is successfully parsed but type of root object type is unmatched to using function.

jkii_parse(jkii_t*, const char*, size_t, jkii_field_t*) requires JSON object if JSON array is passed, then this error is returned.

JKII_ERR_TOKENS_SHORTAGE 

jkii_t::tokens is not enough to parse JSON string.

JKII_ERR_INVALID_INPUT 

JSON string is failed to parse. Passed string is not JSON string.

JKII_ERR_ALLOCATION 

Allocation failed.

Function Documentation

◆ jkii_parse()

jkii_parse_err_t jkii_parse ( const char *  json_string,
size_t  json_string_len,
jkii_field_t fields,
jkii_resource_t resource 
)

Parse JSON string.

Parameters
[in]json_stringof JSON string.
[in]json_string_lenof JSON string.
[in,out]fieldsof kii JSON parser.
[in]resourceof parser.
Returns
parse result.

◆ jkii_parse_with_allocator()

jkii_parse_err_t jkii_parse_with_allocator ( const char *  json_string,
size_t  json_string_len,
jkii_field_t fields,
JKII_CB_RESOURCE_ALLOC  cb_alloc,
JKII_CB_RESOURCE_FREE  cb_free 
)

Parse JSON string with custom memory allocator.

Parameters
[in]json_stringof JSON string.
[in]json_string_lenof JSON string.
[in,out]fieldsof kii JSON parser.
[in]cb_allocallocate resource
[in]cb_freefree resource
Returns
parse result.