Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
ubjsonex.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: ubjsonex.h 5978 2026-09-11 16:13:48Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2014
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://realtimelogic.com
34 ****************************************************************************
35
36 Universal Binary JSON http://ubjson.org/
37 Extended API: UBJDecoder and UBJEncoder_set
38*/
39
42#ifndef __ubjsonex_h
43#define __ubjsonex_h
44
45#include "ubjson.h"
46
53typedef enum {
54
59
62
67
70
73
77
80
85
90
95
96
98typedef struct
99{
100 U16 contIx; /* container (object or array) index */
101 U8 isObj; /* 1 if object, 0 if array */
103
104
108typedef struct
109{
110 union
111 {
112 U8* uint8;
113 S8* int8;
114 S16* int16;
115 S32* int32;
116 S64* int64;
117#ifndef NO_DOUBLE
118 double* float64;
119 float* float32;
120#endif
121 char* string;
122 struct /* For obj/array */
123 {
124 U16 firstIx;
125 U16 lastIx; /* used via UBJDecoder_vget only */
126 } child; /* if t == container (object or array) */
127 UBJPIntf* ubjpintf; /* for 'X' */
128 } u;
129 const char* name; /* Member name, if parent is an object */
130 S32 sSize; /* Size (len+1) of string buffer ( if t == string ) */
131 U16 nextIx;
132 U8 t; /* UBJT */
134
135
136
145typedef struct UBJDecoder
146#ifdef __cplusplus
147: public UBJPIntf
148{
150 int vget(const char* fmt, va_list* argList);
151
191 int get(const char* fmt, ...);
192
206 UBJDecoder(U8* buf, int bufSize, int extraStackLen=0);
207#if 0
208}
209#endif
210#else
211{
212 UBJPIntf super; /* Inherits from UBJPIntf */
213#endif
214 UBJDecoderS status;
215 UBJPIntf* ubjpintf;
216 int startServiceLevel;
217 char* buildStr;
218 U8* buf;
219 int buildStrLen;
220 int bufIx;
221 int bufSize;
222 int stacklen;
223 UBJDecoderStackNode stack[UBJPARS_STACK_LEN];
225
229#define UBJD_MNUM(o, m) #m, &(o)->m
230
234#define UBJD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m)
235
239#define UBJD_ASTR(o, m) &(o)->m, sizeof((o)->m)
240
241
242#ifdef __cplusplus
243extern "C" {
244#endif
245
252int UBJDecoder_vget(UBJDecoder* o, const char* fmt, va_list* argList);
256int UBJDecoder_get(UBJDecoder* o, const char* fmt, ...);
261 UBJDecoder* o, U8* buf, int bufSize, int extraStackLen);
262#ifdef __cplusplus
263}
264inline int UBJDecoder::vget(const char* fmt, va_list* argList){
265 return UBJDecoder_vget(this, fmt, argList);
266}
267inline int UBJDecoder::get(const char* fmt, ...){
268 int status;
269 va_list argList;
270 va_start(argList, fmt);
271 status = UBJDecoder_vget(this, fmt, &argList);
272 va_end(argList);
273 return status;
274}
275inline UBJDecoder::UBJDecoder(U8* buf, int bufSize, int extraStackLen){
276 UBJDecoder_constructor(this, buf, bufSize, extraStackLen);
277}
278#endif
279 /* end of UBJSONRef */
281
282
283#endif
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 fe...
UBJDecoderS
UBJDecoder Status Codes.
Definition: ubjsonex.h:53
int UBJDecoder_vget(UBJDecoder *o, const char *fmt, va_list *argList)
Build the schema using a va_list; see UBJDecoder::get for format rules.
int vget(const char *fmt, va_list *argList)
See UBJDecoder::get for details.
Definition: ubjsonex.h:264
void UBJDecoder_constructor(UBJDecoder *o, U8 *buf, int bufSize, int extraStackLen)
Create/initialize a UBJDecoder instance.
UBJDecoder UBJDecoder
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecode...
UBJDecoder(U8 *buf, int bufSize, int extraStackLen=0)
Create/initialize a UBJDecoder instance.
Definition: ubjsonex.h:275
int get(const char *fmt,...)
Build a pointer value tree that is used by the integrated parser callback function when the parser fe...
Definition: ubjsonex.h:267
@ UBJDecoderS_ChainedErr
A chained parser callback, provided via the 'X' format flag in UBJDecoder::get, reported an error.
Definition: ubjsonex.h:89
@ UBJDecoderS_Unknown
Unknown error.
Definition: ubjsonex.h:79
@ UBJDecoderS_Unbalanced
Incorrect use of '{', '}', '[', or ']' in UBJDecoder::get.
Definition: ubjsonex.h:72
@ UBJDecoderS_BufNotAligned
Memory buffer(s) provided in UBJDecoder constructor must be word aligned.
Definition: ubjsonex.h:84
@ UBJDecoderS_NameNotFound
Parsed data includes a member whose name is not in value tree.
Definition: ubjsonex.h:61
@ UBJDecoderS_Underflow
Input supplies another value after all schema children were consumed.
Definition: ubjsonex.h:76
@ UBJDecoderS_StringOverflow
Parsed string longer than buffer provided.
Definition: ubjsonex.h:69
@ UBJDecoderS_FormatErr
Parsed data does not match the value tree that was created when method UBJDecoder::get was called.
Definition: ubjsonex.h:58
@ UBJDecoderS_Overflow
Unconsumed schema values remain when a container ends; also used for excessive schema nesting.
Definition: ubjsonex.h:66
@ UBJDecoderS_OK
OK, no errors.
Definition: ubjsonex.h:93
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:91
int64_t S64
Signed 64-bit integer.
Definition: GenPrimT.h:87
int32_t S32
Signed 32-bit integer.
Definition: GenPrimT.h:85
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
Used internally in UBJDecoder for nested data structures.
Definition: ubjsonex.h:99
Used internally in UBJDecoder, where one instance represents one node in the pointer value tree.
Definition: ubjsonex.h:109
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecode...
Definition: ubjsonex.h:148
The UBJPIntf interface class is the interface between the parser and an object that implements the UB...
Definition: ubjson.h:201