|
Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
|
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 | UBJParser_destructor(o) |
| No-op destructor. More... | |
| #define | UBJParser_getIndex(o) (o)->stack[(o)->stackIx].ix |
| Query the current optimized-container position. More... | |
| #define | UBJParser_getCount(o) (o)->stack[(o)->stackIx].count |
| Query the current container's declared count. More... | |
| #define | UBJParser_getStatus(o) (o)->status |
| #define | UBJE_MEMBER(o, m) #m, (o)->m |
| UBJEncoder::set helper macro, used when setting a value for an object. More... | |
| #define | UBJEncoder_constructor(o, ubjsBuf) memset(o,0,sizeof(UBJEncoder)),(o)->buf=ubjsBuf |
| Initialize the encoder; no allocation, flush, or return value. More... | |
| #define | UBJEncoder_destructor(o) |
| No-op; does not flush or free buffers. More... | |
| #define | UBJEncoder_reset(o) ((o)->status=0,(o)->val.name=0,o->buf->cursor=0,0) |
| Discard buffered bytes and clear status/name. More... | |
| #define | UBJEncoder_setName(o, v) ((o)->val.name=(char*)v) |
| Set the pending member name. More... | |
| #define | UBJEncoder_null(o) ((o)->val.t=UBJT_Null,UBJEncoder_val(o)) |
| Encode null. More... | |
| #define | UBJEncoder_boolean(o, v) ((o)->val.t=UBJT_Boolean,(o)->val.u.uint8=v,UBJEncoder_val(o)) |
| Encode a boolean. More... | |
| #define | UBJEncoder_uint8(o, v) ((o)->val.t=UBJT_Uint8,(o)->val.u.uint8=v,UBJEncoder_val(o)) |
| Encode a U8 value. More... | |
| #define | UBJEncoder_int8(o, v) ((o)->val.t=UBJT_Int8,(o)->val.u.int8=v,UBJEncoder_val(o)) |
| Encode a S8 value. More... | |
| #define | UBJEncoder_character(o, v) ((o)->val.t=UBJT_Char,(o)->val.u.int8=v,UBJEncoder_val(o)) |
| Encode a char value. More... | |
| #define | UBJEncoder_int16(o, v) ((o)->val.t=UBJT_Int16,(o)->val.u.int16=v,UBJEncoder_val(o)) |
| Encode a S16 value. More... | |
| #define | UBJEncoder_int32(o, v) ((o)->val.t=UBJT_Int32,(o)->val.u.int32=v,UBJEncoder_val(o)) |
| Encode a S32 value. More... | |
| #define | UBJEncoder_int64(o, v) ((o)->val.t=UBJT_Int64,(o)->val.u.int64=v,UBJEncoder_val(o)) |
| Encode a S64 value. More... | |
| #define | UBJEncoder_float64(o, v) ((o)->val.t=UBJT_Float64,(o)->val.u.float64=v,UBJEncoder_val(o)) |
| Encode a double value. More... | |
| #define | UBJEncoder_float32(o, v) ((o)->val.t=UBJT_Float32,(o)->val.u.float32=v,UBJEncoder_val(o)) |
| Encode a float value. More... | |
| #define | UBJEncoder_string(o, v, l) ((o)->val.t=UBJT_String,(o)->val.u.string=v,(o)->val.len=l,UBJEncoder_val(o)) |
| Encode string bytes without requiring NUL termination. More... | |
| #define | UBJEncoder_beginArray(o, count, sType) |
| Begin an array; emit exactly count children when count is nonnegative. More... | |
| #define | UBJEncoder_beginObject(o, count, sType) |
| Begin an object; emit exactly count named members when count is nonnegative. More... | |
| #define | UBJEncoder_endArray(o) ((o)->val.t=UBJT_EndArray,UBJEncoder_val(o)) |
| End the current array. More... | |
| #define | UBJEncoder_endObject(o) ((o)->val.t=UBJT_EndObject,UBJEncoder_val(o)) |
| End the current object. More... | |
| #define | UBJD_MNUM(o, m) #m, &(o)->m |
| UBJDecoder::get helper macro, used when setting a number pointer in an object. More... | |
| #define | UBJD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m) |
| UBJDecoder::get helper macro, used when setting a string pointer in an object. More... | |
| #define | UBJD_ASTR(o, m) &(o)->m, sizeof((o)->m) |
| UBJDecoder::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) |
| Receive a parsed UBJSON event synchronously. 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) |
| Make room in an encoder buffer by flushing or expanding it. More... | |
| typedef struct UBJEBuf | UBJEBuf |
| The UBJSON Encoder buffer is used by the encoder UBJEncoder. More... | |
| 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 | |
| void | UBJVal_setMinInteger (UBJVal *o, S64 in) |
| Choose the smallest supported integer representation. More... | |
| void | UBJParser_constructor (UBJParser *o, UBJPIntf *intf, char *name, int memberNameLen, int extraStackLen) |
| Create the callback interface object. More... | |
| int | UBJParser_parse (UBJParser *o, const U8 *buf, U32 size) |
| Feed or resume parsing a top-level UBJSON object/array. More... | |
| int | UBJEncoder_vset (UBJEncoder *o, const char **fmt, va_list *argList, int isObj) |
| Emit formatted values as for set(), advancing the format cursor. More... | |
| int | UBJEncoder_set (UBJEncoder *o, const char *fmt,...) |
| Encode/serialize C structs/data to UBJSON using formatted output. More... | |
| int | UBJDecoder_vget (UBJDecoder *o, const char *fmt, va_list *argList) |
| Build the schema using a va_list; see UBJDecoder::get for format rules. More... | |
| int | UBJDecoder_get (UBJDecoder *o, const char *fmt,...) |
| Build a pointer value tree that is used by the integrated parser callback function when the parser feeds elements to the UBJDecoder instance. More... | |
| void | UBJDecoder_constructor (UBJDecoder *o, U8 *buf, int bufSize, int extraStackLen) |
| Create/initialize a UBJDecoder instance. More... | |
| 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 () | |
| No-op destructor. More... | |
| int | UBJParser::parse (const U8 *buf, U32 size) |
| Feed or resume parsing a top-level UBJSON object/array. More... | |
| int | UBJParser::getIndex () |
| Query the current optimized-container position. More... | |
| int | UBJParser::getCount () |
| Query the current container's declared count. More... | |
| int | UBJParser::getStatus () |
| UBJEBuf::UBJEBuf (UBJEBuf_FlushCB cb, U8 *buf, S32 bufLen) | |
| Initialize the UBJSON Encoder buffer. More... | |
| UBJEBuf::~UBJEBuf () | |
| No-op destructor; neither flushes nor frees application buffer storage. More... | |
| UBJEncoder::UBJEncoder (UBJEBuf *buf) | |
| Create/initialize an UBJEncoder instance. More... | |
| UBJEncoder::~UBJEncoder () | |
| No-op destructor; does not flush output or free the borrowed buffer. More... | |
| int | UBJEncoder::setName (const char *n) |
| Store a name for the next object value; do not use for array elements. More... | |
| int | UBJEncoder::null () |
| Emit UBJSON null. More... | |
| int | UBJEncoder::boolean (bool b) |
| Emit one boolean value. More... | |
| int | UBJEncoder::uint8 (U8 v) |
| Emit one uint8 value. More... | |
| int | UBJEncoder::int8 (S8 v) |
| Emit one int8 value. More... | |
| int | UBJEncoder::character (char v) |
| Emit one character value. More... | |
| int | UBJEncoder::int16 (S16 v) |
| Emit one int16 value. More... | |
| int | UBJEncoder::int32 (S32 v) |
| Emit one int32 value. More... | |
| int | UBJEncoder::int64 (S64 v) |
| Emit one int64 value. More... | |
| int | UBJEncoder::float64 (double v) |
| Emit one float64 value. More... | |
| int | UBJEncoder::float32 (float v) |
| Emit one float32 value. More... | |
| int | UBJEncoder::string (const char *s, S32 len) |
| Emit a length-delimited string. More... | |
| 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 () |
| Close the matching current container. More... | |
| int | UBJEncoder::endObject () |
| Close the matching current container. More... | |
| void | UBJEncoder::reset () |
| Discard buffered bytes and clear status and the pending member name. More... | |
| int | UBJEncoder::vset (const char **fmt, va_list *argList, bool isObj) |
| Emit formatted values as for set(), advancing the format cursor. More... | |
| 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. More... | |
| 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 UBJDecoder 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) |
UBJDecoder::get helper macro, used when setting a string pointer in an array.
decoder.get("[S]", UBJD_ASTR(structval, membername));
| #define UBJD_MNUM | ( | o, | |
| m | |||
| ) | #m, &(o)->m |
UBJDecoder::get helper macro, used when setting a number pointer in an object.
decoder.get("{l}", UBJD_MNUM(structval, membername));
| #define UBJD_MSTR | ( | o, | |
| m | |||
| ) | #m, &(o)->m, sizeof((o)->m) |
UBJDecoder::get helper macro, used when setting a string pointer in an object.
decoder.get("{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));
| #define UBJEncoder_beginArray | ( | o, | |
| count, | |||
| sType | |||
| ) |
Begin an array; emit exactly count children when count is nonnegative.
| o | Required initialized encoder. |
| count | Number of children, or -1 for an uncounted array. |
| sType | Strong element type, or UBJT_InvalidType for mixed types. |
| #define UBJEncoder_beginObject | ( | o, | |
| count, | |||
| sType | |||
| ) |
Begin an object; emit exactly count named members when count is nonnegative.
| o | Required initialized encoder. |
| count | Number of members, or -1 for an uncounted object. |
| sType | Strong member-value type, or UBJT_InvalidType for mixed types. |
| #define UBJEncoder_boolean | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Boolean,(o)->val.u.uint8=v,UBJEncoder_val(o)) |
Encode a boolean.
| o | Required initialized encoder. |
| v | Boolean value; zero false, nonzero true. |
| #define UBJEncoder_character | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Char,(o)->val.u.int8=v,UBJEncoder_val(o)) |
Encode a char value.
| o | Required initialized encoder. |
| v | Value representable in char. |
| #define UBJEncoder_constructor | ( | o, | |
| ubjsBuf | |||
| ) | memset(o,0,sizeof(UBJEncoder)),(o)->buf=ubjsBuf |
Initialize the encoder; no allocation, flush, or return value.
| o | Required encoder storage. |
| ubjsBuf | Required borrowed initialized UBJEBuf. |
| #define UBJEncoder_destructor | ( | o | ) |
No-op; does not flush or free buffers.
| o | Required initialized encoder. |
| #define UBJEncoder_endArray | ( | o | ) | ((o)->val.t=UBJT_EndArray,UBJEncoder_val(o)) |
End the current array.
| o | Required initialized encoder. |
| #define UBJEncoder_endObject | ( | o | ) | ((o)->val.t=UBJT_EndObject,UBJEncoder_val(o)) |
End the current object.
| o | Required initialized encoder. |
| #define UBJEncoder_float32 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Float32,(o)->val.u.float32=v,UBJEncoder_val(o)) |
Encode a float value.
| o | Required initialized encoder. |
| v | Value representable in float. |
| #define UBJEncoder_float64 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Float64,(o)->val.u.float64=v,UBJEncoder_val(o)) |
Encode a double value.
| o | Required initialized encoder. |
| v | Value representable in double. |
| #define UBJEncoder_int16 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Int16,(o)->val.u.int16=v,UBJEncoder_val(o)) |
Encode a S16 value.
| o | Required initialized encoder. |
| v | Value representable in S16. |
| #define UBJEncoder_int32 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Int32,(o)->val.u.int32=v,UBJEncoder_val(o)) |
Encode a S32 value.
| o | Required initialized encoder. |
| v | Value representable in S32. |
| #define UBJEncoder_int64 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Int64,(o)->val.u.int64=v,UBJEncoder_val(o)) |
Encode a S64 value.
| o | Required initialized encoder. |
| v | Value representable in S64. |
| #define UBJEncoder_int8 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Int8,(o)->val.u.int8=v,UBJEncoder_val(o)) |
Encode a S8 value.
| o | Required initialized encoder. |
| v | Value representable in S8. |
| #define UBJEncoder_null | ( | o | ) | ((o)->val.t=UBJT_Null,UBJEncoder_val(o)) |
Encode null.
| o | Required initialized encoder. |
| #define UBJEncoder_reset | ( | o | ) | ((o)->status=0,(o)->val.name=0,o->buf->cursor=0,0) |
Discard buffered bytes and clear status/name.
Nesting state is not reset. Returns 0.
| o | Required initialized encoder. |
| #define UBJEncoder_setName | ( | o, | |
| v | |||
| ) | ((o)->val.name=(char*)v) |
Set the pending member name.
Returns the assigned char pointer (not a status).
| o | Required initialized encoder. |
| v | Borrowed nonempty NUL-terminated member name, valid until the next value. Embedded NUL bytes are unsupported. An empty name is rejected by the next value operation with UBJEStatus_EmptyName. |
| #define UBJEncoder_string | ( | o, | |
| v, | |||
| l | |||
| ) | ((o)->val.t=UBJT_String,(o)->val.u.string=v,(o)->val.len=l,UBJEncoder_val(o)) |
Encode string bytes without requiring NUL termination.
| o | Required initialized encoder. |
| v | Required readable string bytes, borrowed for the call. |
| l | Nonnegative byte count, excluding any optional NUL. |
| #define UBJEncoder_uint8 | ( | o, | |
| v | |||
| ) | ((o)->val.t=UBJT_Uint8,(o)->val.u.uint8=v,UBJEncoder_val(o)) |
Encode a U8 value.
| o | Required initialized encoder. |
| v | Value representable in U8. |
| #define UBJParser_destructor | ( | o | ) |
No-op destructor.
Input, name storage, and callback interface are borrowed and never freed by the parser. Stop using the parser before releasing them.
| o | Required initialized parser. |
| #define UBJParser_getCount | ( | o | ) | (o)->stack[(o)->stackIx].count |
Query the current container's declared count.
| o | Required initialized parser. |
| #define UBJParser_getIndex | ( | o | ) | (o)->stack[(o)->stackIx].ix |
Query the current optimized-container position.
| o | Required initialized parser. |
| #define UBJParser_getStatus | ( | o | ) | (o)->status |
| o | Required initialized parser. |
| 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.
The UBJSON Encoder buffer is used by the encoder UBJEncoder.
| typedef int(* UBJEBuf_FlushCB) (struct UBJEBuf *o, int sizeRequired) |
Make room in an encoder buffer by flushing or expanding it.
| o | Required borrowed buffer object. Preserve unflushed bytes when growing. After flushing, reset cursor to zero; when growing, update data and dlen. |
| sizeRequired | Additional capacity requested in bytes. |
| typedef struct UBJEncoder UBJEncoder |
UBJSON Encoder.
The encoder performs limited error checking and you can produce incorrect UBJSON data if used incorrectly. Supply matching containers and exact optimized counts. Output is incremental, and an error can leave partial data. Final buffered bytes must be consumed/flushed by the application; the destructor does not flush. The current implementation has not been verified against the complete UBJSON specification. Supply UTF-8 strings and nonempty member names without embedded NUL bytes. UTF-8 is not validated. Empty member names return UBJEStatus_EmptyName. Native floating-point values must be finite; the caller must explicitly encode null for nonfinite values. H numeric text must follow JSON number syntax; the encoder does not validate that syntax.
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each parsed object/primitive type.
Only object/array roots are supported. String payloads must be UTF-8; the parser does not validate this encoding. High-precision H values are delivered as raw text for the application to interpret or reject.
The UBJPIntf interface class is the interface between the parser and an object that implements the UBJPIntf interface.
Receive a parsed UBJSON event synchronously.
| o | Required callback interface. |
| v | Borrowed value event; inspect t before its union. Strings/HNumber are delivered in chunks: len is this chunk's bytes and x is bytes remaining. Neither chunk data nor member-name storage may be retained without copying. |
| recLevel | Top-level begin/end depth is zero; primitive children use one greater than their containing level. Count events use the container 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 | Unconsumed schema values remain when a container ends; also used for excessive schema nesting. |
| UBJDecoderS_StringOverflow | Parsed string longer than buffer provided. |
| UBJDecoderS_Unbalanced | Incorrect use of '{', '}', '[', or ']' in UBJDecoder::get. |
| UBJDecoderS_Underflow | Input supplies another value after all schema children were consumed. |
| UBJDecoderS_Unknown | Unknown 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 UBJDecoder::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 UBJEncoder::boolean | ( | bool | b | ) |
Emit one boolean value.
| b | Value copied into output. |
| int UBJEncoder::character | ( | char | v | ) |
Emit one character value.
| v | Value copied into output. Supply a protocol-valid single-byte character. |
| int UBJEncoder::endArray | ( | ) |
Close the matching current container.
A counted container omits its end marker from the wire, but this call is still required for encoder state.
| int UBJEncoder::endObject | ( | ) |
Close the matching current container.
A counted container omits its end marker from the wire, but this call is still required for encoder state.
| int UBJEncoder::float32 | ( | float | v | ) |
Emit one float32 value.
| v | Value copied into output. Requires floating-point support. |
| int UBJEncoder::float64 | ( | double | v | ) |
Emit one float64 value.
| v | Value copied into output. Requires floating-point support. |
| 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 UBJDecoder instance.
| fmt | format flags:
|
See the JSON and UBJSON tutorial for more information on using this method.
| int UBJParser::getCount | ( | ) |
Query the current container's declared count.
| int UBJParser::getIndex | ( | ) |
Query the current optimized-container position.
| int UBJParser::getStatus | ( | ) |
| int UBJEncoder::int16 | ( | S16 | v | ) |
Emit one int16 value.
| v | Value copied into output. |
| int UBJEncoder::int32 | ( | S32 | v | ) |
Emit one int32 value.
| v | Value copied into output. |
| int UBJEncoder::int64 | ( | S64 | v | ) |
Emit one int64 value.
| v | Value copied into output. |
| int UBJEncoder::int8 | ( | S8 | v | ) |
Emit one int8 value.
| v | Value copied into output. |
| int UBJEncoder::null | ( | ) |
Emit UBJSON null.
Feed or resume parsing a top-level UBJSON object/array.
| buf | Borrowed binary input chunk. Supply new input after DoneEOS or NeedMoreData. After Done, this argument is ignored while the parser consumes unread bytes retained from the previous chunk; keep that storage valid. |
| size | New chunk byte count, ignored during continuation after Done. |
| void UBJEncoder::reset | ( | ) |
Discard buffered bytes and clear status and the pending member name.
This does not flush output or reset nesting/strongly-typed state. Use only after a balanced complete value. Reinitialize to recover from a partial container.
| 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 ANSI 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 | ) |
Store a name for the next object value; do not use for array elements.
| n | Borrowed NUL-terminated name retained until the next value is emitted. |
| int UBJEncoder::string | ( | const char * | s, |
| S32 | len | ||
| ) |
Emit a length-delimited string.
| s | Readable UTF-8 bytes borrowed for this call, required for positive len. |
| len | Nonnegative byte count, excluding a terminator. The encoder does not validate UTF-8. Embedded NUL bytes are included. |
| 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 greater than sizeof(UBJDecoderV) * N, where N is the number of format flags minus the end of array/object flags (] or }). |
| bufSize | Positive byte capacity. buf must be aligned to sizeof(UBJ_ALIGNMT) and retained through parsing. Keep byte offsets representable in U16. This storage does not grow. |
| extraStackLen | is an undocumented value and must be set to 0. |
| void UBJDecoder_constructor | ( | UBJDecoder * | o, |
| U8 * | buf, | ||
| int | bufSize, | ||
| int | extraStackLen | ||
| ) |
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 greater than sizeof(UBJDecoderV) * N, where N is the number of format flags minus the end of array/object flags (] or }). |
| bufSize | Positive byte capacity. buf must be aligned to sizeof(UBJ_ALIGNMT) and retained through parsing. Keep byte offsets representable in U16. This storage does not grow. |
| extraStackLen | is an undocumented value and must be set to 0. |
| o | Required storage to initialize. |
| int UBJDecoder_get | ( | UBJDecoder * | o, |
| const char * | fmt, | ||
| ... | |||
| ) |
Build a pointer value tree that is used by the integrated parser callback function when the parser feeds elements to the UBJDecoder instance.
| fmt | format flags:
|
See the JSON and UBJSON tutorial for more information on using this method.
| o | Required initialized decoder. |
| int UBJDecoder_vget | ( | UBJDecoder * | o, |
| const char * | fmt, | ||
| va_list * | argList | ||
| ) |
Build the schema using a va_list; see UBJDecoder::get for format rules.
| o | Required initialized decoder. |
| fmt | Required NUL-terminated schema format. |
| argList | Required pointer to a va_list matching fmt; consumed by the call. |
| UBJEBuf::UBJEBuf | ( | UBJEBuf_FlushCB | cb, |
| U8 * | buf, | ||
| S32 | bufLen | ||
| ) |
Initialize the UBJSON Encoder buffer.
| cb | Required expansion/flush callback; remains callable while used. |
| buf | Required borrowed writable encoder buffer, retained while used. |
| bufLen | Positive buffer capacity in bytes, at least 14. No storage is allocated and the initial cursor is zero. |
| 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. Required borrowed initialized UBJEBuf, which must outlive the encoder. |
| int UBJEncoder_set | ( | UBJEncoder * | o, |
| const char * | fmt, | ||
| ... | |||
| ) |
Encode/serialize C structs/data to UBJSON using formatted output.
The set method works in a similar fashion to the ANSI 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:
|
| o | Required initialized encoder. |
| int UBJEncoder_vset | ( | UBJEncoder * | o, |
| const char ** | fmt, | ||
| va_list * | argList, | ||
| int | isObj | ||
| ) |
Emit formatted values as for set(), advancing the format cursor.
| fmt | Required pointer to a NUL-terminated format cursor. |
| argList | Required pointer to a matching initialized va_list, consumed. |
| isObj | True consumes a member-name argument before each value; false emits unnamed values. Use the matching container context. |
| o | Required initialized encoder. |
| UBJParser::UBJParser | ( | UBJPIntf * | intf, |
| char * | name, | ||
| int | memberNameLen, | ||
| int | extraStackLen = 0 |
||
| ) |
Create the callback interface object.
| intf | Required borrowed interface with a non-NULL callback. |
| name | is a buffer used for storing an object member name during parsing. Required writable storage retained for the parser lifetime. |
| memberNameLen | is the length of the object member name buffer. The length must be no less than the largest member name expected, plus one byte for its NUL terminator. Empty member names are rejected. Names containing NUL bytes are unsupported. |
| extraStackLen | informs the parser that it can use a stack larger than the default depth of 3. Use zero for an ordinary object. Positive values require the additional writable storage shown below and must fit the integer stack-length representation. The memory for the UBJParser object must be constructed as follows: malloc(sizeof(UBJParser) + extraStackLen * sizeof(UBJPStackNode)) |
| void UBJParser_constructor | ( | UBJParser * | o, |
| UBJPIntf * | intf, | ||
| char * | name, | ||
| int | memberNameLen, | ||
| int | extraStackLen | ||
| ) |
Create the callback interface object.
| intf | Required borrowed interface with a non-NULL callback. |
| name | is a buffer used for storing an object member name during parsing. Required writable storage retained for the parser lifetime. |
| memberNameLen | is the length of the object member name buffer. The length must be no less than the largest member name expected, plus one byte for its NUL terminator. Empty member names are rejected. Names containing NUL bytes are unsupported. |
| extraStackLen | informs the parser that it can use a stack larger than the default depth of 3. Use zero for an ordinary object. Positive values require the additional writable storage shown below and must fit the integer stack-length representation. The memory for the UBJParser object must be constructed as follows: malloc(sizeof(UBJParser) + extraStackLen * sizeof(UBJPStackNode)) |
| o | Required storage to initialize. |
Feed or resume parsing a top-level UBJSON object/array.
| buf | Borrowed binary input chunk. Supply new input after DoneEOS or NeedMoreData. After Done, this argument is ignored while the parser consumes unread bytes retained from the previous chunk; keep that storage valid. |
| size | New chunk byte count, ignored during continuation after Done. |
| o | Required initialized parser. |
| UBJPIntf::UBJPIntf | ( | UBJPIntf_Service | s | ) |
Create the callback interface object.
| s | Required callback, callable while installed. |
Choose the smallest supported integer representation.
| o | Required output record; sets t and its selected union member only. |
| in | Signed 64-bit input value. Other record fields remain unchanged. |
| int UBJEncoder::uint8 | ( | U8 | v | ) |
Emit one uint8 value.
| v | Value copied into output. |
| int UBJDecoder::vget | ( | const char * | fmt, |
| va_list * | argList | ||
| ) |
See UBJDecoder::get for details.
| int UBJEncoder::vset | ( | const char ** | fmt, |
| va_list * | argList, | ||
| bool | isObj | ||
| ) |
Emit formatted values as for set(), advancing the format cursor.
| fmt | Required pointer to a NUL-terminated format cursor. |
| argList | Required pointer to a matching initialized va_list, consumed. |
| isObj | True consumes a member-name argument before each value; false emits unnamed values. Use the matching container context. |
| UBJEBuf::~UBJEBuf | ( | ) |
No-op destructor; neither flushes nor frees application buffer storage.
| UBJEncoder::~UBJEncoder | ( | ) |
No-op destructor; does not flush output or free the borrowed buffer.
| UBJParser::~UBJParser | ( | ) |
No-op destructor.
Input, name storage, and callback interface are borrowed and never freed by the parser. Stop using the parser before releasing them.