40 perror(
"Failed to create lite3_ctx *ctx");
46 perror(
"Failed to decode JSON document");
53 perror(
"Failed to get data array");
58 perror(
"Failed to create iterator");
62 size_t el_densest_ofs = 0;
63 double el_densest_kg_per_m3 = 0.0;
71 perror(
"Failed to get element density");
74 if (kg_per_m3 > el_densest_kg_per_m3) {
75 el_densest_ofs = el_ofs;
76 el_densest_kg_per_m3 = kg_per_m3;
80 perror(
"Failed to get iter element");
83 if (el_densest_ofs == 0) {
84 perror(
"Failed to find densest element");
90 perror(
"Failed to get densest element name");
93 printf(
"densest element: %s\n\n",
LITE3_STR(ctx->buf, name));
95 printf(
"Convert Lite³ to JSON by returned heap pointer (prettified):\n");
99 perror(
"Failed encode JSON");
102 printf(
"%s\n\n", json);
105 printf(
"Convert Lite³ to JSON by writing to buffer (non-prettified):\n");
106 size_t json_buf_size = 1024;
107 char *json_buf = malloc(json_buf_size);
110 perror(
"Failed encode JSON");
113 size_t json_buf_len = (size_t)ret_i64;
114 printf(
"%s\n", json_buf);
115 printf(
"json bytes written: %zu\n", json_buf_len);
#define lite3_ctx_get_str(ctx, ofs, key, out)
Get string value by key.
#define lite3_ctx_get_f64(ctx, ofs, key, out)
Get floating point value by key.
#define lite3_ctx_get_arr(ctx, ofs, key, out)
Get array by key.
static int lite3_ctx_iter_create(lite3_ctx *ctx, size_t ofs, lite3_iter *out)
Create a lite3 iterator for the given object or array.
static int lite3_ctx_iter_next(lite3_ctx *ctx, lite3_iter *iter, lite3_str *out_key, size_t *out_val_ofs)
Get the next item from a lite3 iterator.
static int64_t lite3_ctx_json_enc_buf(lite3_ctx *ctx, size_t ofs, char *__restrict json_buf, size_t json_bufsz)
Convert Lite³ to JSON and write to output buffer.
static int lite3_ctx_json_dec_file(lite3_ctx *ctx, const char *__restrict path)
Convert JSON from file path to Lite³
static char * lite3_ctx_json_enc_pretty(lite3_ctx *ctx, size_t ofs, size_t *__restrict out_len)
Convert Lite³ to JSON prettified string.
static lite3_ctx * lite3_ctx_create(void)
Create context with minimum size.
void lite3_ctx_destroy(lite3_ctx *ctx)
Destroy context.
#define lite3_ctx_is_null(ctx, ofs, key)
Find value by key and test for null type.
#define LITE3_ITER_ITEM
Return value of lite3_iter_next(); iterator produced an item, continue;.
#define LITE3_STR(buf, val)
Generational pointer / safe access wrapper.
Lite³ Context API Header.
Struct containing iterator state.
Struct holding a reference to a string inside a Lite³ buffer.