Barracuda Application Server C/C++ Reference
NO
JSON Parser Callback

Detailed Description

JSON Parser Callback Interface.

Collaboration diagram for JSON Parser Callback:

Classes

struct  JParserValFact
 JParserValFact is the JVal JSON parser factory class. More...
 
struct  JParserIntf
 The JParserIntf interface class is the interface between the parser and an object that implements the JParserIntf interface. More...
 
struct  JDecoderStackNode
 Used internally in JDecoder for nested data structures. More...
 
struct  JDecoderV
 Used internally in JDecoder, where one instance represents one node in the pointer value tree. More...
 
struct  JDecoder
 JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder::get is called. More...
 

Macros

#define JD_MNUM(o, m)   #m, &(o)->m
 JDecoder::get helper macro, used when setting a number pointer in an object. More...
 
#define JD_MSTR(o, m)   #m, &(o)->m, sizeof((o)->m)
 JDecoder::get helper macro, used when setting a string pointer in an object. More...
 
#define JD_ASTR(o, m)   &(o)->m, sizeof((o)->m)
 JDecoder::get helper macro, used when setting a string pointer in an array. More...
 

Typedefs

typedef JParserValFact JParserValFact
 JParserValFact is the JVal JSON parser factory class. More...
 
typedef int(* JParserIntf_Service) (struct JParserIntf *o, struct JParserVal *v, int recLevel)
 The parser callback function. More...
 
typedef struct JParserIntf JParserIntf
 The JParserIntf interface class is the interface between the parser and an object that implements the JParserIntf interface.
 
typedef JDecoder JDecoder
 JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder::get is called. More...
 

Enumerations

enum  JDecoderS {
  JDecoderS_FormatErr = -100 , JDecoderS_NameNotFound , JDecoderS_Overflow , JDecoderS_StringOverflow ,
  JDecoderS_Unbalanced , JDecoderS_Underflow , JDecoderS_Unknown , JDecoderS_BufNotAligned ,
  JDecoderS_ChainedErr , JDecoderS_OK = 0
}
 JDecoder Status. More...
 

Functions

 JParserValFact::JParserValFact (AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
 create a JParserValFact JVal factory instance. More...
 
JValJParserValFact::getFirstVal ()
 Returns the root of the JVal syntax tree.
 
JValJParserValFact::manageFirstVal ()
 Similar to getFirstVal, but you must manage the JVal tree as the value is detached from the JParserValFact.
 
void JParserValFact::termFirstVal ()
 Terminate the syntax tree such that the JParserValFact instance can be reused when the JParser instance parses the next JSON object in a stream.
 
 JParserValFact::~JParserValFact ()
 The destructor terminates all nodes not managed.
 
int JParserIntf::serviceCB (JParserVal *v, int recLevel)
 Calling the JParserIntf service function is typically performed in a design using a chained parser callback interface. More...
 
int JDecoder::vget (const char *fmt, va_list *argList)
 See JDecoder::get for details.
 
int JDecoder::get (const char *fmt,...)
 Build a pointer value tree that is used by the integrated parser callback function when the parser feeds elements to the JDecoder instance. More...
 
 JDecoder::JDecoder (U8 *buf, int bufSize, int extraStackLen=0)
 Create/initialize a JDecoder instance. More...
 

Macro Definition Documentation

◆ JD_ASTR

#define JD_ASTR (   o,
 
)    &(o)->m, sizeof((o)->m)

JDecoder::get helper macro, used when setting a string pointer in an array.

encoder.set("[s]", JD_ASTR(structval, membername));

◆ JD_MNUM

#define JD_MNUM (   o,
 
)    #m, &(o)->m

JDecoder::get helper macro, used when setting a number pointer in an object.

encoder.set("{d}", JD_MNUM(structval, membername));

◆ JD_MSTR

#define JD_MSTR (   o,
 
)    #m, &(o)->m, sizeof((o)->m)

