WE310F5  39.00.000
M2MB JSON

This section describes the M2MB APIs for the JSON module. More...

enum  M2MB_JSON_OBJ_TYPE {
  M2MB_JSON_COMPLEX_ELEMENT,
  M2MB_JSON_SIMPLE_ELEMENT
}
 Object type supported by the json. More...
 
enum  M2MB_JSON_DATA_TYPE {
  M2MB_JSON_DT_NONE,
  M2MB_JSON_DT_UINT8,
  M2MB_JSON_DT_INT8,
  M2MB_JSON_DT_UINT16,
  M2MB_JSON_DT_INT16,
  M2MB_JSON_DT_UINT32,
  M2MB_JSON_DT_INT32,
  M2MB_JSON_DT_UINT64,
  M2MB_JSON_DT_INT64,
  M2MB_JSON_DT_FLOAT,
  M2MB_JSON_DT_DOUBLE,
  M2MB_JSON_DT_STR,
  M2MB_JSON_DT_TOKEN,
  M2MB_JSON_DT_BASE64BIN,
  M2MB_JSON_DT_HEXBIN,
  M2MB_JSON_DT_DATE,
  M2MB_JSON_DT_TIME,
  M2MB_JSON_DT_DATE_TIME,
  M2MB_JSON_DT_DURATION,
  M2MB_JSON_DT_BOOL,
  M2MB_JSON_DT_TLV8,
  M2MB_JSON_DT_IPV4,
  M2MB_JSON_DT_IPV6,
  M2MB_JSON_DT_IP,
  M2MB_JSON_DT_MAC
}
 Data type supported by the json. More...
 
typedef enum M2MB_JSON_OBJ_TYPE M2MB_JSON_OBJ_TYPE_T
 Object type supported by the json. More...
 
typedef enum M2MB_JSON_DATA_TYPE M2MB_JSON_DATA_TYPE_T
 Data type supported by the json. More...
 
typedef struct M2MB_JSON_NODE M2MB_JSON_NODE_T
 Json node structure. More...
 
typedef struct M2MB_JSON_DATE M2MB_JSON_DATE_T
 Json date structure json. More...
 
typedef struct M2MB_JSON_TIME M2MB_JSON_TIME_T
 Json time structure json. More...
 
typedef struct M2MB_JSON_DATE_TIME M2MB_JSON_DATE_TIME_T
 Json date & time structure json. More...
 
typedef struct M2MB_JSON_DURATION M2MB_JSON_DURATION_T
 Json duration structure. More...
 
typedef struct M2MB_JSON_HEX M2MB_JSON_HEX_T
 HEX stream structure json. More...
 
typedef struct M2MB_JSON_OBJ M2MB_JSON_OBJ_T
 Json object structure. More...
 
typedef struct M2MB_JSON_COMPLEX_INFO M2MB_JSON_COMPLEX_INFO_T
 Json complex information structure. More...
 
typedef struct M2MB_JSON_COMPLEX_OBJ M2MB_JSON_COMPLEX_OBJ_T
 Json complex object structure. More...
 
M2MB_STATUS_T m2mb_json_encode (M2MB_JSON_COMPLEX_OBJ_T *jsonSchema, UINT8 *usrStruct, UINT8 *jsonFileBuffer, UINT32 jsonFileBufferSize, UINT32 *lenOfJsonWritten)
 Encode API for JSON module. More...
 
M2MB_STATUS_T m2mb_json_decode (UINT8 *parent_start, UINT8 *parent_end, M2MB_JSON_COMPLEX_OBJ_T *jsonSchema, UINT8 *returnStruct)
 Decode API for JSON module. More...
 
UINT16 m2mb_json_node_get (M2MB_JSON_NODE_T *pCNode, UINT8 *pPNStart, UINT8 *pPNEnd)
 Get node API for JSON module. More...
 
UINT16 m2mb_json_node_occ_get (UINT8 *pTName, UINT8 *pPNStart, UINT8 *pPNEnd)
 Occurrence of node present API for JSON module. More...
 

Detailed Description

This section describes the M2MB APIs for the JSON module.

JSON modules provides APIs to decodes a JSON string and fills the parameters in the provided structure. Similarly it also provides APIs to encode JSON string from the provided structure. The structure information and the JSON tag information are given to the JSON module in a proprietary embedded schema format. Each TAG in JSON string is defined in structured format that gives the detail information about it, like the tag name, tag type, info on where to decode and fill the data of the tag, tag data type.

Typedef Documentation

◆ M2MB_JSON_COMPLEX_INFO_T

Json complex information structure.

Json complex information structure.

◆ M2MB_JSON_COMPLEX_OBJ_T

Json complex object structure.

Json complex object structure.

◆ M2MB_JSON_DATA_TYPE_T

Data type supported by the json.

