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()).

IMPORTANT: The stream buffer is invalidated after this call.

Parameters
sbStream buffer to write to (invalidated after call)
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, _S"/name", stvar(string, _S"test"));
ssdSet(root, _S"/value", stvar(int32, 42));
VFSFile *file = vfsOpen(vfs, _S"output.json", FS_Write | FS_Create);
StreamBuffer *sb = sbufCreate(4096);
sbufFileCRegisterPush(sb, file, true);
objRelease(&root);
@ FS_Write
Open for writing.
Definition file.h:37
@ FS_Create
Create file if it doesn't exist.
Definition file.h:38
struct VFSFile VFSFile
Definition vfs.h:44
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
#define objRelease(pinst)
Definition objclass.h:223
bool sbufFileCRegisterPush(StreamBuffer *sb, VFSFile *file, bool close)
@ JSON_Pretty
Preset: 4-space indent with newlines (readable output)
Definition jsonout.h:59
#define jsonOutTree(sb, tree,...)
Definition jsonout.h:171
StreamBuffer * sbufCreate(size_t targetsz)
#define ssdSet(root, path, createpath, val)
Definition ssdtree.h:415
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392
#define stvar(typen, val)
Definition stvar.h:153

Definition at line 171 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, _S"/items/0", stvar(int32, 1));
ssdSet(root, _S"/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:202
void strDestroy(strhandle ps)

Definition at line 202 of file jsonout.h.