Barracuda Application Server C/C++ Reference
NO
JDecoder.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Application Server
10  *
11  ****************************************************************************
12  * HEADER
13  *
14  * $Id: JDecoder.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 
37 #ifndef __jdecode_h
38 #define __jdecode_h
39 
40 #include <JVal.h>
41 
46 #ifndef J_ALIGNMT
47 #define J_ALIGNMT uintptr_t
48 #endif
49 #define J_POINTER_NOT_ALIGNED(p) (0 != ((uintptr_t)p & (sizeof(J_ALIGNMT)-1)))
50 
51 
54 typedef enum {
59 
62 
67 
70 
73 
78 
81 
84 
89 
92  JDecoderS_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* b;
112  S32* d;
113  S64* l;
114 #ifndef NO_DOUBLE
115  double* f;
116 #endif
117  char* s;
118  struct /* For obj/array */
119  {
120  U16 firstIx;
121  U16 lastIx; /* used via JDecoder_vget only */
122  } child; /* if t == container (object or array) */
123  JParserIntf* pIntf; /* for 'X' */
124  } u;
125  const char* name; /* Member name, if parent is an object */
126  S32 sSize; /* Size (len+1) of s buffer ( if t == s ) */
127  U16 nextIx;
128  U8 t; /* JVType */
129 } JDecoderV;
130 
131 
140 typedef struct JDecoder
141 #ifdef __cplusplus
142 : public JParserIntf
143 {
145  int vget(const char* fmt, va_list* argList);
146 
174  int get(const char* fmt, ...);
175 
187  JDecoder(U8* buf, int bufSize, int extraStackLen=0);
188 #if 0
189 }
190 #endif
191 #else
192 {
193  JParserIntf super; /* Inherits from JParserIntf */
194 #endif
195  JDecoderS status;
196  JParserIntf* pIntf;
197  int startServiceLevel;
198  U8* buf;
199  int bufIx;
200  int bufSize;
201  int stacklen;
202  JDecoderStackNode stack[JPARSER_STACK_LEN];
204 
205 
209 #define JD_MNUM(o, m) #m, &(o)->m
210 
214 #define JD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m)
215 
219 #define JD_ASTR(o, m) &(o)->m, sizeof((o)->m)
220 
221 #ifdef __cplusplus
222 extern "C" {
223 #endif
224 
225 int JDecoder_vget(JDecoder* o, const char* fmt, va_list* argList);
226 int JDecoder_get(JDecoder* o, const char* fmt, ...);
227 void JDecoder_constructor(
228  JDecoder* o, U8* buf, int bufSize, int extraStackLen);
229 #ifdef __cplusplus
230 }
231 inline int JDecoder::vget(const char* fmt, va_list* argList){
232  return JDecoder_vget(this, fmt, argList);
233 }
234 inline int JDecoder::get(const char* fmt, ...){
235  int status;
236  va_list argList;
237  va_start(argList, fmt);
238  status = JDecoder_vget(this, fmt, &argList);
239  va_end(argList);
240  return status;
241 }
242 inline JDecoder::JDecoder(U8* buf, int bufSize, int extraStackLen){
243  JDecoder_constructor(this, buf, bufSize, extraStackLen);
244 }
245 #endif
246  /* end of JSONCB */
248 
249 
250 #endif
JDecoderStackNode
Used internally in JDecoder for nested data structures.
Definition: JDecoder.h:98
JDecoderS_Underflow
@ JDecoderS_Underflow
Received less array or object member values from parsed data than found in value tree.
Definition: JDecoder.h:77
JParserIntf
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:65
JDecoderS
JDecoderS
JDecoder Status.
Definition: JDecoder.h:54
JDecoderS_NameNotFound
@ JDecoderS_NameNotFound
Parsed data includes a member whose name is not in value tree.
Definition: JDecoder.h:61
JDecoderS_OK
@ JDecoderS_OK
OK, no errors.
Definition: JDecoder.h:92
JDecoder::vget
int vget(const char *fmt, va_list *argList)
See JDecoder::get for details.
Definition: JDecoder.h:231
JDecoderS_Unknown
@ JDecoderS_Unknown
Unkown error.
Definition: JDecoder.h:80
JDecoder::JDecoder
JDecoder(U8 *buf, int bufSize, int extraStackLen=0)
Create/initialize a JDecoder instance.
Definition: JDecoder.h:242
JDecoderS_Overflow
@ JDecoderS_Overflow
Received more array or object member values from parsed data than found in value tree.
Definition: JDecoder.h:66
JDecoderS_Unbalanced
@ JDecoderS_Unbalanced
Incorrect use of '{', '}', '[', or '[' in JDecoder::get.
Definition: JDecoder.h:72
JDecoderS_FormatErr
@ JDecoderS_FormatErr
Parsed data does not match the value tree that was created when method JDecoder::get was called.
Definition: JDecoder.h:58
JDecoder::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: JDecoder.h:234
JDecoder
JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder...
Definition: JDecoder.h:143
JDecoderS_StringOverflow
@ JDecoderS_StringOverflow
Parsed string longer than buffer provided.
Definition: JDecoder.h:69
JDecoderS_ChainedErr
@ JDecoderS_ChainedErr
A chained parser callback, provided via the 'X' format flag in JDecoder::get, reported an error.
Definition: JDecoder.h:88
JDecoder
JDecoder JDecoder
JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder...
JDecoderS_BufNotAligned
@ JDecoderS_BufNotAligned
Memory buffer(s) provided in JDecoder constructor must be word aligned.
Definition: JDecoder.h:83
JDecoderV
Used internally in JDecoder, where one instance represents one node in the pointer value tree.
Definition: JDecoder.h:108