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 6657 2026-10-28 18:19:39Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2014 - 2026
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 double* f;
116 char* s;
117 struct /* For obj/array */
118 {
119 U16 firstIx;
120 U16 lastIx; /* used via JDecoder_vget only */
121 } child; /* if t == container (object or array) */
122 JParserIntf* pIntf; /* for 'X' */
123 } u;
124 const char* name; /* Member name, if parent is an object */
125 S32 sSize; /* Size (len+1) of s buffer ( if t == s ) */
126 U16 nextIx;
127 U8 t; /* JVType */
128} JDecoderV;
129
130
139typedef struct JDecoder
140#ifdef __cplusplus
141: public JParserIntf
142{
148 int vget(const char* fmt, va_list* argList);
149
191 int get(const char* fmt, ...);
192
207 JDecoder(U8* buf, int bufSize, int extraStackLen=0);
208#if 0
209}
210#endif
211#else
212{
213 JParserIntf super; /* Inherits from JParserIntf */
214#endif
218 JParserIntf* pIntf;
219 int startServiceLevel;
220 U8* buf;
221 int bufIx;
222 int bufSize;
223 int stacklen;
224 JDecoderStackNode stack[JPARSER_STACK_LEN];
226
227
231#define JD_MNUM(o, m) #m, &(o)->m
232
236#define JD_MSTR(o, m) #m, &(o)->m, sizeof((o)->m)
237
241#define JD_ASTR(o, m) &(o)->m, sizeof((o)->m)
242
243#ifdef __cplusplus
244extern "C" {
245#endif
246
250int JDecoder_vget(JDecoder* o, const char* fmt, va_list* argList);
254int JDecoder_get(JDecoder* o, const char* fmt, ...);
259 JDecoder* o, U8* buf, int bufSize, int extraStackLen);
260#ifdef __cplusplus
261}
262inline int JDecoder::vget(const char* fmt, va_list* argList){
263 return JDecoder_vget(this, fmt, argList);
264}
265inline int JDecoder::get(const char* fmt, ...){
266 int stat;
267 va_list argList;
268 va_start(argList, fmt);
269 stat = JDecoder_vget(this, fmt, &argList);
270 va_end(argList);
271 return stat;
272}
273inline JDecoder::JDecoder(U8* buf, int bufSize, int extraStackLen){
274 JDecoder_constructor(this, buf, bufSize, extraStackLen);
275}
276#endif
277 /* end of JSONCB */
279
280
281#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:273
int vget(const char *fmt, va_list *argList)
Build the same schema as get(), consuming a variable argument list.
Definition: JDecoder.h:262
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:265
@ 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:94
int64_t S64
Signed 64-bit integer.
Definition: GenPrimT.h:90
int32_t S32
Signed 32-bit integer.
Definition: GenPrimT.h:88
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:92
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:142
JDecoderS status
Decoder status set by get() and parser callbacks.
Definition: JDecoder.h:217
The JParserIntf interface class is the interface between the parser and an object that implements the...
Definition: JParser.h:72