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

Set value in array. More...

Functions

static int lite3_arr_set_null (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index)
 Set null in array.
 
static int lite3_arr_set_bool (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, bool value)
 Set boolean in array.
 
static int lite3_arr_set_i64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, int64_t value)
 Set integer in array.
 
static int lite3_arr_set_f64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, double value)
 Set float in array.
 
static int lite3_arr_set_bytes (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, const unsigned char *__restrict bytes, size_t bytes_len)
 Set bytes in array.
 
static int lite3_arr_set_str (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, const char *__restrict str)
 Set string in array.
 
static int lite3_arr_set_str_n (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, const char *__restrict str, size_t str_len)
 Set string in array by length.
 
static int lite3_arr_set_obj (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, size_t *__restrict out_ofs)
 Set object in array.
 
static int lite3_arr_set_arr (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, size_t *__restrict out_ofs)
 Set array in array.
 

Detailed Description

Set value in 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
Note
Setting a value at an existing index will override the current value.
Warning
  1. Insertions, 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.
  3. Overriding any value with an existing key can still grow the buffer and increase *inout_buflen.
  4. Overriding a variable-length value (string/bytes) will require extra buffer space if the new value is larger than the old. The overridden space is never recovered, causing buffer size to grow indefinitely.

Function Documentation

◆ lite3_arr_set_arr()

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

Set array in 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]indexarray index
[out]out_ofsoffset of the newly inserted array (if not needed, pass NULL)

Definition at line 1649 of file lite3.h.

◆ lite3_arr_set_bool()

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

Set boolean in 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]indexarray index
[in]valueboolean value to set

Definition at line 1465 of file lite3.h.

◆ lite3_arr_set_bytes()

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

Set bytes in 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]indexarray index
[in]bytesbytes pointer
[in]bytes_lenbytes amount

Definition at line 1534 of file lite3.h.

◆ lite3_arr_set_f64()

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

Set float in 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]indexarray index
[in]valuefloating point value to set

Definition at line 1511 of file lite3.h.

◆ lite3_arr_set_i64()

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

Set integer in 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]indexarray index
[in]valueinteger value to set

Definition at line 1488 of file lite3.h.

◆ lite3_arr_set_null()

static int lite3_arr_set_null ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
uint32_t  index 
)
inlinestatic

Set null in 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]indexarray index

Definition at line 1444 of file lite3.h.

◆ lite3_arr_set_obj()

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

Set object in 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]indexarray index
[out]out_ofsoffset of the newly inserted object (if not needed, pass NULL)

Definition at line 1623 of file lite3.h.

◆ lite3_arr_set_str()

static int lite3_arr_set_str ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
uint32_t  index,
const char *__restrict  str 
)
inlinestatic

Set string in 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]indexarray index
[in]strstring pointer

Definition at line 1563 of file lite3.h.

◆ lite3_arr_set_str_n()

static int lite3_arr_set_str_n ( unsigned char *  buf,
size_t *__restrict  inout_buflen,
size_t  ofs,
size_t  bufsz,
uint32_t  index,
const char *__restrict  str,
size_t  str_len 
)
inlinestatic

Set string in 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]indexarray index
[in]strstring pointer
[in]str_lenstring length, exclusive of NULL-terminator.

Definition at line 1591 of file lite3.h.