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

Utility functions. More...

Macros

#define lite3_ctx_get_type(ctx, ofs, key)
 Find value by key and return value type.
 
#define lite3_ctx_get_type_size(ctx, ofs, key, out)
 Find value by key and write back type size.
 
#define lite3_ctx_exists(ctx, ofs, key)
 Attempt to find a key.
 
#define lite3_ctx_is_null(ctx, ofs, key)
 Find value by key and test for null type.
 
#define lite3_ctx_is_bool(ctx, ofs, key)
 Find value by key and test for bool type.
 
#define lite3_ctx_is_i64(ctx, ofs, key)
 Find value by key and test for integer type.
 
#define lite3_ctx_is_f64(ctx, ofs, key)
 Find value by key and test for floating point type.
 
#define lite3_ctx_is_bytes(ctx, ofs, key)
 Find value by key and test for bytes type.
 
#define lite3_ctx_is_str(ctx, ofs, key)
 Find value by key and test for string type.
 
#define lite3_ctx_is_obj(ctx, ofs, key)
 Find value by key and test for object type.
 
#define lite3_ctx_is_arr(ctx, ofs, key)
 Find value by key and test for array type.
 

Functions

static void lite3_ctx_print (lite3_ctx *ctx)
 View the internal structure of a Lite³ buffer.
 
static int lite3_ctx_count (lite3_ctx *ctx, size_t ofs, uint32_t *out)
 Write back the number of object entries or array elements.
 

Detailed Description

Utility functions.

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 utility funtions. Mixing reads and writes however is not thread-safe.

Macro Definition Documentation

◆ lite3_ctx_exists

#define lite3_ctx_exists (   ctx,
  ofs,
  key 
)

Attempt to find a key.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true on success
false on failure

Definition at line 1279 of file lite3_context_api.h.

◆ lite3_ctx_get_type

#define lite3_ctx_get_type (   ctx,
  ofs,
  key 
)

Find value by key and return value type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
lite3_type on success
LITE3_TYPE_INVALID on error (key cannot be found)

Definition at line 1215 of file lite3_context_api.h.

◆ lite3_ctx_get_type_size

#define lite3_ctx_get_type_size (   ctx,
  ofs,
  key,
  out 
)

Find value by key and write back type size.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
[out]out(size *) type size
Returns
0 on success
< 0 on error
Note
For variable sized types like LITE3_TYPE_BYTES or LITE3_TYPE_STRING, the number of bytes (including NULL-terminator for string) are written back.

Definition at line 1246 of file lite3_context_api.h.

◆ lite3_ctx_is_arr

#define lite3_ctx_is_arr (   ctx,
  ofs,
  key 
)

Find value by key and test for array type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1513 of file lite3_context_api.h.

◆ lite3_ctx_is_bool

#define lite3_ctx_is_bool (   ctx,
  ofs,
  key 
)

Find value by key and test for bool type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1357 of file lite3_context_api.h.

◆ lite3_ctx_is_bytes

#define lite3_ctx_is_bytes (   ctx,
  ofs,
  key 
)

Find value by key and test for bytes type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1435 of file lite3_context_api.h.

◆ lite3_ctx_is_f64

#define lite3_ctx_is_f64 (   ctx,
  ofs,
  key 
)

Find value by key and test for floating point type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1409 of file lite3_context_api.h.

◆ lite3_ctx_is_i64

#define lite3_ctx_is_i64 (   ctx,
  ofs,
  key 
)

Find value by key and test for integer type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1383 of file lite3_context_api.h.

◆ lite3_ctx_is_null

#define lite3_ctx_is_null (   ctx,
  ofs,
  key 
)

Find value by key and test for null type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1331 of file lite3_context_api.h.

◆ lite3_ctx_is_obj

#define lite3_ctx_is_obj (   ctx,
  ofs,
  key 
)

Find value by key and test for object type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1487 of file lite3_context_api.h.

◆ lite3_ctx_is_str

#define lite3_ctx_is_str (   ctx,
  ofs,
  key 
)

Find value by key and test for string type.

Parameters
[in]ctx(lite3_ctx *) context pointer
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true if the value matches the type
false if the type does not match or the key cannot be found

Definition at line 1461 of file lite3_context_api.h.

Function Documentation

◆ lite3_ctx_count()

static int lite3_ctx_count ( lite3_ctx ctx,
size_t  ofs,
uint32_t *  out 
)
inlinestatic

Write back the number of object entries or array elements.

This function can be called on objects and arrays.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[out]outnumber of object entries or array elements

Definition at line 1303 of file lite3_context_api.h.

◆ lite3_ctx_print()

static void lite3_ctx_print ( lite3_ctx ctx)
inlinestatic

View the internal structure of a Lite³ buffer.

Requires LITE3_DEBUG enabled. See Library Configuration Options.

Definition at line 1200 of file lite3_context_api.h.