Barracuda Application Server C/C++ Reference
NO
|
Universal Binary JSON Reference Manual.
See the UBJSON tutorial for an introduction to using the UBJSON API.
Modules | |
UBJSON Parser Callback | |
UBJSON Parser Callback Interface. | |
Classes | |
struct | UBJVal |
UBJParser Value (passed into the parser callback interface UBJPIntf) More... | |
struct | UBJPStackNode |
The event based parser uses a stack instead of recursion and the UBJPStackNode type represent one entry in the stack. More... | |
struct | UBJPIntf |
The UBJPIntf interface class is the interface between the parser and an object that implements the UBJPIntf interface. More... | |
struct | UBJParser |
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each parsed object/primitive type. More... | |
struct | UBJEBuf |
The UBJSON Encoder buffer is used by the encoder UBJEncoder. More... | |
struct | UBJEncoder |
UBJSON Encoder. More... | |
struct | UBJDecoderStackNode |
Used internally in UBJDecoder for nested data structures. More... | |
struct | UBJDecoderV |
Used internally in UBJDecoder, where one instance represents one node in the pointer value tree. More... | |
struct | UBJDecoder |
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecoder::get is called. More... | |
Macros | |
#define | UBJE_MEMBER(o, m) #m, (o)->m |
UBJEncoder::set helper macro, used when setting a value for an object. More... | |
#define | UBJD_MNUM(o, m) #m, &(o)->m |
JDecoder::get helper macro, used when setting a number pointer in an object. More... | |
#define | UBJD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m) |
JDecoder::get helper macro, used when setting a string pointer in an object. More... | |
#define | UBJD_ASTR(o, m) &(o)->m, sizeof((o)->m) |
JDecoder::get helper macro, used when setting a string pointer in an array. More... | |
Typedefs | |
typedef int(* | UBJPIntf_Service) (struct UBJPIntf *o, UBJVal *v, int recLevel) |
Parser callback function used by interface class UBJPIntf. More... | |
typedef struct UBJPIntf | UBJPIntf |
The UBJPIntf interface class is the interface between the parser and an object that implements the UBJPIntf interface. More... | |
typedef struct UBJParser | UBJParser |
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each parsed object/primitive type. More... | |
typedef int(* | UBJEBuf_FlushCB) (struct UBJEBuf *o, int sizeRequired) |
UBJSON Encoder buffer callback can be used for flushing the buffer or for expanding the buffer. More... | |
typedef struct UBJEBuf | UBJEBuf |
The UBJSON Encoder buffer is used by the encoder UBJEncoder. | |
typedef struct UBJEncoder | UBJEncoder |
UBJSON Encoder. More... | |
typedef UBJDecoder | UBJDecoder |
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecoder::get is called. More... | |
Functions | |
UBJPIntf::UBJPIntf (UBJPIntf_Service s) | |
Create the callback interface object. More... | |
UBJParser::UBJParser (UBJPIntf *intf, char *name, int memberNameLen, int extraStackLen=0) | |
Create the callback interface object. More... | |
UBJParser::~UBJParser () | |
Destructor. | |
int | UBJParser::parse (const U8 *buf, U32 size) |
Parse a UBJSON chunk. More... | |
int | UBJParser::getIndex () |
Returns the current container index position when parsing an optimized container. | |
int | UBJParser::getCount () |
Returns the length of the optimized container when type (t) is UBJT_Count. | |
int | UBJParser::getStatus () |
Returns the parser status. More... | |
UBJEBuf::UBJEBuf (UBJEBuf_FlushCB cb, U8 *buf, S32 bufLen) | |
Initialize the UBJSON Encoder buffer. More... | |
UBJEncoder::UBJEncoder (UBJEBuf *buf) | |
Create/initialize an UBJEncoder instance. More... | |
UBJEncoder::~UBJEncoder () | |
Destructor. | |
int | UBJEncoder::setName (const char *n) |
Set member name. More... | |
int | UBJEncoder::null () |
Set UBJSON NULL. | |
int | UBJEncoder::boolean (bool b) |
Set boolean. | |
int | UBJEncoder::uint8 (U8 v) |
Set uint8. | |
int | UBJEncoder::int8 (S8 v) |
Set int8. | |
int | UBJEncoder::character (char v) |
Set 'char'. | |
int | UBJEncoder::int16 (S16 v) |
Set int16. | |
int | UBJEncoder::int32 (S32 v) |
Set int32. | |
int | UBJEncoder::int64 (S64 v) |
Set int64. | |
int | UBJEncoder::float64 (double v) |
Set float64. | |
int | UBJEncoder::float32 (float v) |
Set float32. | |
int | UBJEncoder::string (const char *s, S32 len) |
Set string. | |
int | UBJEncoder::beginArray (S32 count=-1, UBJT type=UBJT_InvalidType) |
Begin formatting an array. More... | |
int | UBJEncoder::beginObject (S32 count=-1, UBJT type=UBJT_InvalidType) |
Begin formatting an object. More... | |
int | UBJEncoder::endArray () |
End of array. | |
int | UBJEncoder::endObject () |
End of object. | |
void | UBJEncoder::reset () |
Resets the UBJEBuf cursor (the buffer provided in the constructor) | |
int | UBJEncoder::vset (const char **fmt, va_list *argList, bool isObj) |
See UBJEncoder:set for details. | |
int | UBJEncoder::set (const char *fmt,...) |
Encode/serialize C structs/data to UBJSON using formatted output. More... | |
int | UBJDecoder::vget (const char *fmt, va_list *argList) |
See UBJDecoder::get for details. | |
int | UBJDecoder::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... | |
UBJDecoder::UBJDecoder (U8 *buf, int bufSize, int extraStackLen=0) | |
Create/initialize a UBJDecoder instance. More... | |
#define UBJD_ASTR | ( | o, | |
m | |||
) | &(o)->m, sizeof((o)->m) |
JDecoder::get helper macro, used when setting a string pointer in an array.
encoder.set("[s]", UBJD_ASTR(structval, membername));
#define UBJD_MNUM | ( | o, | |
m | |||
) | #m, &(o)->m |
JDecoder::get helper macro, used when setting a number pointer in an object.
encoder.set("{d}", UBJD_MNUM(structval, membername));
#define UBJD_MSTR | ( | o, | |
m | |||
) | #m, &(o)->m, sizeof((o)->m) |
JDecoder::get helper macro, used when setting a string pointer in an object.
encoder.set("{s}", UBJD_MSTR(structval, membername));
#define UBJE_MEMBER | ( | o, | |
m | |||
) | #m, (o)->m |
UBJEncoder::set helper macro, used when setting a value for an object.
encoder.set("{d}", UBJE_MEMBER(structval, membername));
typedef UBJDecoder UBJDecoder |
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecoder::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 UBJDecoder.
typedef int(* UBJEBuf_FlushCB) (struct UBJEBuf *o, int sizeRequired) |
UBJSON Encoder buffer callback can be used for flushing the buffer or for expanding the buffer.
The callback must set the cursor position to zero if the buffer is flushed.
o | UBJEBuf |
sizeRequired | is the extra size required by the buffer (if expanding the buffer). |
typedef struct UBJEncoder UBJEncoder |
UBJSON Encoder.
The encoder performs limited error checking and you can produce incorrect UBJSON data if you incorrectly use the methods in this class.
The UBJPIntf interface class is the interface between the parser and an object that implements the UBJPIntf interface.
Parser callback function used by interface class UBJPIntf.
o | the interface object |
v | the parsed value |
recLevel | goes from 0 to N and represents object nesting level |
enum UBJDecoderS |
UBJDecoder Status Codes.
Enumerator | |
---|---|
UBJDecoderS_FormatErr | Parsed data does not match the value tree that was created when method UBJDecoder::get was called. |
UBJDecoderS_NameNotFound | Parsed data includes a member whose name is not in value tree. |
UBJDecoderS_Overflow | Received more array or object member values from parsed data than found in value tree. |
UBJDecoderS_StringOverflow | Parsed string longer than buffer provided. |
UBJDecoderS_Unbalanced | Incorrect use of '{', '}', '[', or '[' in JDecoder::get. |
UBJDecoderS_Underflow | Received less array or object member values from parsed data than found in value tree. |
UBJDecoderS_Unknown | Unkown error. |
UBJDecoderS_BufNotAligned | Memory buffer(s) provided in UBJDecoder constructor must be word aligned. |
UBJDecoderS_ChainedErr | A chained parser callback, provided via the 'X' format flag in JDecoder::get, reported an error. |
UBJDecoderS_OK | OK, no errors. |
enum UBJEStatus |
UBJSON Encoder status.
enum UBJPStatus |
UBJSON Parser Status.
enum UBJT |
UBJSON Value Type: See UBJVal::t and the UBJSON type reference for more information.
int UBJEncoder::beginArray | ( | S32 | count = -1 , |
UBJT | type = UBJT_InvalidType |
||
) |
Begin formatting an array.
Use the default values for the two parameters, or consult the UBJSON specification, section: Optimized Format.
count | must be set to the number of elements in the array when formatting an optimized array with count or to -1 if not used. |
type | must be set to the type of the optimized array if formatting a strongly typed array, or to UBJT_InvalidType if not used. |
int UBJEncoder::beginObject | ( | S32 | count = -1 , |
UBJT | type = UBJT_InvalidType |
||
) |
Begin formatting an object.
Use the default values for the two parameters, or consult the UBJSON specification, section: Optimized Format.
count | must be set to the number of elements in the object when formatting an optimized object with count or to -1 if not used. |
type | must be set to the type of the optimized object if formatting a strongly typed object, or to UBJT_InvalidType if not used. |
int UBJDecoder::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.
fmt | format flags:
|
See the JSON and UBJSON tutorial for more information on using this method.
int UBJParser::getStatus | ( | ) |
Returns the parser status.
Typically used when method parse returns a value less than zero.
int UBJParser::parse | ( | const U8 * | buf, |
U32 | size | ||
) |
Parse a UBJSON chunk.
buf | a pointer to the UBJSON chunk. |
size | is the buffer length. |
int UBJEncoder::set | ( | const char * | fmt, |
... | |||
) |
Encode/serialize C structs/data to UBJSON using formatted output.
The set method works in a similar fashion to the ANSII C function printf; thus, it performs formatted output conversion.
The method internally uses the 'setXXX' methods in this class for setting the actual value(s), where XXX is uint8, float32, etc.. The following table shows the relationship between the format flags and the UBJSON values:
fmt | format flags:
|
int UBJEncoder::setName | ( | const char * | n | ) |
Set member name.
This function must be called for objects, but must not be called for arrays.
UBJDecoder::UBJDecoder | ( | U8 * | buf, |
int | bufSize, | ||
int | extraStackLen = 0 |
||
) |
Create/initialize a UBJDecoder instance.
buf | is a pointer to a buffer used internally for memory storage when building the pointer value tree. The minimum size must be sizeof(UBJDecoderV) * N, where N is the number of format flags minus the end of array/object flags (] or }). |
bufSize | the size of 'buf' |
extraStackLen | is a non documented value and must be set to 0. |
UBJEBuf::UBJEBuf | ( | UBJEBuf_FlushCB | cb, |
U8 * | buf, | ||
S32 | bufLen | ||
) |
Initialize the UBJSON Encoder buffer.
cb | the expand or flush callback. |
buf | the (initial) encoder buffer |
bufLen | is length of buffer (min 14 bytes) |
UBJEncoder::UBJEncoder | ( | UBJEBuf * | buf | ) |
Create/initialize an UBJEncoder instance.
buf | a buffer that either buffers all produced UBJSON data or small chunks, which are then flushed out to a stream when the buffer is full. |
UBJParser::UBJParser | ( | UBJPIntf * | intf, |
char * | name, | ||
int | memberNameLen, | ||
int | extraStackLen = 0 |
||
) |
Create the callback interface object.
intf | the callback interface object. |
name | is a buffer used for storing an object member name during parsing. |
memberNameLen | is the length of the object member name buffer. The length must be no less than the largest member name expected. |
extraStackLen | informs the parser that it can use a stack larger than the default depth of 3. The memory for the UBJParser object must be constructed as follows: malloc(sizeof(UBJParser) + extraStackLen * sizeof(UBJPStackNode)) |
UBJPIntf::UBJPIntf | ( | UBJPIntf_Service | s | ) |
Create the callback interface object.
s | the parser service callback function. |