44#include <TargConfig.h>
53#define UBJ_ALIGNMT uintptr_t
55#define UBJ_POINTER_NOT_ALIGNED(p) \
56 (0 != ((uintptr_t)p & (sizeof(UBJ_ALIGNMT) - 1)))
59#define UBJPARS_STACK_LEN 3
155void UBJVal_setMinInteger(
UBJVal* o, S64 in);
201#define UBJPIntf_constructor(o,serviceMA) (o)->service=serviceMA
202#define UBJPIntf_destructor(o)
203#define UBJPIntf_service(o,v,recLev) (o)->service(o,v,recLev)
207 UBJPIntf_constructor(
this, s);
209inline UBJPIntf::~UBJPIntf() {
210 UBJPIntf_destructor(
this);
248 int parse(
const U8* buf, U32 size);
272 const U8* lxTokenPtr;
292 int memberNameLen,
int extraStackLen);
293#define UBJParser_destructor(o)
294int UBJParser_parse(
UBJParser* o,
const U8* buf, U32 size);
295#define UBJParser_getIndex(o) (o)->stack[(o)->stackIx].ix
296#define UBJParser_getCount(o) (o)->stack[(o)->stackIx].count
297#define UBJParser_getStatus(o) (o)->status
301 UBJPIntf* intf,
char* name,
int memberNameLen,
int extraStackLen) {
302 UBJParser_constructor(
this, intf, name, memberNameLen, extraStackLen);
305 UBJParser_destructor(
this);
308 return UBJParser_parse(
this, buf, size);
311 return UBJParser_getIndex(
this);
314 return UBJParser_getCount(
this);
317 return UBJParser_getStatus(
this);
350#define UBJEBuf_constructor(o, flushCBM, dataM, dlenM) \
351 (o)->flushCB=flushCBM,(o)->data=dataM,(o)->dlen=dlenM,(o)->cursor=0
352#define UBJEBuf_destructor(o)
356 UBJEBuf_constructor(
this, cb,buf,bufLen);
358inline UBJEBuf::~UBJEBuf() {
359 UBJEBuf_destructor(
this);
445 int string(
const char* s, S32 len);
485 int vset(
const char** fmt, va_list* argList,
bool isObj);
515 int set(
const char* fmt, ...);
533#define UBJE_MEMBER(o, m) #m, (o)->m
535#define UBJEncoder_constructor(o, ubjsBuf) \
536 memset(o,0,sizeof(UBJEncoder)),(o)->buf=ubjsBuf
537#define UBJEncoder_destructor(o)
538#define UBJEncoder_reset(o) ((o)->status=0,(o)->val.name=0,o->buf->cursor=0,0)
545int UBJEncoder_vset(
UBJEncoder* o,
const char** fmt,va_list* argList,
int isObj);
546int UBJEncoder_set(
UBJEncoder* o,
const char* fmt, ...);
551#define UBJEncoder_setName(o,v) ((o)->val.name=(char*)v)
552#define UBJEncoder_null(o) ((o)->val.t=UBJT_Null,UBJEncoder_val(o))
553#define UBJEncoder_boolean(o,v) \
554 ((o)->val.t=UBJT_Boolean,(o)->val.u.uint8=v,UBJEncoder_val(o))
555#define UBJEncoder_uint8(o,v) \
556 ((o)->val.t=UBJT_Uint8,(o)->val.u.uint8=v,UBJEncoder_val(o))
557#define UBJEncoder_int8(o,v) \
558 ((o)->val.t=UBJT_Int8,(o)->val.u.int8=v,UBJEncoder_val(o))
559#define UBJEncoder_character(o,v) \
560 ((o)->val.t=UBJT_Char,(o)->val.u.int8=v,UBJEncoder_val(o))
561#define UBJEncoder_int16(o,v) \
562 ((o)->val.t=UBJT_Int16,(o)->val.u.int16=v,UBJEncoder_val(o))
563#define UBJEncoder_int32(o,v) \
564 ((o)->val.t=UBJT_Int32,(o)->val.u.int32=v,UBJEncoder_val(o))
565#define UBJEncoder_int64(o,v) \
566 ((o)->val.t=UBJT_Int64,(o)->val.u.int64=v,UBJEncoder_val(o))
567#define UBJEncoder_float64(o,v) \
568 ((o)->val.t=UBJT_Float64,(o)->val.u.float64=v,UBJEncoder_val(o))
569#define UBJEncoder_float32(o,v) \
570 ((o)->val.t=UBJT_Float32,(o)->val.u.float32=v,UBJEncoder_val(o))
571#define UBJEncoder_string(o,v,l) \
572 ((o)->val.t=UBJT_String,(o)->val.u.string=v,(o)->val.len=l,UBJEncoder_val(o))
573#define UBJEncoder_beginArray(o,count, sType) \
574 ((o)->val.t=UBJT_BeginArray,(o)->val.len=count, \
575 (o)->val.x=sType,UBJEncoder_val(o))
576#define UBJEncoder_beginObject(o,count, sType) \
577 ((o)->val.t=UBJT_BeginObject,(o)->val.len=count, \
578 (o)->val.x=sType,UBJEncoder_val(o))
579#define UBJEncoder_endArray(o) ((o)->val.t=UBJT_EndArray,UBJEncoder_val(o))
580#define UBJEncoder_endObject(o) ((o)->val.t=UBJT_EndObject,UBJEncoder_val(o))
584 UBJEncoder_constructor(
this, b);
587 UBJEncoder_destructor(
this);
590 return UBJEncoder_setName(
this, n);
593 return UBJEncoder_null(
this);
596 return UBJEncoder_boolean(
this, b ? 1 : 0);
599 return UBJEncoder_uint8(
this, v);
602 return UBJEncoder_int8(
this, v);
605 return UBJEncoder_character(
this, v);
608 return UBJEncoder_int16(
this, v);
611 return UBJEncoder_int32(
this, v);
614 return UBJEncoder_int64(
this, v);
617 return UBJEncoder_float64(
this, v);
620 return UBJEncoder_float32(
this, v);
623 return UBJEncoder_string(
this, s, len);
626 return UBJEncoder_beginArray(
this, count, t);
629 return UBJEncoder_beginObject(
this, count, t);
632 return UBJEncoder_endArray(
this);
635 return UBJEncoder_endObject(
this);
638 UBJEncoder_reset(
this);
641 return UBJEncoder_vset(
this, fmt, argList, isObj ? 1 : 0);
647 status = UBJEncoder_vset(
this, &fmt, &varg, 0);
struct UBJEncoder UBJEncoder
UBJSON Encoder.
int endObject()
End of object.
Definition: ubjson.h:634
struct UBJParser UBJParser
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each pa...
int vset(const char **fmt, va_list *argList, bool isObj)
See UBJEncoder:set for details.
Definition: ubjson.h:640
int int32(S32 v)
Set int32.
Definition: ubjson.h:610
int uint8(U8 v)
Set uint8.
Definition: ubjson.h:598
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...
UBJT
UBJSON Value Type: See UBJVal::t and the UBJSON type reference for more information.
Definition: ubjson.h:65
int int8(S8 v)
Set int8.
Definition: ubjson.h:601
~UBJEncoder()
Destructor.
Definition: ubjson.h:586
int getIndex()
Returns the current container index position when parsing an optimized container.
Definition: ubjson.h:310
int character(char v)
Set 'char'.
Definition: ubjson.h:604
UBJEStatus
UBJSON Encoder status.
Definition: ubjson.h:365
UBJEncoder(UBJEBuf *buf)
Create/initialize an UBJEncoder instance.
Definition: ubjson.h:583
int setName(const char *n)
Set member name.
Definition: ubjson.h:589
UBJEBuf(UBJEBuf_FlushCB cb, U8 *buf, S32 bufLen)
Initialize the UBJSON Encoder buffer.
Definition: ubjson.h:355
int getCount()
Returns the length of the optimized container when type (t) is UBJT_Count.
Definition: ubjson.h:313
int parse(const U8 *buf, U32 size)
Parse a UBJSON chunk.
Definition: ubjson.h:307
int(* UBJEBuf_FlushCB)(struct UBJEBuf *o, int sizeRequired)
UBJSON Encoder buffer callback can be used for flushing the buffer or for expanding the buffer.
Definition: ubjson.h:330
int set(const char *fmt,...)
Encode/serialize C structs/data to UBJSON using formatted output.
Definition: ubjson.h:643
UBJPStatus
UBJSON Parser Status.
Definition: ubjson.h:90
int endArray()
End of array.
Definition: ubjson.h:631
UBJParser(UBJPIntf *intf, char *name, int memberNameLen, int extraStackLen=0)
Create the callback interface object.
Definition: ubjson.h:300
int string(const char *s, S32 len)
Set string.
Definition: ubjson.h:622
int(* UBJPIntf_Service)(struct UBJPIntf *o, UBJVal *v, int recLevel)
Parser callback function used by interface class UBJPIntf.
Definition: ubjson.h:181
int beginArray(S32 count=-1, UBJT type=UBJT_InvalidType)
Begin formatting an array.
Definition: ubjson.h:625
int float32(float v)
Set float32.
Definition: ubjson.h:619
UBJPIntf(UBJPIntf_Service s)
Create the callback interface object.
Definition: ubjson.h:206
int float64(double v)
Set float64.
Definition: ubjson.h:616
int getStatus()
Returns the parser status.
Definition: ubjson.h:316
~UBJParser()
Destructor.
Definition: ubjson.h:304
int int64(S64 v)
Set int64.
Definition: ubjson.h:613
void reset()
Resets the UBJEBuf cursor (the buffer provided in the constructor)
Definition: ubjson.h:637
int boolean(bool b)
Set boolean.
Definition: ubjson.h:595
int null()
Set UBJSON NULL.
Definition: ubjson.h:592
int int16(S16 v)
Set int16.
Definition: ubjson.h:607
int beginObject(S32 count=-1, UBJT type=UBJT_InvalidType)
Begin formatting an object.
Definition: ubjson.h:628
@ UBJT_Int8
Type UBJT_Int8.
Definition: ubjson.h:70
@ UBJT_BeginObject
Type UBJT_BeginObject.
Definition: ubjson.h:80
@ UBJT_EndArray
Type UBJT_EndArray.
Definition: ubjson.h:84
@ UBJT_Boolean
Type UBJT_Boolean.
Definition: ubjson.h:69
@ UBJT_HNumber
Type UBJT_HNumber.
Definition: ubjson.h:77
@ UBJT_BeginArray
Type UBJT_BeginArray.
Definition: ubjson.h:81
@ UBJT_Int64
Type UBJT_Int64.
Definition: ubjson.h:74
@ UBJT_NoOp
Type UBJT_NoOp.
Definition: ubjson.h:68
@ UBJT_Float64
Type UBJT_Float64.
Definition: ubjson.h:76
@ UBJT_Int32
Type UBJT_Int32.
Definition: ubjson.h:73
@ UBJT_String
Type UBJT_String.
Definition: ubjson.h:79
@ UBJT_Count
Type UBJT_Count.
Definition: ubjson.h:82
@ UBJT_Null
Type UBJT_Null.
Definition: ubjson.h:67
@ UBJT_Int16
Type UBJT_Int16.
Definition: ubjson.h:72
@ UBJT_InvalidType
Not a valid UBJSON type.
Definition: ubjson.h:66
@ UBJT_Char
Type UBJT_Char.
Definition: ubjson.h:78
@ UBJT_Float32
Type UBJT_Float32.
Definition: ubjson.h:75
@ UBJT_Uint8
Type UBJT_Uint8.
Definition: ubjson.h:71
@ UBJT_EndObject
Type UBJT_EndObject.
Definition: ubjson.h:83
@ UBJEStatus_ok
No error.
Definition: ubjson.h:385
@ UBJEStatus_TypeMismatch
The value set does not mach type set for Optimized Strongly Typed
Definition: ubjson.h:376
@ UBJEStatus_LengthRequired
Length required for Optimized Strongly Typed Container.
Definition: ubjson.h:370
@ UBJEStatus_StackOverflow
Object depth exceeding internal stack.
Definition: ubjson.h:373
@ UBJEStatus_Unknown
Unknown type (Must be a type from UBJT)
Definition: ubjson.h:382
@ UBJEStatus_FlushErr
UBJEBuf_FlushCB returned a non zero value.
Definition: ubjson.h:367
@ UBJEStatus_Unbalanced
(curly) bracket start/end mismatch
Definition: ubjson.h:379
@ UBJPStatus_Done
The parser completed parsing a new UBJSON object, but found the start of a new object in the provided...
Definition: ubjson.h:99
@ UBJPStatus_ParseErr
UBJSON Parse error.
Definition: ubjson.h:106
@ UBJPStatus_Overflow
Parsed data/array/object too big.
Definition: ubjson.h:114
@ UBJPStatus_DoneEOS
The parser completed parsing a new UBJSON object.
Definition: ubjson.h:94
@ UBJPStatus_IntfErr
The UBJParserIntf interface reported a problem.
Definition: ubjson.h:110
@ UBJPStatus_NeedMoreData
The parser requires more data to complete.
Definition: ubjson.h:102
The UBJSON Encoder buffer is used by the encoder UBJEncoder.
Definition: ubjson.h:334
UBJSON Encoder.
Definition: ubjson.h:395
The UBJPIntf interface class is the interface between the parser and an object that implements the UB...
Definition: ubjson.h:189
The event based parser uses a stack instead of recursion and the UBJPStackNode type represent one ent...
Definition: ubjson.h:166
The UBJSON parser parses a binary UBJSON stream and calls the UBJPIntf callback interface for each pa...
Definition: ubjson.h:221
UBJParser Value (passed into the parser callback interface UBJPIntf)
Definition: ubjson.h:118
U8 uint8
Use when 't' is UBJT_Uint8 or UBJT_Boolean.
Definition: ubjson.h:121
S32 int32
Use when 't' is UBJT_Int32.
Definition: ubjson.h:125
double float64
Use when 't' is UBJT_Float64.
Definition: ubjson.h:128
S8 int8
Use when 't' is UBJT_Uint8.
Definition: ubjson.h:122
S64 int64
Use when 't' is UBJT_Int64.
Definition: ubjson.h:126
float float32
Use when 't' is UBJT_Float32.
Definition: ubjson.h:129
const char * string
Use when 't' is UBJT_String.
Definition: ubjson.h:131
S16 int16
Use when 't' is UBJT_Int16.
Definition: ubjson.h:124
S32 len
When t=UBJT_Count: container len, When t=UBJT_String: string chunk len.
Definition: ubjson.h:135
char * name
Object member name: set when parent is an object.
Definition: ubjson.h:141
S32 x
When t=UBJT_Count: type UBJT.
Definition: ubjson.h:138
char ch
Use when 't' is UBJT_Char.
Definition: ubjson.h:123
U8 t
UBJSON Type, t is set to one of the types in UBJT.
Definition: ubjson.h:144