36static unsigned char buf[1024];
40 size_t bufsz =
sizeof(buf);
43 if (lite3_init_obj(buf, &buflen, bufsz) < 0
46 ||
lite3_set_str(buf, &buflen, 0, bufsz,
"email",
"marie@example.com") < 0) {
47 perror(
"Failed to build message");
54 perror(
"Failed to get email");
59 if (
lite3_set_str(buf, &buflen, 0, bufsz,
"phone",
"1234567890") < 0) {
60 perror(
"Failed to set email");
69 printf(
"Marie's email: %s\n\n",
LITE3_STR(buf, email));
71 const char *country =
"Germany";
72 size_t country_len = strlen(country);
74 if (
lite3_set_str_n(buf, &buflen, 0, bufsz,
"country", country, country_len) < 0) {
75 perror(
"Failed to set country");
80 perror(
"Failed to print JSON");
#define lite3_get_str(buf, buflen, ofs, key, out)
Get string value by key.
int lite3_json_print(const unsigned char *buf, size_t buflen, size_t ofs)
Print Lite³ buffer as JSON to stdout
#define lite3_set_str(buf, inout_buflen, ofs, bufsz, key, str)
Set string in object.
#define lite3_set_str_n(buf, inout_buflen, ofs, bufsz, key, str, str_len)
Set string in object by length.
#define lite3_set_i64(buf, inout_buflen, ofs, bufsz, key, value)
Set integer in object.
#define LITE3_STR(buf, val)
Generational pointer / safe access wrapper.
Struct holding a reference to a string inside a Lite³ buffer.