|
Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
|
The JEncoder can serialize a JSON JVAL syntax tree to the JSON text format.
The JEncoder can also be used for assembling JSON text by calling the primitive methods in this class. Supply a valid sequence of names, values, and matching container delimiters. Writes are incremental: failure can leave partial output and does not roll back prior bytes. The borrowed JErr retains errors until explicitly reset by the caller.
Example:
#include <JEncoder.h>
Public Member Functions | |
| JEncoder (JErr *err, BufPrint *out) | |
| Initialize an encoder without writing output or resetting err. More... | |
| ~JEncoder () | |
| Call flush() without freeing the borrowed writer or error object. More... | |
| int | setInt (S32 val) |
| Write a JSON number. More... | |
| int | setLong (S64 val) |
| Write a JSON number. More... | |
| int | setDouble (double val) |
| Write a JSON number. More... | |
| int | setString (const char *val, size_t len) |
| Write a quoted JSON string through BufPrint::jsonString. More... | |
| int | b64enc (const void *source, S32 slen) |
| Write binary data as a quoted standard Base64 string. More... | |
| int | fmtString (const char *fmt,...) |
| Format text inside JSON quotation marks. More... | |
| int | vFmtString (const char *fmt, va_list argList) |
| Write formatted text between JSON quotes, or JSON null. More... | |
| int | setBoolean (bool val) |
| Write a JSON boolean. More... | |
| int | setNull () |
| Write JSON null. More... | |
| int | setJV (struct JVal *val, bool iterateNext=false) |
| Serialize a JVal node and its child values. More... | |
| int | set (const char *fmt,...) |
| Encode/serialize C structs/data to JSON using formatted output. More... | |
| int | setName (const char *name) |
| Write an object member name before its value. More... | |
| int | beginObject () |
| Begin a JSON object value; call setName() before each member value. More... | |
| int | endObject () |
| Close the current object after its final complete member. More... | |
| int | beginArray () |
| Begin a JSON array value; array elements have no member-name call. More... | |
| int | endArray () |
| Close the current array after its final complete element. More... | |
| JErr * | getErr () |
| Query error storage. More... | |
| int | flush () |
| Flush the underlying writer if JErr is clear. More... | |
| int | commit () |
| Permit a new top-level value and flush the writer. More... | |
| BufPrint * | getBufPrint () |
| Query output storage. More... | |