36static unsigned char buf[1024];
40 size_t bufsz =
sizeof(buf);
43 if (lite3_init_arr(buf, &buflen, bufsz) < 0
50 perror(
"Failed to build message");
53 printf(
"buflen: %zu\n", buflen);
55 perror(
"Failed to print JSON");
61 perror(
"Failed to get element");
64 printf(
"Element at index 2: %s\n",
LITE3_STR(buf, element_2));
66 uint32_t element_count;
67 if (
lite3_count(buf, buflen, 0, &element_count) < 0) {
68 perror(
"Failed to get element count");
71 printf(
"Element count: %u\n", element_count);
75 perror(
"Failed to get element");
78 printf(
"Last element: %s\n",
LITE3_STR(buf, last_element));
80 printf(
"\nOverwriting index 2 with \"gnu\"\n");
82 perror(
"Failed to set element");
85 printf(
"buflen: %zu\n", buflen);
87 perror(
"Failed to print JSON");
91 printf(
"\nOverwriting index 3 with \"springbok\"\n");
93 perror(
"Failed to set element");
96 printf(
"buflen: %zu\n", buflen);
98 perror(
"Failed to print JSON");
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_get_str(const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, lite3_str *out)
Get string value by index.
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.
int lite3_json_print(const unsigned char *buf, size_t buflen, size_t ofs)
Print Lite³ buffer as JSON to stdout
#define LITE3_STR(buf, val)
Generational pointer / safe access wrapper.
static int lite3_count(unsigned char *buf, size_t buflen, size_t ofs, uint32_t *out)
Write back the number of object entries or array elements.
Struct holding a reference to a string inside a Lite³ buffer.