le_json.h File Reference
Go to the source code of this file.
Typedefs | |
typedef void(* | le_json_EventHandler_t) (le_json_Event_t event) |
typedef void(* | le_json_ErrorHandler_t) (le_json_Error_t error, const char *msg) |
typedef struct le_json_ParsingSession * | le_json_ParsingSessionRef_t |
Functions | |
LE_FULL_API le_json_ParsingSessionRef_t | le_json_Parse (int fd, le_json_EventHandler_t eventHandler, le_json_ErrorHandler_t errorHandler, void *opaquePtr) |
le_json_ParsingSessionRef_t | le_json_ParseString (const char *jsonString, le_json_EventHandler_t eventHandler, le_json_ErrorHandler_t errorHandler, void *opaquePtr) |
void | le_json_Cleanup (le_json_ParsingSessionRef_t session) |
void | le_json_SetEventHandler (le_json_EventHandler_t callbackFunc) |
le_json_ContextType_t | le_json_GetContextType (void) |
void | le_json_SetOpaquePtr (void *ptr) |
void * | le_json_GetOpaquePtr (void) |
void | le_json_SetErrorHandler (le_json_ErrorHandler_t callbackFunc) |
const char * | le_json_GetString (void) |
double | le_json_GetNumber (void) |
const char * | le_json_GetEventName (le_json_Event_t event) |
const char * | le_json_GetContextName (le_json_ContextType_t context) |
size_t | le_json_GetBytesRead (le_json_ParsingSessionRef_t session) |
le_json_ParsingSessionRef_t | le_json_GetSession (void) |
Detailed Description
Legato JSON Parsing API include file.
Copyright (C) Sierra Wireless Inc.
Typedef Documentation
◆ le_json_ErrorHandler_t
typedef void(* le_json_ErrorHandler_t) (le_json_Error_t error, const char *msg) |
Callbacks for errors look like this.
- Parameters
-
error [in] Indicates what type of error occured. msg [in] Human-readable message describing the error. (Valid until handler returns.)
◆ le_json_EventHandler_t
typedef void(* le_json_EventHandler_t) (le_json_Event_t event) |
Callbacks for (non-error) parsing events look like this.
- Parameters
-
event [in] Indicates what type of event occured.
◆ le_json_ParsingSessionRef_t
typedef struct le_json_ParsingSession* le_json_ParsingSessionRef_t |
Parsing session reference. Refers to a parsing session started by le_json_Parse(). Pass this to le_json_Cleanup() to stop the parsing and clean up memory allocated by the parser.
Enumeration Type Documentation
◆ le_json_ContextType_t
Enumeration of the different types of "contexts" that can exist during a parsing session.
◆ le_json_Error_t
enum le_json_Error_t |
◆ le_json_Event_t
enum le_json_Event_t |
Enumeration of all the different events that can be reported during JSON document parsing.
Enumerator | |
---|---|
LE_JSON_OBJECT_START | object started, subsequent object members are part of this object |
LE_JSON_OBJECT_MEMBER | object member name received: Call le_json_GetString() to get name |
LE_JSON_OBJECT_END | object finished, subsequent members/values are outside this object |
LE_JSON_ARRAY_START | array started, upcoming values are elements of this array |
LE_JSON_ARRAY_END | array finished, subsequent values are outside this array |
LE_JSON_STRING | string value received: call le_json_GetString() to get value |
LE_JSON_NUMBER | number value received: call le_json_GetNumber() to get value |
LE_JSON_TRUE | true value received |
LE_JSON_FALSE | false value received |
LE_JSON_NULL | null value received |
LE_JSON_DOC_END | End of the document reached. Parsing has stopped. |
Function Documentation
◆ le_json_Cleanup()
void le_json_Cleanup | ( | le_json_ParsingSessionRef_t | session | ) |
Stops parsing and cleans up memory allocated by the parser.
- Warning
- Be sure to stop parsing before closing the file descriptor.
- Parameters
-
session The parsing session to clean up (see le_json_Parse()).
◆ le_json_GetBytesRead()
size_t le_json_GetBytesRead | ( | le_json_ParsingSessionRef_t | session | ) |
- Returns
- The number of bytes that have been read from the input stream so far.
- Parameters
-
session Parsing session.
◆ le_json_GetContextName()
const char* le_json_GetContextName | ( | le_json_ContextType_t | context | ) |
- Returns
- Human readable string containing the name of a given JSON parsing context.
◆ le_json_GetContextType()
le_json_ContextType_t le_json_GetContextType | ( | void | ) |
Get the type of parsing context that the parser is currently in.
- Returns
- The context type.
- Warning
- This function can only be called inside event or error handlers.
◆ le_json_GetEventName()
const char* le_json_GetEventName | ( | le_json_Event_t | event | ) |
- Returns
- Human readable string containing the name of a given JSON parsing event.
◆ le_json_GetNumber()
double le_json_GetNumber | ( | void | ) |
Fetches the value of a parsed number.
- Warning
- This function can only be called inside event handlers when LE_JSON_NUMBER events are being handled.
◆ le_json_GetOpaquePtr()
void* le_json_GetOpaquePtr | ( | void | ) |
Get the opaque pointer attached to the parser.
- Returns
- The pointer previously set by le_json_Parse() or a subsequent call to le_json_SetOpaquePtr().
- Warning
- This function can only be called inside event or error handlers.
◆ le_json_GetSession()
le_json_ParsingSessionRef_t le_json_GetSession | ( | void | ) |
For use by an event handler or error handler to fetch the JSON parsing session reference for the session that called its handler function.
- Returns
- The session reference of the JSON parsing session.
- Warning
- This function can only be called inside event or error handlers.
◆ le_json_GetString()
const char* le_json_GetString | ( | void | ) |
Fetches a pointer to a string value or object member name.
This pointer is only valid until the event handler returns.
- Warning
- This function can only be called inside event handlers when LE_JSON_OBJECT_MEMBER or LE_JSON_STRING events are being handled.
◆ le_json_Parse()
LE_FULL_API le_json_ParsingSessionRef_t le_json_Parse | ( | int | fd, |
le_json_EventHandler_t | eventHandler, | ||
le_json_ErrorHandler_t | errorHandler, | ||
void * | opaquePtr | ||
) |
Parse a JSON document received via a file descriptor.
- Returns
- Reference to the JSON parsing session started by this function call.
- Parameters
-
fd File descriptor to read the JSON document from. eventHandler Function to call when normal parsing events happen. errorHandler Function to call when errors happen. opaquePtr Opaque pointer to be fetched by handlers using le_json_GetOpaquePtr().
◆ le_json_ParseString()
le_json_ParsingSessionRef_t le_json_ParseString | ( | const char * | jsonString, |
le_json_EventHandler_t | eventHandler, | ||
le_json_ErrorHandler_t | errorHandler, | ||
void * | opaquePtr | ||
) |
Parse a JSON document received via C string.
- Returns
- Reference to the JSON parsing session started by this function call.
- Parameters
-
jsonString JSON string to parse. eventHandler Function to call when normal parsing events happen. errorHandler Function to call when errors happen. opaquePtr Opaque pointer to be fetched by handlers using le_json_GetOpaquePtr().
◆ le_json_SetErrorHandler()
void le_json_SetErrorHandler | ( | le_json_ErrorHandler_t | callbackFunc | ) |
Set the error handler function
- Warning
- This function can only be called inside event or error handlers.
- Parameters
-
callbackFunc Function to call when parsing errors happen.
◆ le_json_SetEventHandler()
void le_json_SetEventHandler | ( | le_json_EventHandler_t | callbackFunc | ) |
Set the current context's event handler function.
- Warning
- This function can only be called inside event or error handlers.
- Parameters
-
callbackFunc Function to call when parsing events happen.
◆ le_json_SetOpaquePtr()
void le_json_SetOpaquePtr | ( | void * | ptr | ) |
Set the opaque pointer attached to the parser.
- Warning
- This function can only be called inside event or error handlers.
- Parameters
-
ptr Opaque pointer to be fetched using le_json_GetOpaquePtr().