JDecoder::get helper macro, used when setting a string pointer in an object.

encoder.set("{s}", JD_MSTR(structval, membername));

Typedef Documentation

◆ JDecoder

typedef JDecoder JDecoder

JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder::get is called.

The pointer value tree is used by the parser callback when the parser feeds the callback with parsed data.

See the JSON and UBJSON tutorial for more information on using JDecoder.

◆ JParserIntf_Service

typedef int(* JParserIntf_Service) (struct JParserIntf *o, struct JParserVal *v, int recLevel)

The parser callback function.

Parameters
othe interface object
vthe parsed value
recLevelgoes from 0 to N and represents object nesting level

◆ JParserValFact

JParserValFact is the JVal JSON parser factory class.

An instance of this class is connected to an instance of the JParser. The JParser communicates with the JVal factory when parsing JSON, and the JVal factory creates JVal objects.

Method getFirstVal returns the first value in the syntax tree.

The class automatically manages the nodes allocated. The allocated nodes are automatically de-allocated when the destructor runs. You can manage the values by calling JParserValFact::manageFirstVal or by calling JVal::manageJ on any of the children.

See also
JValFact
JDecode

Enumeration Type Documentation

◆ JDecoderS

enum JDecoderS

JDecoder Status.

Enumerator
JDecoderS_FormatErr 

Parsed data does not match the value tree that was created when method JDecoder::get was called.

JDecoderS_NameNotFound 

Parsed data includes a member whose name is not in value tree.

JDecoderS_Overflow 

Received more array or object member values from parsed data than found in value tree.

JDecoderS_StringOverflow 

Parsed string longer than buffer provided.

JDecoderS_Unbalanced 

Incorrect use of '{', '}', '[', or '[' in JDecoder::get.

JDecoderS_Underflow 

Received less array or object member values from parsed data than found in value tree.

JDecoderS_Unknown 

Unkown error.

JDecoderS_BufNotAligned 

Memory buffer(s) provided in JDecoder constructor must be word aligned.

JDecoderS_ChainedErr 

A chained parser callback, provided via the 'X' format flag in JDecoder::get, reported an error.

JDecoderS_OK 

OK, no errors.

Function Documentation

◆ get()

int JDecoder::get ( const char *  fmt,
  ... 
)

Build a pointer value tree that is used by the integrated parser callback function when the parser feeds elements to the JDecoder instance.

Parameters
fmtformat flags:
JSON typeFormat flagC type
Numberd S32*
Numberl S64*
Numberf double*
booleanb BaBool* or U8*
strings char**
Start object{ n/a
End object} n/a
Start array[ n/a
End array] n/a
N/AX JParserIntf*

See the JSON and UBJSON tutorial for more information on using this method.

See also
JD_MNUM
JD_MSTR
JD_ASTR
JEncoder::set

◆ JDecoder()

JDecoder::JDecoder ( U8 *  buf,
int  bufSize,
int  extraStackLen = 0 
)

Create/initialize a JDecoder instance.

Parameters
bufis a pointer to a buffer used internally for memory storage when building the pointer value tree. The minimum size must be sizeof(JDecoderV) * N, where N is the number of format flags minus the end of array/object flags (] or }).
bufSizethe size of 'buf'
extraStackLenis a non documented value and must be set to 0.

◆ JParserValFact()

JParserValFact::JParserValFact ( AllocatorIntf vAlloc,
AllocatorIntf dAlloc 
)

create a JParserValFact JVal factory instance.

Parameters
vAllocis used when allocating nodes.
dAllocis used when allocating strings. The two allocators can be the same.

◆ serviceCB()

int JParserIntf::serviceCB ( JParserVal v,
int  recLevel 
)

Calling the JParserIntf service function is typically performed in a design using a chained parser callback interface.

Parameters
vthe parsed value provided by JParser
recLevelmust be adjusted by the chained callback