Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
JDecoder.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: JDecoder.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
39#ifndef __jdecode_h
40#define __jdecode_h
41
42#include <JVal.h>
43
48#ifndef J_ALIGNMT
49#define J_ALIGNMT uintptr_t
50#endif
51#define J_POINTER_NOT_ALIGNED(p) (0 != ((uintptr_t)p & (sizeof(J_ALIGNMT)-1)))
52
53
56typedef enum {
61
64
69
72
75
79
82
85
90
93 JDecoderS_OK = 0
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* b;
113 S32* d;
114 S64* l;
115#ifndef NO_DOUBLE
116 double* f;
117#endif
118 char* s;
119 struct /* For obj/array */
120 {
121 U16 firstIx;
122 U16 lastIx; /* used via JDecoder_vget only */
123 } child; /* if t == container (object or array) */
124 JParserIntf* pIntf; /* for 'X' */
125 } u;
126 const char* name; /* Member name, if parent is an object */
127 S32 sSize; /* Size (len+1) of s buffer ( if t == s ) */
128 U16 nextIx;
129 U8 t; /* JVType */
130} JDecoderV;
131
132
141typedef struct JDecoder
142#ifdef __cplusplus
143: public JParserIntf
144{
150 int vget(const char* fmt, va_list* argList);
151
193 int get(const char* fmt, ...);
194
209 JDecoder(U8* buf, int bufSize, int extraStackLen=0);
210#if 0
211}
212#endif
213#else
214{
215 JParserIntf super; /* Inherits from JParserIntf */
216#endif
220 JParserIntf* pIntf;
221 int startServiceLevel;
222 U8* buf;
223 int bufIx;
224 int bufSize;
225 int stacklen;
226 JDecoderStackNode stack[JPARSER_STACK_LEN];
228
229
233#define JD_MNUM(o, m) #m, &(o)->m
234
238#define JD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m)
239
243#define JD_ASTR(o, m) &(o)->m, sizeof((o)->m)
244
245#ifdef __cplusplus
246extern "C" {
247#endif
248
252int JDecoder_vget(JDecoder* o, const char* fmt, va_list* argList);
256int JDecoder_get(JDecoder* o, const char* fmt, ...);
261 JDecoder* o, U8* buf, int bufSize, int extraStackLen);
262#ifdef __cplusplus
263}
264inline int JDecoder::vget(const char* fmt, va_list* argList){
265 return JDecoder_vget(this, fmt, argList);
266}
267inline int JDecoder::get(const char* fmt, ...){
268 int stat;
269 va_list argList;
270 va_start(argList, fmt);
271 stat = JDecoder_vget(this, fmt, &argList);
272 va_end(argList);
273 return stat;
274}
275inline JDecoder::JDecoder(U8* buf, int bufSize, int extraStackLen){
276 JDecoder_constructor(this, buf, bufSize, extraStackLen);
277}
278#endif
279 /* end of JSONCB */
281
282
283#endif
int JDecoder_get(JDecoder *o, const char *fmt,...)
Build a pointer value tree that is used by the integrated parser callback function when the parser fe...
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:275
int vget(const char *fmt, va_list *argList)
Build the same schema as get(), consuming a variable argument list.
Definition: JDecoder.h:264
JDecoderS
JDecoder Status.
Definition: JDecoder.h:56
void JDecoder_constructor(JDecoder *o, U8 *buf, int bufSize, int extraStackLen)
Create/initialize a JDecoder instance.
int JDecoder_vget(JDecoder *o, const char *fmt, va_list *argList)
Build the same schema as get(), consuming a variable argument list.
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:267
@ JDecoderS_Overflow
Unconsumed schema values remain when a container ends; also used for excessive schema nesting.
Definition: JDecoder.h:68
@ JDecoderS_Underflow
Input supplies another value after all schema children were consumed.
Definition: JDecoder.h:78
@ JDecoderS_OK
OK, no errors.
Definition: JDecoder.h:93
@ JDecoderS_NameNotFound
Parsed data includes a member whose name is not in value tree.
Definition: JDecoder.h:63
@ JDecoderS_StringOverflow
Parsed string longer than buffer provided.
Definition: JDecoder.h:71
@ JDecoderS_ChainedErr
A chained parser callback, provided via the 'X' format flag in JDecoder::get, reported an error.
Definition: JDecoder.h:89
@ JDecoderS_Unbalanced
Incorrect use of '{', '}', '[', or ']' in JDecoder::get.
Definition: JDecoder.h:74
@ JDecoderS_BufNotAligned
Memory buffer(s) provided in JDecoder constructor must be word aligned.
Definition: JDecoder.h:84
@ JDecoderS_FormatErr
Parsed data does not match the value tree that was created when method JDecoder::get was called.
Definition: JDecoder.h:60
@ JDecoderS_Unknown
Unknown error.
Definition: JDecoder.h:81
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
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
Used internally in JDecoder for nested data structures.
Definition: JDecoder.h:99
Used internally in JDecoder, where one instance represents one node in the pointer value tree.
Definition: JDecoder.h:109
JDecoder implements the parser callback API JParserIntf and builds a pointer value tree when JDecoder...
Definition: JDecoder.h:144
JDecoderS status
Decoder status set by get() and parser callbacks.
Definition: JDecoder.h:219
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:72