Barracuda Application Server C/C++ Reference
NO
ubjsonex.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Application Server
10  *
11  ****************************************************************************
12  * HEADER
13  *
14  * $Id: ubjsonex.h 4914 2021-12-01 18:24:30Z 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 
40 #ifndef __ubjsonex_h
41 #define __ubjsonex_h
42 
43 #include "ubjson.h"
44 
51 typedef enum {
52 
57 
60 
65 
68 
71 
76 
79 
84 
89 
92  UBJDecoderS_OK = 0
94 
95 
97 typedef struct
98 {
99  U16 contIx; /* container (object or array) index */
100  U8 isObj; /* 1 if object, 0 if array */
102 
103 
107 typedef struct
108 {
109  union
110  {
111  U8* uint8;
112  S8* int8;
113  S16* int16;
114  S32* int32;
115  S64* int64;
116 #ifndef NO_DOUBLE
117  double* float64;
118  float* float32;
119 #endif
120  char* string;
121  struct /* For obj/array */
122  {
123  U16 firstIx;
124  U16 lastIx; /* used via UBJDecoder_vget only */
125  } child; /* if t == container (object or array) */
126  UBJPIntf* ubjpintf; /* for 'X' */
127  } u;
128  const char* name; /* Member name, if parent is an object */
129  S32 sSize; /* Size (len+1) of string buffer ( if t == string ) */
130  U16 nextIx;
131  U8 t; /* UBJT */
132 } UBJDecoderV;
133 
134 
135 
144 typedef struct UBJDecoder
145 #ifdef __cplusplus
146 : public UBJPIntf
147 {
149  int vget(const char* fmt, va_list* argList);
150 
178  int get(const char* fmt, ...);
179 
191  UBJDecoder(U8* buf, int bufSize, int extraStackLen=0);
192 #if 0
193 }
194 #endif
195 #else
196 {
197  UBJPIntf super; /* Inherits from UBJPIntf */
198 #endif
199  UBJDecoderS status;
200  UBJPIntf* ubjpintf;
201  int startServiceLevel;
202  char* buildStr;
203  U8* buf;
204  int buildStrLen;
205  int bufIx;
206  int bufSize;
207  int stacklen;
208  UBJDecoderStackNode stack[UBJPARS_STACK_LEN];
210 
214 #define UBJD_MNUM(o, m) #m, &(o)->m
215 
219 #define UBJD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m)
220 
224 #define UBJD_ASTR(o, m) &(o)->m, sizeof((o)->m)
225 
226 
227 #ifdef __cplusplus
228 extern "C" {
229 #endif
230 
231 int UBJDecoder_vget(UBJDecoder* o, const char* fmt, va_list* argList);
232 int UBJDecoder_get(UBJDecoder* o, const char* fmt, ...);
233 void UBJDecoder_constructor(
234  UBJDecoder* o, U8* buf, int bufSize, int extraStackLen);
235 #ifdef __cplusplus
236 }
237 inline int UBJDecoder::vget(const char* fmt, va_list* argList){
238  return UBJDecoder_vget(this, fmt, argList);
239 }
240 inline int UBJDecoder::get(const char* fmt, ...){
241  int status;
242  va_list argList;
243  va_start(argList, fmt);
244  status = UBJDecoder_vget(this, fmt, &argList);
245  va_end(argList);
246  return status;
247 }
248 inline UBJDecoder::UBJDecoder(U8* buf, int bufSize, int extraStackLen){
249  UBJDecoder_constructor(this, buf, bufSize, extraStackLen);
250 }
251 #endif
252  /* end of UBJSONRef */
254 
255 
256 #endif
UBJDecoder::UBJDecoder
UBJDecoder(U8 *buf, int bufSize, int extraStackLen=0)
Create/initialize a UBJDecoder instance.
Definition: ubjsonex.h:248
UBJDecoderS_StringOverflow
@ UBJDecoderS_StringOverflow
Parsed string longer than buffer provided.
Definition: ubjsonex.h:67
UBJDecoderS_Unknown
@ UBJDecoderS_Unknown
Unkown error.
Definition: ubjsonex.h:78
UBJDecoderV
Used internally in UBJDecoder, where one instance represents one node in the pointer value tree.
Definition: ubjsonex.h:108
UBJDecoderS_FormatErr
@ UBJDecoderS_FormatErr
Parsed data does not match the value tree that was created when method UBJDecoder::get was called.
Definition: ubjsonex.h:56
UBJDecoder::get
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:240
UBJDecoderS
UBJDecoderS
UBJDecoder Status Codes.
Definition: ubjsonex.h:51
UBJDecoder
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecode...
Definition: ubjsonex.h:147
UBJDecoderS_Overflow
@ UBJDecoderS_Overflow
Received more array or object member values from parsed data than found in value tree.
Definition: ubjsonex.h:64
UBJDecoderS_Underflow
@ UBJDecoderS_Underflow
Received less array or object member values from parsed data than found in value tree.
Definition: ubjsonex.h:75
UBJPIntf
The UBJPIntf interface class is the interface between the parser and an object that implements the UB...
Definition: ubjson.h:189
UBJDecoder
UBJDecoder UBJDecoder
UBJDecoder implements the parser callback API UBJPIntf and builds a pointer value tree when UBJDecode...
UBJDecoderS_ChainedErr
@ UBJDecoderS_ChainedErr
A chained parser callback, provided via the 'X' format flag in JDecoder::get, reported an error.
Definition: ubjsonex.h:88
UBJDecoderS_OK
@ UBJDecoderS_OK
OK, no errors.
Definition: ubjsonex.h:92
UBJDecoderS_NameNotFound
@ UBJDecoderS_NameNotFound
Parsed data includes a member whose name is not in value tree.
Definition: ubjsonex.h:59
UBJDecoderS_Unbalanced
@ UBJDecoderS_Unbalanced
Incorrect use of '{', '}', '[', or '[' in JDecoder::get.
Definition: ubjsonex.h:70
UBJDecoderStackNode
Used internally in UBJDecoder for nested data structures.
Definition: ubjsonex.h:98
UBJDecoderS_BufNotAligned
@ UBJDecoderS_BufNotAligned
Memory buffer(s) provided in UBJDecoder constructor must be word aligned.
Definition: ubjsonex.h:83
UBJDecoder::vget
int vget(const char *fmt, va_list *argList)
See UBJDecoder::get for details.
Definition: ubjsonex.h:237