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

Append value to array. More...

Functions

static int lite3_arr_append_null (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz)
 Append null to array.
 
static int lite3_arr_append_bool (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, bool value)
 Append boolean to array.
 
static int lite3_arr_append_i64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, int64_t value)
 Append integer to array.
 
static int lite3_arr_append_f64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, double value)
 Append floating point to array.
 
static int lite3_arr_append_bytes (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, const unsigned char *__restrict bytes, size_t bytes_len)
 Append bytes to array.
 
static int lite3_arr_append_str (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, const char *__restrict str)
 Append string to array.
 
static int lite3_arr_append_str_n (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, const char *__restrict str, size_t str_len)
 Append string to array by length.
 
static int lite3_arr_append_obj (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, size_t *__restrict out_ofs)
 Append object to array.
 
static int lite3_arr_append_arr (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, size_t *__restrict out_ofs)
 Append array to array.
 

Detailed Description

Append value to array.

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

Set functions read *inout_buflen to know the currently used portion of the buffer. After modifications, the new length will be written back. The caller must provide sufficient buffer space via bufsz or the call will fail and set errno to ENOBUFS. Retrying is up to the caller.

The number of bytes written to *buf never exceeds bufsz.

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 *inout_buflen.

Function Documentation

◆ lite3_arr_append_arr()

static int lite3_arr_append_arr ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
size_t *__restrict  out_ofs 
)
inlinestatic

Append array to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[out]out_ofsoffset of the newly appended array (if not needed, pass NULL)

Definition at line 1391 of file lite3.h.

◆ lite3_arr_append_bool()

static int lite3_arr_append_bool ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
bool  value 
)
inlinestatic

Append boolean to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[in]valueboolean value to append

Definition at line 1214 of file lite3.h.

◆ lite3_arr_append_bytes()

static int lite3_arr_append_bytes ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
const unsigned char *__restrict  bytes,
size_t  bytes_len 
)
inlinestatic

Append bytes to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[in]bytesbytes pointer
[in]bytes_lenbytes amount

Definition at line 1280 of file lite3.h.

◆ lite3_arr_append_f64()

static int lite3_arr_append_f64 ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
double  value 
)
inlinestatic

Append floating point to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[in]valuefloating point value to append

Definition at line 1258 of file lite3.h.

◆ lite3_arr_append_i64()

static int lite3_arr_append_i64 ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
int64_t  value 
)
inlinestatic

Append integer to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[in]valueinteger value to append

Definition at line 1236 of file lite3.h.

◆ lite3_arr_append_null()

static int lite3_arr_append_null ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz 
)
inlinestatic

Append null to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size

Definition at line 1194 of file lite3.h.

◆ lite3_arr_append_obj()

static int lite3_arr_append_obj ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
size_t *__restrict  out_ofs 
)
inlinestatic

Append object to array.

Returns
0 on success
< 0 on error
Parameters
[in]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[out]out_ofsoffset of the newly appended object (if not needed, pass NULL)

Definition at line 1366 of file lite3.h.

◆ lite3_arr_append_str()

static int lite3_arr_append_str ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
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]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[in]strstring pointer

Definition at line 1308 of file lite3.h.

◆ lite3_arr_append_str_n()

static int lite3_arr_append_str_n ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
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]bufbuffer pointer
[in,out]inout_buflenbuffer used length
[in]ofsstart offset (0 == root)
[in]bufszbuffer max size
[in]strstring pointer
[in]str_lenstring length, exclusive of NULL-terminator.

Definition at line 1335 of file lite3.h.