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

Utility functions. More...

Macros

#define lite3_get_type(buf, buflen, ofs, key)
 Find value by key and return value type.
 
#define lite3_get_type_size(buf, buflen, ofs, key, out)
 Find value by key and write back type size.
 
#define lite3_exists(buf, buflen, ofs, key)
 Attempt to find a key.
 
#define lite3_is_null(buf, buflen, ofs, key)
 Find value by key and test for null type.
 
#define lite3_is_bool(buf, buflen, ofs, key)
 Find value by key and test for bool type.
 
#define lite3_is_i64(buf, buflen, ofs, key)
 Find value by key and test for integer type.
 
#define lite3_is_f64(buf, buflen, ofs, key)
 Find value by key and test for floating point type.
 
#define lite3_is_bytes(buf, buflen, ofs, key)
 Find value by key and test for bytes type.
 
#define lite3_is_str(buf, buflen, ofs, key)
 Find value by key and test for string type.
 
#define lite3_is_obj(buf, buflen, ofs, key)
 Find value by key and test for object type.
 
#define lite3_is_arr(buf, buflen, ofs, key)
 Find value by key and test for array type.
 

Functions

static int lite3_count (unsigned char *buf, size_t buflen, size_t ofs, uint32_t *out)
 Write back the number of object entries or array elements.
 

Detailed Description

Utility functions.

Get functions read buflen to know the currently used portion of the buffer.

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

Macro Definition Documentation

◆ lite3_exists

#define lite3_exists (   buf,
  buflen,
  ofs,
  key 
)

Attempt to find a key.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[in]ofs(size_t) start offset (0 == root)
[in]key(const char *) key
Returns
true on success
false on failure

Definition at line 1838 of file lite3.h.

◆ lite3_get_type

#define lite3_get_type (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and return value type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 1772 of file lite3.h.

◆ lite3_get_type_size

#define lite3_get_type_size (   buf,
  buflen,
  ofs,
  key,
  out 
)

Find value by key and write back type size.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 1804 of file lite3.h.

◆ lite3_is_arr

#define lite3_is_arr (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for array type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 2081 of file lite3.h.

◆ lite3_is_bool

#define lite3_is_bool (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for bool type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 1919 of file lite3.h.

◆ lite3_is_bytes

#define lite3_is_bytes (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for bytes type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 2000 of file lite3.h.

◆ lite3_is_f64

#define lite3_is_f64 (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for floating point type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 1973 of file lite3.h.

◆ lite3_is_i64

#define lite3_is_i64 (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for integer type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 1946 of file lite3.h.

◆ lite3_is_null

#define lite3_is_null (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for null type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 1892 of file lite3.h.

◆ lite3_is_obj

#define lite3_is_obj (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for object type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 2054 of file lite3.h.

◆ lite3_is_str

#define lite3_is_str (   buf,
  buflen,
  ofs,
  key 
)

Find value by key and test for string type.

Parameters
[in]buf(const unsigned char *) buffer pointer
[in]buflen(size_t) buffer used length
[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 2027 of file lite3.h.

Function Documentation

◆ lite3_count()

static int lite3_count ( unsigned char *  buf,
size_t  buflen,
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]bufbuffer pointer
[in]buflenbuffer used length
[in]ofsstart offset (0 == root)
[out]outnumber of object entries or array elements

Definition at line 1862 of file lite3.h.