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

Append value to array. More...

Functions

static int lite3_ctx_arr_append_null (lite3_ctx *ctx, size_t ofs)
 Append null to array.
 
static int lite3_ctx_arr_append_bool (lite3_ctx *ctx, size_t ofs, bool value)
 Append boolean to array.
 
static int lite3_ctx_arr_append_i64 (lite3_ctx *ctx, size_t ofs, int64_t value)
 Append integer to array.
 
static int lite3_ctx_arr_append_f64 (lite3_ctx *ctx, size_t ofs, double value)
 Append floating point to array.
 
static int lite3_ctx_arr_append_bytes (lite3_ctx *ctx, size_t ofs, const unsigned char *__restrict bytes, size_t bytes_len)
 Append bytes to array.
 
static int lite3_ctx_arr_append_str (lite3_ctx *ctx, size_t ofs, const char *__restrict str)
 Append string to array.
 
static int lite3_ctx_arr_append_str_n (lite3_ctx *ctx, size_t ofs, const char *__restrict str, size_t str_len)
 Append string to array by length.
 
static int lite3_ctx_arr_append_obj (lite3_ctx *ctx, size_t ofs, size_t *__restrict out_ofs)
 Append object to array.
 
static int lite3_ctx_arr_append_arr (lite3_ctx *ctx, size_t ofs, size_t *__restrict out_ofs)
 Append array to array.
 

Detailed Description

Append value to array.

An empty buffer must first be initialized using lite3_ctx_init_obj() or lite3_ctx_init_arr() before insertion. See Object / Array Initialization.

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.

Returns
  • Returns 0 on success
  • Returns < 0 on error
Warning
  1. Append actions, like any other buffer mutations, are not thread-safe. The caller must manually synchronize access to the buffer.
  2. A failed call with return value < 0 can still write to the buffer and increase message size.

Function Documentation

◆ lite3_ctx_arr_append_arr()

static int lite3_ctx_arr_append_arr ( lite3_ctx ctx,
size_t  ofs,
size_t *__restrict  out_ofs 
)
inlinestatic

Append array to array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[out]out_ofsoffset of the newly appended array (if not needed, pass NULL)

Definition at line 922 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_bool()

static int lite3_ctx_arr_append_bool ( lite3_ctx ctx,
size_t  ofs,
bool  value 
)
inlinestatic

Append boolean to array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[in]valueboolean value to append

Definition at line 762 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_bytes()

static int lite3_ctx_arr_append_bytes ( lite3_ctx ctx,
size_t  ofs,
const unsigned char *__restrict  bytes,
size_t  bytes_len 
)
inlinestatic

Append bytes to array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[in]bytesbytes pointer
[in]bytes_lenbytes amount

Definition at line 822 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_f64()

static int lite3_ctx_arr_append_f64 ( lite3_ctx ctx,
size_t  ofs,
double  value 
)
inlinestatic

Append floating point to array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[in]valuefloating point value to append

Definition at line 802 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_i64()

static int lite3_ctx_arr_append_i64 ( lite3_ctx ctx,
size_t  ofs,
int64_t  value 
)
inlinestatic

Append integer to array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[in]valueinteger value to append

Definition at line 782 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_null()

static int lite3_ctx_arr_append_null ( lite3_ctx ctx,
size_t  ofs 
)
inlinestatic

Append null to array.

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

Definition at line 744 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_obj()

static int lite3_ctx_arr_append_obj ( lite3_ctx ctx,
size_t  ofs,
size_t *__restrict  out_ofs 
)
inlinestatic

Append object to array.

Returns
0 on success
< 0 on error
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[out]out_ofsoffset of the newly appended object (if not needed, pass NULL)

Definition at line 897 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_str()

static int lite3_ctx_arr_append_str ( lite3_ctx ctx,
size_t  ofs,
const char *__restrict  str 
)
inlinestatic

Append string to array.

Returns
0 on success
< 0 on error
Note
This function must call strlen() to learn the size of the string. If you know the length beforehand, it is more efficient to call lite3_set_str_n().
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[in]strstring pointer

Definition at line 848 of file lite3_context_api.h.

◆ lite3_ctx_arr_append_str_n()

static int lite3_ctx_arr_append_str_n ( lite3_ctx ctx,
size_t  ofs,
const char *__restrict  str,
size_t  str_len 
)
inlinestatic

Append string to array by length.

Returns
0 on success
< 0 on error
Warning
str_len is exclusive of the NULL-terminator.
Parameters
[in]ctxcontext pointer
[in]ofsstart offset (0 == root)
[in]strstring pointer
[in]str_lenstring length, exclusive of NULL-terminator.

Definition at line 873 of file lite3_context_api.h.