CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Tree Output

Macros

#define jsonOutTree(sb, tree, ...)    _jsonOutTree(sb, tree, opt_flags(__VA_ARGS__), (SSDLockState*)_ssdCurrentLockState)
 
#define jsonTreeToString(out, tree, ...)    _jsonTreeToString(out, tree, opt_flags(__VA_ARGS__), (SSDLockState*)_ssdCurrentLockState)
 

Detailed Description

Automatic JSON serialization from SSD trees.

Macro Definition Documentation

◆ jsonOutTree

#define jsonOutTree (   sb,
  tree,
  ... 
)     _jsonOutTree(sb, tree, opt_flags(__VA_ARGS__), (SSDLockState*)_ssdCurrentLockState)

bool jsonOutTree(StreamBuffer *sb, SSDNode *tree, [flags])

Serializes an SSD tree to a stream buffer as JSON.

Automatically traverses the entire tree and outputs properly formatted JSON. The stream buffer should have a consumer registered (e.g., sbufStrCRegisterPush() or sbufFileCRegisterPush()).

Parameters
sbStream buffer to write to
treeRoot node of SSD tree to serialize
...(flags) Optional output formatting flags (defaults to platform EOL with no indent)
Returns
true on success, false on error

Example:

SSDNode *root = ssdCreate(0);
ssdSet(root, _SL("/name"), stvar(string, _SL("test")));
ssdSet(root, _SL("/value"), stvar(int32, 42));
VFSFile *file = vfsOpen(vfs, _SL("output.json"), FS_Write | FS_Create);
StreamBuffer *sb = sbufCreate(4096);
sbufFileCRegisterPush(sb, file, true);
objRelease(&root);
@ FS_Write
Open for writing.
Definition fs.h:322
@ FS_Create
Create file if it doesn't exist.
Definition fs.h:323
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
#define objRelease(pinst)
Definition objclass.h:257
@ JSON_Pretty
Preset: 4-space indent with newlines (readable output)
Definition jsonout.h:61
#define jsonOutTree(sb, tree,...)
Definition jsonout.h:198
#define sbufCreate(targetsz,...)
Definition streambuf.h:275
#define ssdSet(root, path, createpath, val)
Definition ssdtree.h:417
#define _SL(s)
Inline ASCII string literal with compile-time embedded length (STR_LEN8). Content must be < 200 bytes...
Definition strliteral.h:207
#define stvar(typen, val)
Definition stvar.h:162

Definition at line 198 of file jsonout.h.

◆ jsonTreeToString

#define jsonTreeToString (   out,
  tree,
  ... 
)     _jsonTreeToString(out, tree, opt_flags(__VA_ARGS__), (SSDLockState*)_ssdCurrentLockState)

bool jsonTreeToString(string *out, SSDNode *tree, [flags])

Serializes an SSD tree to a string as JSON.

Convenience function that internally creates a stream buffer and writes the JSON output to a string. Equivalent to manually setting up a stream buffer with sbufStrCRegisterPush() and calling jsonOutTree().

Parameters
outString to receive JSON output
treeRoot node of SSD tree to serialize
...(flags) Optional output formatting flags (defaults to platform EOL with no indent)
Returns
true on success, false on error

Example:

SSDNode *root = ssdCreate(0);
ssdSet(root, _SL("/items/0"), stvar(int32, 1));
ssdSet(root, _SL("/items/1"), stvar(int32, 2));
string json = 0;
// json now contains: {\n "items": [1, 2]\n}\n
strDestroy(&json);
objRelease(&root);
#define jsonTreeToString(out, tree,...)
Definition jsonout.h:229
void strDestroy(strhandle ps)

Definition at line 229 of file jsonout.h.