MHEG  17.9.0
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
Data Structures | Macros | Typedefs | Enumerations | Functions
mh5json.h File Reference

string parsing utility functions described by the [JSON] schema More...

#include "techtype.h"
#include "dtvstring.h"

Go to the source code of this file.

Data Structures

struct  s_json_members
 

Macros

#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 }
 

Typedefs

typedef void *(* JsonCallback )(unsigned int val, void *array, void *usr)
 
typedef struct s_json_members S_JSON_MEMBERS
 

Enumerations

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 }
 

Functions

E_JSON_STATE JSON_Parse (U8BIT *data, U32BIT size, const S_JSON_MEMBERS *members, void *usr)
 
void JSON_FreeAstring (S_STRING *p_str)
 
void JSON_FreeUintArray (U32BIT *p_uint)
 
void JSON_FreeStrArray (S_STRING **pp_str)
 

Detailed Description

string parsing utility functions described by the [JSON] schema

Date
15/07/2010
Author
Adam Sturtridge

Typedef Documentation

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
valJST_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
arrayJST_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)
usruser data given to JSON_parse
Returns
n/a

Function Documentation

void JSON_FreeAstring ( S_STRING p_str)
Parameters
p_strpointer to allocated string (JST_CBF_ASTRING)
Returns
n/a
void JSON_FreeStrArray ( S_STRING **  pp_str)
Parameters
arraypointer to allocated array
typetype 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_uintpointer 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
datapointer to JSON formated data
sizenumber of bytes of JSON data
membersarray 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
datapointer to JSON formated data
sizenumber of bytes of JSON data
membersarray of [token, type, callback func]
Returns
JSON_ERROR, - encountered wrong data JSON_OKAY - success JSON_MAIN,JSON_NEXT - data ended while still processing