Barracuda Application Server C/C++ Reference
NO
JEncoder Struct Reference

Detailed Description

The JEncoder can serialize a JSON JVAL syntax tree to the JSON text format.

The JEncoder can also be used for assembling JSON text from calling the primitive methods in this class.

Example:

JErr err;
char buf[40]; //Must be sufficiently large for the JSON string
BufPrint jBuf(buf,sizeof(buf));
JEncoder jEnc(&err,&jBuf);
jEnc.set("{d}", "The number of the day is", 5);
//jBuf.buf == buf
buf[jBuf.cursor]=0; // So we can use printf
printf("%s\n",buf); // Prints: {"The number of the day is":5}

#include <JEncoder.h>

Public Member Functions

 JEncoder (JErr *err, BufPrint *out)
 Create an instance of the JEncoder class.
 
int setInt (S32 val)
 Format an integer value.
 
int setLong (S64 val)
 Format a long integer value.
 
int setDouble (double val)
 Format a double value.
 
int setString (const char *val)
 Format a string value. More...
 
int b64enc (const void *source, S32 slen)
 Encode and emit (binary) data using B64 encoding.
 
int fmtString (const char *fmt,...)
 Converts (according to format 'fmt') and writes to stream. More...
 
int vFmtString (const char *fmt, va_list argList)
 Equivalent to fmtString with variable argument list replaced by argList.
 
int setBoolean (bool val)
 Format a boolean value.
 
int setNull ()
 Set a JSON null value.
 
int setJV (struct JVal *val, bool iterateNext=false)
 Format a node or a tree of JVal nodes.
 
int set (const char *fmt,...)
 Encode/serialize C structs/data to JSON using formatted output. More...
 
int setName (const char *name)
 Set the member name before calling any of the set<value> members if formatting an object. More...
 
int beginObject ()
 Begin object formatting. More...
 
int endObject ()
 End object formatting.
 
int beginArray ()
 Begin array formatting.
 
int endArray ()
 End array formatting.
 
JErrgetErr ()
 Returns the JErr object.
 
int flush ()
 Flush JEncoder data to the output stream.
 
int commit ()
 Calls flush and enables the construction of a new object.
 
BufPrintgetBufPrint ()
 Fetch the internal BufPrint object.
 
JEncoder
The JEncoder can serialize a JSON JVAL syntax tree to the JSON text format.
Definition: JEncoder.h:66
BufPrint
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
JErr
The JSON error container object.
Definition: JParser.h:155