Lite³
A JSON-Compatible Zero-Copy Serialization Format
Loading...
Searching...
No Matches
Iterators

Create and use iterators for objects/arrays. More...

Macros

#define LITE3_ITER_ITEM
 Return value of lite3_ctx_iter_next(); iterator produced an item, continue;.
 
#define LITE3_ITER_DONE
 Return value of lite3_ctx_iter_next(); iterator finished; stop.
 

Functions

static int lite3_ctx_iter_create (lite3_ctx *ctx, size_t ofs, lite3_iter *out)
 Create a lite3 iterator for the given object or array.
 
static int lite3_ctx_iter_next (lite3_ctx *ctx, lite3_iter *iter, lite3_str *out_key, size_t *out_val_ofs)
 Get the next item from a lite3 iterator.
 

Detailed Description

Create and use iterators for objects/arrays.

The ofs (offset) field is used to target an object or array inside the Lite³ buffer. To target the root-level object/array, use ofs == 0.

Warning
Read-only operations are thread-safe. This includes all iterator funtions. Mixing reads and writes however is not thread-safe.

Macro Definition Documentation

◆ LITE3_ITER_DONE

#define LITE3_ITER_DONE

Return value of lite3_ctx_iter_next(); iterator finished; stop.

Definition at line 2046 of file lite3_context_api.h.

◆ LITE3_ITER_ITEM

#define LITE3_ITER_ITEM

Return value of lite3_ctx_iter_next(); iterator produced an item, continue;.

Definition at line 2044 of file lite3_context_api.h.

Function Documentation

◆ lite3_ctx_iter_create()

static int lite3_ctx_iter_create ( lite3_ctx ctx,
size_t  ofs,
lite3_iter out 
)
inlinestatic

Create a lite3 iterator for the given object or array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[out]outiterator struct pointer

Definition at line 2055 of file lite3_context_api.h.

◆ lite3_ctx_iter_next()

static int lite3_ctx_iter_next ( lite3_ctx ctx,
lite3_iter iter,
lite3_str out_key,
size_t *  out_val_ofs 
)
inlinestatic

Get the next item from a lite3 iterator.

To use in conjunctions with lite3_val functions, the *out_val_ofs can be casted to (lite3_val *).

Returns
LITE3_ITER_ITEM (== 1) on item produced
LITE3_ITER_DONE (== 0) on success (no more items)
< 0 on error
Note
If the user does not want a key or value, simply pass NULL. For array iterators, out_key should always be passed as NULL.
Warning
Iterators are read-only. Any attempt to write to the buffer using lite3_ctx_set_xxxx() will immediately invalidate the iterator. If you need to make changes to the buffer, first prepare your changes, then apply them afterwards in one batch.
Parameters
[in]ctxcontext pointer
[in]iteriterator struct pointer
[out]out_keycurrent key (if not needed, pass NULL)
[out]out_val_ofscurrent value offset (if not needed, pass NULL)

Definition at line 2082 of file lite3_context_api.h.