List of data types supported by json module.

◆ M2MB_JSON_DATE_T

Json date structure json.

Date structure json module.

◆ M2MB_JSON_DATE_TIME_T

Json date & time structure json.

Date & Time structure json module.

◆ M2MB_JSON_DURATION_T

Json duration structure.

Duration structure json module.

◆ M2MB_JSON_HEX_T

HEX stream structure json.

Hex stream structure json module.

◆ M2MB_JSON_NODE_T

Json node structure.

Json node structure.

◆ M2MB_JSON_OBJ_T

Json object structure.

Json object structure.

◆ M2MB_JSON_OBJ_TYPE_T

Object type supported by the json.

List of object types supported by json module.

◆ M2MB_JSON_TIME_T

Json time structure json.

Time structure json module.

Enumeration Type Documentation

◆ M2MB_JSON_DATA_TYPE

Data type supported by the json.

List of data types supported by json module.

Enumerator
M2MB_JSON_DT_NONE 
M2MB_JSON_DT_UINT8 
M2MB_JSON_DT_INT8 
M2MB_JSON_DT_UINT16 
M2MB_JSON_DT_INT16 
M2MB_JSON_DT_UINT32 
M2MB_JSON_DT_INT32 
M2MB_JSON_DT_UINT64 
M2MB_JSON_DT_INT64 
M2MB_JSON_DT_FLOAT 
M2MB_JSON_DT_DOUBLE 
M2MB_JSON_DT_STR 
M2MB_JSON_DT_TOKEN 
M2MB_JSON_DT_BASE64BIN 
M2MB_JSON_DT_HEXBIN 
M2MB_JSON_DT_DATE 
M2MB_JSON_DT_TIME 
M2MB_JSON_DT_DATE_TIME 
M2MB_JSON_DT_DURATION 
M2MB_JSON_DT_BOOL 
M2MB_JSON_DT_TLV8 
M2MB_JSON_DT_IPV4 
M2MB_JSON_DT_IPV6 
M2MB_JSON_DT_IP 
M2MB_JSON_DT_MAC 

Definition at line 80 of file m2mb_json.h.

◆ M2MB_JSON_OBJ_TYPE

Object type supported by the json.

List of object types supported by json module.

Enumerator
M2MB_JSON_COMPLEX_ELEMENT 
M2MB_JSON_SIMPLE_ELEMENT 

Definition at line 69 of file m2mb_json.h.

Function Documentation

◆ m2mb_json_decode()

M2MB_STATUS_T m2mb_json_decode ( UINT8 parent_start,
UINT8 parent_end,
M2MB_JSON_COMPLEX_OBJ_T jsonSchema,
UINT8 returnStruct 
)

Decode API for JSON module.

This function decode the Json file,extract the data and fill that on user structure.

Parameters
[in]parent_startThe starting address of the Json file
[in]parent_endThe Ending address of the Json file.
[in]jsonSchema
[in]returnStructThe user structure buffer to be filled with the data.
Returns
M2MB_OK – when json decode was successful M2MB_ERROR – when json decode failed
Note
<Notes>

Example

typedef struct M2M_WLAN_STA_CFG_S
{
UINT8 enable;
UINT8 ssid[33];
UINT8 pwd[65];
}M2M_WLAN_STA_CFG_T;
const M2MB_JSON_OBJ_T json_sta_enable_in =
{
"enable",
1,
offsetof(M2M_WLAN_STA_CFG_T, enable),
sizeof( UINT8 )
};
const M2MB_JSON_OBJ_T json_sta_wlan_ssid_in =
{
"ssid",
1,
offsetof(M2M_WLAN_STA_CFG_T, ssid),
33
};
const M2MB_JSON_OBJ_T json_sta_wlan_pwd_in =
{
"pwd",
1,
offsetof(M2M_WLAN_STA_CFG_T, pwd),
65
};
const M2MB_JSON_OBJ_T* json_sta_wlan_input[] = {
( const M2MB_JSON_OBJ_T* )&json_sta_enable_in,
( const M2MB_JSON_OBJ_T* )&json_sta_wlan_ssid_in,
( const M2MB_JSON_OBJ_T* )&json_sta_wlan_pwd_in,
};
const M2MB_JSON_COMPLEX_OBJ_T json_sta_wlan_schema = {
"sta",
1,
offsetof( M2MB_STA_CFG_T, pWlan ),
sizeof( M2M_WLAN_STA_CFG_T ),
{
sizeof(json_sta_wlan_input)/sizeof(M2MB_JSON_OBJ_T*),
json_sta_wlan_input
}
};
const UINT8 encoded_str = "\"sta\": {\"enable\": 1,\"ssid\": \"SSID1\",\"pwd\": \"PWD1\"};"
M2M_WLAN_STA_CFG_T sta_cfg;
M2MB_STATUS_T return_status = m2mb_json_decode( encoded_str,
encoded_str + strlen(encoded_str),
(M2MB_JSON_COMPLEX_OBJ_T *)&json_sta_wlan_schema,
( UINT8* )&sta_cfg );

