46#include <TargConfig.h>
55#define UBJ_ALIGNMT uintptr_t
57#define UBJ_POINTER_NOT_ALIGNED(p) \
58 (0 != ((uintptr_t)p & (sizeof(UBJ_ALIGNMT) - 1)))
61#define UBJPARS_STACK_LEN 3
213#define UBJPIntf_constructor(o,serviceMA) (o)->service=serviceMA
214#define UBJPIntf_destructor(o)
215#define UBJPIntf_service(o,v,recLev) (o)->service(o,v,recLev)
219 UBJPIntf_constructor(
this, s);
221inline UBJPIntf::~UBJPIntf() {
222 UBJPIntf_destructor(
this);
298 const U8* lxTokenPtr;
321 int memberNameLen,
int extraStackLen);
325#define UBJParser_destructor(o)
333#define UBJParser_getIndex(o) (o)->stack[(o)->stackIx].ix
337#define UBJParser_getCount(o) (o)->stack[(o)->stackIx].count
341#define UBJParser_getStatus(o) (o)->status
345 UBJPIntf* intf,
char* name,
int memberNameLen,
int extraStackLen) {
398#define UBJEBuf_constructor(o, flushCBM, dataM, dlenM) \
399 (o)->flushCB=flushCBM,(o)->data=dataM,(o)->dlen=dlenM,(o)->cursor=0
400#define UBJEBuf_destructor(o)
404 UBJEBuf_constructor(
this, cb,buf,bufLen);
407 UBJEBuf_destructor(
this);
623 int vset(
const char** fmt, va_list* argList,
bool isObj);
660 int set(
const char* fmt, ...);
678#define UBJE_MEMBER(o, m) #m, (o)->m
684#define UBJEncoder_constructor(o, ubjsBuf) \
685 memset(o,0,sizeof(UBJEncoder)),(o)->buf=ubjsBuf
690#define UBJEncoder_destructor(o)
695#define UBJEncoder_reset(o) ((o)->status=0,(o)->val.name=0,o->buf->cursor=0,0)
720#define UBJEncoder_setName(o,v) ((o)->val.name=(char*)v)
727#define UBJEncoder_null(o) ((o)->val.t=UBJT_Null,UBJEncoder_val(o))
734#define UBJEncoder_boolean(o,v) \
735 ((o)->val.t=UBJT_Boolean,(o)->val.u.uint8=v,UBJEncoder_val(o))
742#define UBJEncoder_uint8(o,v) \
743 ((o)->val.t=UBJT_Uint8,(o)->val.u.uint8=v,UBJEncoder_val(o))
750#define UBJEncoder_int8(o,v) \
751 ((o)->val.t=UBJT_Int8,(o)->val.u.int8=v,UBJEncoder_val(o))
758#define UBJEncoder_character(o,v) \
759 ((o)->val.t=UBJT_Char,(o)->val.u.int8=v,UBJEncoder_val(o))
766#define UBJEncoder_int16(o,v) \
767 ((o)->val.t=UBJT_Int16,(o)->val.u.int16=v,UBJEncoder_val(o))
774#define UBJEncoder_int32(o,v) \
775 ((o)->val.t=UBJT_Int32,(o)->val.u.int32=v,UBJEncoder_val(o))
782#define UBJEncoder_int64(o,v) \
783 ((o)->val.t=UBJT_Int64,(o)->val.u.int64=v,UBJEncoder_val(o))
790#define UBJEncoder_float64(o,v) \
791 ((o)->val.t=UBJT_Float64,(o)->val.u.float64=v,UBJEncoder_val(o))
798#define UBJEncoder_float32(o,v) \
799 ((o)->val.t=UBJT_Float32,(o)->val.u.float32=v,UBJEncoder_val(o))
807#define UBJEncoder_string(o,v,l) \
808 ((o)->val.t=UBJT_String,(o)->val.u.string=v,(o)->val.len=l,UBJEncoder_val(o))
816#define UBJEncoder_beginArray(o,count, sType) \
817 ((o)->val.t=UBJT_BeginArray,(o)->val.len=count, \
818 (o)->val.x=sType,UBJEncoder_val(o))
826#define UBJEncoder_beginObject(o,count, sType) \
827 ((o)->val.t=UBJT_BeginObject,(o)->val.len=count, \
828 (o)->val.x=sType,UBJEncoder_val(o))
835#define UBJEncoder_endArray(o) ((o)->val.t=UBJT_EndArray,UBJEncoder_val(o))
842#define UBJEncoder_endObject(o) ((o)->val.t=UBJT_EndObject,UBJEncoder_val(o))
#define UBJEncoder_endArray(o)
End the current array.
Definition: ubjson.h:835
struct UBJEncoder UBJEncoder
UBJSON Encoder.
#define UBJParser_getIndex(o)
Query the current optimized-container position.
Definition: ubjson.h:333
#define UBJEncoder_character(o, v)
Encode a char value.
Definition: ubjson.h:758
int endObject()
Close the matching current container.
Definition: ubjson.h:896
#define UBJEncoder_constructor(o, ubjsBuf)
Initialize the encoder; no allocation, flush, or return value.
Definition: ubjson.h:684
struct UBJParser UBJParser
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each pa...
#define UBJParser_destructor(o)
No-op destructor.
Definition: ubjson.h:325
#define UBJEncoder_int8(o, v)
Encode a S8 value.
Definition: ubjson.h:750
#define UBJEncoder_float32(o, v)
Encode a float value.
Definition: ubjson.h:798
~UBJEBuf()
No-op destructor; neither flushes nor frees application buffer storage.
Definition: ubjson.h:406
#define UBJEncoder_setName(o, v)
Set the pending member name.
Definition: ubjson.h:720
int vset(const char **fmt, va_list *argList, bool isObj)
Emit formatted values as for set(), advancing the format cursor.
Definition: ubjson.h:902
int int32(S32 v)
Emit one int32 value.
Definition: ubjson.h:872
int uint8(U8 v)
Emit one uint8 value.
Definition: ubjson.h:860
int UBJParser_parse(UBJParser *o, const U8 *buf, U32 size)
Feed or resume parsing a top-level UBJSON object/array.
struct UBJEBuf UBJEBuf
The UBJSON Encoder buffer is used by the encoder UBJEncoder.
struct UBJPIntf UBJPIntf
The UBJPIntf interface class is the interface between the parser and an object that implements the UB...
void UBJParser_constructor(UBJParser *o, UBJPIntf *intf, char *name, int memberNameLen, int extraStackLen)
Create the callback interface object.
UBJT
UBJSON Value Type: See UBJVal::t and the UBJSON type reference for more information.
Definition: ubjson.h:67
int int8(S8 v)
Emit one int8 value.
Definition: ubjson.h:863
~UBJEncoder()
No-op destructor; does not flush output or free the borrowed buffer.
Definition: ubjson.h:848
int getIndex()
Query the current optimized-container position.
Definition: ubjson.h:354
int UBJEncoder_set(UBJEncoder *o, const char *fmt,...)
Encode/serialize C structs/data to UBJSON using formatted output.
#define UBJEncoder_reset(o)
Discard buffered bytes and clear status/name.
Definition: ubjson.h:695
void UBJVal_setMinInteger(UBJVal *o, S64 in)
Choose the smallest supported integer representation.
#define UBJParser_getCount(o)
Query the current container's declared count.
Definition: ubjson.h:337
int character(char v)
Emit one character value.
Definition: ubjson.h:866
#define UBJEncoder_uint8(o, v)
Encode a U8 value.
Definition: ubjson.h:742
#define UBJEncoder_null(o)
Encode null.
Definition: ubjson.h:727
UBJEStatus
UBJSON Encoder status.
Definition: ubjson.h:413
UBJEncoder(UBJEBuf *buf)
Create/initialize an UBJEncoder instance.
Definition: ubjson.h:845
#define UBJEncoder_string(o, v, l)
Encode string bytes without requiring NUL termination.
Definition: ubjson.h:807
#define UBJEncoder_int16(o, v)
Encode a S16 value.
Definition: ubjson.h:766
int setName(const char *n)
Store a name for the next object value; do not use for array elements.
Definition: ubjson.h:851
int UBJEncoder_vset(UBJEncoder *o, const char **fmt, va_list *argList, int isObj)
Emit formatted values as for set(), advancing the format cursor.
#define UBJEncoder_boolean(o, v)
Encode a boolean.
Definition: ubjson.h:734
UBJEBuf(UBJEBuf_FlushCB cb, U8 *buf, S32 bufLen)
Initialize the UBJSON Encoder buffer.
Definition: ubjson.h:403
int getCount()
Query the current container's declared count.
Definition: ubjson.h:357
int parse(const U8 *buf, U32 size)
Feed or resume parsing a top-level UBJSON object/array.
Definition: ubjson.h:351
#define UBJEncoder_float64(o, v)
Encode a double value.
Definition: ubjson.h:790
int(* UBJEBuf_FlushCB)(struct UBJEBuf *o, int sizeRequired)
Make room in an encoder buffer by flushing or expanding it.
Definition: ubjson.h:375
#define UBJEncoder_int64(o, v)
Encode a S64 value.
Definition: ubjson.h:782
int set(const char *fmt,...)
Encode/serialize C structs/data to UBJSON using formatted output.
Definition: ubjson.h:905
#define UBJEncoder_beginObject(o, count, sType)
Begin an object; emit exactly count named members when count is nonnegative.
Definition: ubjson.h:826
UBJPStatus
UBJSON Parser Status.
Definition: ubjson.h:92
int endArray()
Close the matching current container.
Definition: ubjson.h:893
UBJParser(UBJPIntf *intf, char *name, int memberNameLen, int extraStackLen=0)
Create the callback interface object.
Definition: ubjson.h:344
#define UBJEncoder_int32(o, v)
Encode a S32 value.
Definition: ubjson.h:774
int string(const char *s, S32 len)
Emit a length-delimited string.
Definition: ubjson.h:884
#define UBJParser_getStatus(o)
Definition: ubjson.h:341
int(* UBJPIntf_Service)(struct UBJPIntf *o, UBJVal *v, int recLevel)
Receive a parsed UBJSON event synchronously.
Definition: ubjson.h:193
int beginArray(S32 count=-1, UBJT type=UBJT_InvalidType)
Begin formatting an array.
Definition: ubjson.h:887
int float32(float v)
Emit one float32 value.
Definition: ubjson.h:881
UBJPIntf(UBJPIntf_Service s)
Create the callback interface object.
Definition: ubjson.h:218
#define UBJEncoder_beginArray(o, count, sType)
Begin an array; emit exactly count children when count is nonnegative.
Definition: ubjson.h:816
int float64(double v)
Emit one float64 value.
Definition: ubjson.h:878
int getStatus()
Definition: ubjson.h:360
~UBJParser()
No-op destructor.
Definition: ubjson.h:348
int int64(S64 v)
Emit one int64 value.
Definition: ubjson.h:875
void reset()
Discard buffered bytes and clear status and the pending member name.
Definition: ubjson.h:899
int boolean(bool b)
Emit one boolean value.
Definition: ubjson.h:857
#define UBJEncoder_destructor(o)
No-op; does not flush or free buffers.
Definition: ubjson.h:690
int null()
Emit UBJSON null.
Definition: ubjson.h:854
#define UBJEncoder_endObject(o)
End the current object.
Definition: ubjson.h:842
int int16(S16 v)
Emit one int16 value.
Definition: ubjson.h:869
int beginObject(S32 count=-1, UBJT type=UBJT_InvalidType)
Begin formatting an object.
Definition: ubjson.h:890
@ UBJT_Int8
Type UBJT_Int8.
Definition: ubjson.h:72
@ UBJT_BeginObject
Type UBJT_BeginObject.
Definition: ubjson.h:82
@ UBJT_EndArray
Type UBJT_EndArray.
Definition: ubjson.h:86
@ UBJT_Boolean
Type UBJT_Boolean.
Definition: ubjson.h:71
@ UBJT_HNumber
Raw numeric text; the parser does not validate its grammar.
Definition: ubjson.h:79
@ UBJT_BeginArray
Type UBJT_BeginArray.
Definition: ubjson.h:83
@ UBJT_Int64
Type UBJT_Int64.
Definition: ubjson.h:76
@ UBJT_NoOp
Type UBJT_NoOp.
Definition: ubjson.h:70
@ UBJT_Float64
Type UBJT_Float64.
Definition: ubjson.h:78
@ UBJT_Int32
Type UBJT_Int32.
Definition: ubjson.h:75
@ UBJT_String
Type UBJT_String.
Definition: ubjson.h:81
@ UBJT_Count
Type UBJT_Count.
Definition: ubjson.h:84
@ UBJT_Null
Type UBJT_Null.
Definition: ubjson.h:69
@ UBJT_Int16
Type UBJT_Int16.
Definition: ubjson.h:74
@ UBJT_InvalidType
Not a valid UBJSON type.
Definition: ubjson.h:68
@ UBJT_Char
Type UBJT_Char.
Definition: ubjson.h:80
@ UBJT_Float32
Type UBJT_Float32.
Definition: ubjson.h:77
@ UBJT_Uint8
Type UBJT_Uint8.
Definition: ubjson.h:73
@ UBJT_EndObject
Type UBJT_EndObject.
Definition: ubjson.h:85
@ UBJEStatus_ok
No error.
Definition: ubjson.h:436
@ UBJEStatus_TypeMismatch
The value set does not match the type set for Optimized Strongly Typed.
Definition: ubjson.h:424
@ UBJEStatus_LengthRequired
Length required for Optimized Strongly Typed Container.
Definition: ubjson.h:418
@ UBJEStatus_StackOverflow
Object depth exceeding internal stack.
Definition: ubjson.h:421
@ UBJEStatus_EmptyName
Empty object member names are unsupported.
Definition: ubjson.h:433
@ UBJEStatus_Unknown
Unknown type (Must be a type from UBJT)
Definition: ubjson.h:430
@ UBJEStatus_FlushErr
UBJEBuf_FlushCB returned a non zero value.
Definition: ubjson.h:415
@ UBJEStatus_Unbalanced
(curly) bracket start/end mismatch
Definition: ubjson.h:427
@ UBJPStatus_Done
The parser completed parsing a new UBJSON object, but found the unread bytes in the supplied buffer,...
Definition: ubjson.h:101
@ UBJPStatus_ParseErr
UBJSON Parse error.
Definition: ubjson.h:108
@ UBJPStatus_Overflow
Parsed data/array/object too big.
Definition: ubjson.h:116
@ UBJPStatus_DoneEOS
The parser completed parsing a new UBJSON object.
Definition: ubjson.h:96
@ UBJPStatus_IntfErr
The UBJParserIntf interface reported a problem.
Definition: ubjson.h:112
@ UBJPStatus_NeedMoreData
The parser requires more data to complete.
Definition: ubjson.h:104
int64_t S64
Signed 64-bit integer.
Definition: GenPrimT.h:87
int32_t S32
Signed 32-bit integer.
Definition: GenPrimT.h:85
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:93
int16_t S16
Signed 16-bit integer.
Definition: GenPrimT.h:83
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
int8_t S8
Signed 8-bit integer.
Definition: GenPrimT.h:81
The UBJSON Encoder buffer is used by the encoder UBJEncoder.
Definition: ubjson.h:379
UBJSON Encoder.
Definition: ubjson.h:454
The UBJPIntf interface class is the interface between the parser and an object that implements the UB...
Definition: ubjson.h:201
The event based parser uses a stack instead of recursion and the UBJPStackNode type represent one ent...
Definition: ubjson.h:172
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each pa...
Definition: ubjson.h:240
UBJParser Value (passed into the parser callback interface UBJPIntf)
Definition: ubjson.h:120
U8 uint8
Use when 't' is UBJT_Uint8 or UBJT_Boolean.
Definition: ubjson.h:123
S32 int32
Use when 't' is UBJT_Int32.
Definition: ubjson.h:127
double float64
Use when 't' is UBJT_Float64.
Definition: ubjson.h:130
S8 int8
Use when 't' is UBJT_Int8.
Definition: ubjson.h:124
S64 int64
Use when 't' is UBJT_Int64.
Definition: ubjson.h:128
float float32
Use when 't' is UBJT_Float32.
Definition: ubjson.h:131
const char * string
Borrowed chunk for String/HNumber; not NUL-terminated.
Definition: ubjson.h:133
S16 int16
Use when 't' is UBJT_Int16.
Definition: ubjson.h:126
S32 len
When t=UBJT_Count: container len, When t=UBJT_String: string chunk len.
Definition: ubjson.h:137
char * name
Object member name: set when parent is an object.
Definition: ubjson.h:143
S32 x
When t=UBJT_Count: type UBJT.
Definition: ubjson.h:140
char ch
Use when 't' is UBJT_Char.
Definition: ubjson.h:125
U8 t
UBJSON Type, t is set to one of the types in UBJT.
Definition: ubjson.h:146