string parsing utility functions described by the [JSON] schema
More...
#include "techtype.h"
#include "dtvstring.h"
Go to the source code of this file.
|
#define | JSON_VALUE_FINISH 0x80000000 |
|
#define | JSON_VALUE_ERROR 0xffffffff |
|
#define | NULL_TOKEN "" |
|
#define | DECLARE_MEMBER(token_str, type, ptr, child_object) { sizeof(token_str) - 1, token_str, type, {ptr}, child_object } |
|
#define | DECLARE_OBJECT(cb_func) { 0, NULL_TOKEN, JST_CBF_OBJECT, {cb_func}, NULL } |
|
#define | DECLARE_OBJEND() { 0, NULL_TOKEN, JST_NOTHING, {NULL}, NULL } |
|
|
enum | E_JSON_TYPE {
JST_NOTHING,
JST_PTR_INTEGER,
JST_PTR_STRING,
JST_PTR_ASTRING,
JST_CBF_OBJECT,
JST_CBF_INTEGER,
JST_CBF_STRING,
JST_CBF_ASTRING,
JST_CBF_ARRAY_OBJ,
JST_CBF_ARRAY_INT,
JST_CBF_ARRAY_STR
} |
|
enum | E_JSON_STATE { JSON_ERROR,
JSON_OKAY,
JSON_MAIN,
JSON_NEXT
} |
|
string parsing utility functions described by the [JSON] schema
- Date
- 15/07/2010
- Author
- Adam Sturtridge
typedef void*(* JsonCallback) (unsigned int val, void *array, void *usr) |
For JST_CBF_STRING, the function is passed pointer to location in JSON data. The purpose of this type is that the string data could have a particular intrepetation (e.g. "dvb location" string or time string). The implementation of the callback could allocate memory, if it wishs to save the string data, but that is provided by JSON parser with JST_CBF_ASTRING. For JST_CBF_ASTRING and for arrays of basic types (JST_CBF_ARRAY_INT and JST_CBF_ARRAY_STR), the JSON parser allocates memory. The user code is responsible for calling appropriate JSON_Free???() when memory is finished.
- Parameters
-
val | JST_CBF_INTEGER the integer value JST_CBF_STRING string length JST_CBF_ASTRING string length (NOT including '\0') JST_CBF_ARRAY_OBJ Start gives count of items, and end has JSON_VALUE_FINISH or JSON_VALUE_ERROR JST_CBF_ARRAY_INT number of integers in allocated array JST_CBF_ARRAY_STR number of strings in allocated array |
array | JST_CBF_INTEGER NULL pointer JST_CBF_STRING string pointer (memory NOT allocated) JST_CBF_ASTRING pointer to memory allocated string JST_CBF_ARRAY_OBJ NULL pointer JST_CBF_ARRAY_INT pointer to allocated array of integers JST_CBF_ARRAY_STR pointer to allocated array of strings (but string pointers NOT allocated) |
usr | user data given to JSON_parse |
- Returns
- n/a
void JSON_FreeAstring |
( |
S_STRING * |
p_str | ) |
|
- Parameters
-
p_str | pointer to allocated string (JST_CBF_ASTRING) |
- Returns
- n/a
void JSON_FreeStrArray |
( |
S_STRING ** |
pp_str | ) |
|
- Parameters
-
array | pointer to allocated array |
type | type of array (JST_CBF_ARRAY_INT or JST_CBF_ARRAY_STR) or allocated string (JST_CBF_ASTRING) |
- Returns
- n/a
void JSON_FreeUintArray |
( |
U32BIT * |
p_uint | ) |
|
- Parameters
-
p_uint | pointer to allocated int array (JST_CBF_ARRAY_INT) |
- Returns
- n/a
E_JSON_STATE JSON_Parse |
( |
U8BIT * |
data, |
|
|
U32BIT |
size, |
|
|
const S_JSON_MEMBERS * |
members, |
|
|
void * |
usr |
|
) |
| |
- Parameters
-
data | pointer to JSON formated data |
size | number of bytes of JSON data |
members | array of [token, type, callback/pointer, children] |
- Returns
- JSON_ERROR, - encountered wrong data JSON_OKAY - success JSON_MAIN,JSON_NEXT - data ended while still processing
- Parameters
-
data | pointer to JSON formated data |
size | number of bytes of JSON data |
members | array of [token, type, callback func] |
- Returns
- JSON_ERROR, - encountered wrong data JSON_OKAY - success JSON_MAIN,JSON_NEXT - data ended while still processing