Set (or overwrite) value in array.
More...
|
| static int | lite3_ctx_arr_set_null (lite3_ctx *ctx, size_t ofs, uint32_t index) |
| | Set null in array.
|
| |
| static int | lite3_ctx_arr_set_bool (lite3_ctx *ctx, size_t ofs, uint32_t index, bool value) |
| | Set boolean in array.
|
| |
| static int | lite3_ctx_arr_set_i64 (lite3_ctx *ctx, size_t ofs, uint32_t index, int64_t value) |
| | Set integer in array.
|
| |
| static int | lite3_ctx_arr_set_f64 (lite3_ctx *ctx, size_t ofs, uint32_t index, double value) |
| | Set float in array.
|
| |
| static int | lite3_ctx_arr_set_bytes (lite3_ctx *ctx, size_t ofs, uint32_t index, const unsigned char *__restrict bytes, size_t bytes_len) |
| | Set bytes in array.
|
| |
| static int | lite3_ctx_arr_set_str (lite3_ctx *ctx, size_t ofs, uint32_t index, const char *__restrict str) |
| | Set string in array.
|
| |
| static int | lite3_ctx_arr_set_str_n (lite3_ctx *ctx, size_t ofs, uint32_t index, const char *__restrict str, size_t str_len) |
| | Set string in array by length.
|
| |
| static int | lite3_ctx_arr_set_obj (lite3_ctx *ctx, size_t ofs, uint32_t index, size_t *__restrict out_ofs) |
| | Set object in array.
|
| |
| static int | lite3_ctx_arr_set_arr (lite3_ctx *ctx, size_t ofs, uint32_t index, size_t *__restrict out_ofs) |
| | Set array in array.
|
| |
Set (or overwrite) value in 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
- 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 message size.
- Overriding any value with an existing key can still grow the buffer and increase message size.
- 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_ctx_arr_set_arr()
| static int lite3_ctx_arr_set_arr |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
uint32_t |
index, |
|
|
size_t *__restrict |
out_ofs |
|
) |
| |
|
inlinestatic |
Set array in array.
- Returns
- 0 on success
-
< 0 on error
- Parameters
-
| [in] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [out] | out_ofs | offset of the newly inserted array (if not needed, pass NULL) |
Definition at line 1160 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_bool()
| static int lite3_ctx_arr_set_bool |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
uint32_t |
index, |
|
|
bool |
value |
|
) |
| |
|
inlinestatic |
Set boolean in array.
- Returns
- 0 on success
-
< 0 on error
- Parameters
-
| [in] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [in] | value | boolean value to set |
Definition at line 993 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_bytes()
| static int lite3_ctx_arr_set_bytes |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
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] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [in] | bytes | bytes pointer |
| [in] | bytes_len | bytes amount |
Definition at line 1056 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_f64()
| static int lite3_ctx_arr_set_f64 |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
uint32_t |
index, |
|
|
double |
value |
|
) |
| |
|
inlinestatic |
Set float in array.
- Returns
- 0 on success
-
< 0 on error
- Parameters
-
| [in] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [in] | value | floating point value to set |
Definition at line 1035 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_i64()
| static int lite3_ctx_arr_set_i64 |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
uint32_t |
index, |
|
|
int64_t |
value |
|
) |
| |
|
inlinestatic |
Set integer in array.
- Returns
- 0 on success
-
< 0 on error
- Parameters
-
| [in] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [in] | value | integer value to set |
Definition at line 1014 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_null()
| static int lite3_ctx_arr_set_null |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
uint32_t |
index |
|
) |
| |
|
inlinestatic |
Set null in array.
- Returns
- 0 on success
-
< 0 on error
- Parameters
-
| [in] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
Definition at line 974 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_obj()
| static int lite3_ctx_arr_set_obj |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
uint32_t |
index, |
|
|
size_t *__restrict |
out_ofs |
|
) |
| |
|
inlinestatic |
Set object in array.
- Returns
- 0 on success
-
< 0 on error
- Parameters
-
| [in] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [out] | out_ofs | offset of the newly inserted object (if not needed, pass NULL) |
Definition at line 1134 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_str()
| static int lite3_ctx_arr_set_str |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
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] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [in] | str | string pointer |
Definition at line 1083 of file lite3_context_api.h.
◆ lite3_ctx_arr_set_str_n()
| static int lite3_ctx_arr_set_str_n |
( |
lite3_ctx * |
ctx, |
|
|
size_t |
ofs, |
|
|
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] | ctx | context pointer |
| [in] | ofs | start offset (0 == root) |
| [in] | index | array index |
| [in] | str | string pointer |
| [in] | str_len | string length, exclusive of NULL-terminator. |
Definition at line 1109 of file lite3_context_api.h.