◆ m2mb_json_encode()

M2MB_STATUS_T m2mb_json_encode ( M2MB_JSON_COMPLEX_OBJ_T jsonSchema,
UINT8 usrStruct,
UINT8 jsonFileBuffer,
UINT32  jsonFileBufferSize,
UINT32 lenOfJsonWritten 
)

Encode API for JSON module.

This function create the Json file from the data structure and the Json schema.

Parameters
[in]jsonSchema
[in]usrStructThe user structure which holds all data to be encoded.
[in]jsonFileBufferThe user buffer which will be filled with the Json file.
[in]jsonFileBufferSizeTotal Size of the user buffer.
[in]lenOfJsonWrittenSize of the user buffer filled with Json file.
Returns
M2MB_OK – when json encode was successful M2MB_ERROR – when json encode failed
Note
<Notes>

Example

typedef struct M2M_WLAN_STA_CFG_S
{
UINT8 enable;
UINT8 ssid[33];
UINT8 pwd[65];
}M2M_WLAN_STA_CFG_T;
const M2MB_JSON_OBJ_T json_sta_enable_in =
{
"enable",
1,
offsetof(M2M_WLAN_STA_CFG_T, enable),
sizeof( UINT8 )
};
const M2MB_JSON_OBJ_T json_sta_wlan_ssid_in =
{
"ssid",
1,
offsetof(M2M_WLAN_STA_CFG_T, ssid),
33
};
const M2MB_JSON_OBJ_T json_sta_wlan_pwd_in =
{
"pwd",
1,
offsetof(M2M_WLAN_STA_CFG_T, pwd),
65
};
const M2MB_JSON_OBJ_T* json_sta_wlan_input[] = {
( const M2MB_JSON_OBJ_T* )&json_sta_enable_in,
( const M2MB_JSON_OBJ_T* )&json_sta_wlan_ssid_in,
( const M2MB_JSON_OBJ_T* )&json_sta_wlan_pwd_in,
};
const M2MB_JSON_COMPLEX_OBJ_T json_sta_wlan_schema = {
"sta",
1,
offsetof( M2MB_STA_CFG_T, pWlan ),
sizeof( M2M_WLAN_STA_CFG_T ),
{
sizeof(json_sta_wlan_input)/sizeof(M2MB_JSON_OBJ_T*),
json_sta_wlan_input
}
};
static UINT8 encoded_str[1024];
M2M_WLAN_STA_CFG_T sta_cfg;
UINT8 length;
(M2MB_JSON_COMPLEX_OBJ_T *)&json_sta_wlan_schema,
( UINT8* )&sta_cfg, ( UINT8* )encoded_str,
sizeof(encoded_str), ( UINT32* )&length );
encoded_str[length++] = '\0';

◆ m2mb_json_node_get()

UINT16 m2mb_json_node_get ( M2MB_JSON_NODE_T pCNode,
UINT8 pPNStart,
UINT8 pPNEnd 
)

Get node API for JSON module.

This function gets the node details i.e. start and end pointer within the start and end pointer given.

Parameters
[in]pCNodeJson child node details. User has to fill the name of the tag and the API would fill the start and end pointer with in the pPNStart and pPNEnd pointer.
[in]pPNStartThe starting address of the Json file.
[in]pPNEndThe Ending address of the Json file.
Returns
Number of occurrence of the node within the start and end pointer.
Note
<Notes>

Example

const UINT8 encoded_str = "\"sta\": {\"enable\": 1,\"ssid\": \"SSID1\",\"pwd\": \"PWD1\"};"
UINT16 nu_of_occ = m2mb_json_node_get( &pCNode, encoded_str,
encoded_str + strlen(encoded_str));

◆ m2mb_json_node_occ_get()

UINT16 m2mb_json_node_occ_get ( UINT8 pTName,
UINT8 pPNStart,
UINT8 pPNEnd 
)

Occurrence of node present API for JSON module.

This function finds the occurrence of a tag within the start and end pointer given.

Parameters
[in]pTNameName of the tag.
[in]pPNStartThe starting address of the Json file.
[in]pPNEndThe Ending address of the Json file.
Returns
Number of occurrence of the Tag within the start and end pointer.
Note
<Notes>

Example

const UINT8 encoded_str = "\"sta\": {\"enable\": 1,\"ssid\": \"SSID1\",\"pwd\": \"PWD1\"};"
UINT16 nu_of_occ = m2mb_json_node_get( "sta", encoded_str,
encoded_str + strlen(encoded_str));