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 5392 2023-02-21 15:56:50Z 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
54typedef enum {
59
62
67
70
73
78
81
84
89
92 JDecoderS_OK = 0
94
95
97typedef struct
98{
99 U16 contIx; /* container (object or array) index */
100 U8 isObj; /* 1 if object, 0 if array */
102
103
107typedef 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
140typedef 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
222extern "C" {
223#endif
224
225int JDecoder_vget(JDecoder* o, const char* fmt, va_list* argList);
226int JDecoder_get(JDecoder* o, const char* fmt, ...);
227void JDecoder_constructor(
228 JDecoder* o, U8* buf, int bufSize, int extraStackLen);
229#ifdef __cplusplus
230}
231inline int JDecoder::vget(const char* fmt, va_list* argList){
232 return JDecoder_vget(this, fmt, argList);
233}
234inline int JDecoder::get(const char* fmt, ...){
235 int stat;
236 va_list argList;
237 va_start(argList, fmt);
238 stat = JDecoder_vget(this, fmt, &argList);
239 va_end(argList);
240 return stat;
241}
242inline 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
JDecoder JDecoder
JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder...
JDecoder(U8 *buf, int bufSize, int extraStackLen=0)
Create/initialize a JDecoder instance.
Definition: JDecoder.h:242
int vget(const char *fmt, va_list *argList)
See JDecoder::get for details.
Definition: JDecoder.h:231
JDecoderS
JDecoder Status.
Definition: JDecoder.h:54
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
@ JDecoderS_Overflow
Received more array or object member values from parsed data than found in value tree.
Definition: JDecoder.h:66
@ JDecoderS_Underflow
Received less array or object member values from parsed data than found in value tree.
Definition: JDecoder.h:77
@ JDecoderS_OK
OK, no errors.
Definition: JDecoder.h:92
@ JDecoderS_NameNotFound
Parsed data includes a member whose name is not in value tree.
Definition: JDecoder.h:61
@ JDecoderS_StringOverflow
Parsed string longer than buffer provided.
Definition: JDecoder.h:69
@ JDecoderS_ChainedErr
A chained parser callback, provided via the 'X' format flag in JDecoder::get, reported an error.
Definition: JDecoder.h:88
@ JDecoderS_Unbalanced
Incorrect use of '{', '}', '[', or '[' in JDecoder::get.
Definition: JDecoder.h:72
@ JDecoderS_BufNotAligned
Memory buffer(s) provided in JDecoder constructor must be word aligned.
Definition: JDecoder.h:83
@ JDecoderS_FormatErr
Parsed data does not match the value tree that was created when method JDecoder::get was called.
Definition: JDecoder.h:58
@ JDecoderS_Unknown
Unkown error.
Definition: JDecoder.h:80
Used internally in JDecoder for nested data structures.
Definition: JDecoder.h:98
Used internally in JDecoder, where one instance represents one node in the pointer value tree.
Definition: JDecoder.h:108
JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder...
Definition: JDecoder.h:143
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:65