Set value in array.
More...
|
| 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.
|
| |
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
- Insertions, like any other buffer mutations, are not thread-safe. The caller must manually synchronize access to the buffer.
- A failed call with return value < 0 can still write to the buffer and increase
*inout_buflen.
- Overriding any value with an existing key can still grow the buffer and increase
*inout_buflen.
- 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.
◆ 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [out] | out_ofs | offset 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [in] | value | boolean 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [in] | bytes | bytes pointer |
| [in] | bytes_len | bytes 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [in] | value | floating 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [in] | value | integer 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [out] | out_ofs | offset 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [in] | str | string 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] | buf | buffer pointer |
| [in,out] | inout_buflen | buffer used length |
| [in] | ofs | start offset (0 == root) |
| [in] | bufsz | buffer max size |
| [in] | index | array index |
| [in] | str | string pointer |
| [in] | str_len | string length, exclusive of NULL-terminator. |
Definition at line 1591 of file lite3.h.