39const char names[NAME_COUNT][10] = {
51 perror(
"Failed to create lite3_ctx *ctx");
57 perror(
"Failed to initialize array");
60 for (
int i = 0; i < NAME_COUNT; i++) {
67 perror(
"Failed to build array");
72 perror(
"Failed to print JSON");
79 perror(
"Failed to create iterator");
91 perror(
"Failed to get object");
94 printf(
"id: %li\tname: %s\tvip_member: %s\tbenefits: %s\n",
97 vip_member ?
"true" :
"false",
98 benefits ?
"yes" :
"no"
105 perror(
"Failed to create iterator");
108 printf(
"\nObject keys:\n");
114 printf(
"key: %s\tvalue: ",
LITE3_STR(ctx->buf, key));
118 printf(
"%li\n", lite3_val_i64(val));
121 printf(
"%s\n", lite3_val_bool(val) ?
"true" :
"false");
127 printf(
"%s\n", lite3_val_str(val));
130 fprintf(stderr,
"Invalid object value type\n");
static int lite3_ctx_arr_append_obj(lite3_ctx *ctx, size_t ofs, size_t *__restrict out_ofs)
Append object to array.
#define lite3_ctx_get_str(ctx, ofs, key, out)
Get string value by key.
#define lite3_ctx_get_bool(ctx, ofs, key, out)
Get boolean value by key.
#define lite3_ctx_get_i64(ctx, ofs, key, out)
Get integer value by key.
static int lite3_ctx_init_arr(lite3_ctx *ctx)
Initialize a Lite³ context as an array.
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 int lite3_ctx_json_print(lite3_ctx *ctx, size_t ofs)
Print Lite³ buffer as JSON to stdout
static lite3_ctx * lite3_ctx_create(void)
Create context with minimum size.
void lite3_ctx_destroy(lite3_ctx *ctx)
Destroy context.
#define lite3_ctx_set_i64(ctx, ofs, key, value)
Set integer in object.
#define lite3_ctx_set_null(ctx, ofs, key)
Set null in object.
#define lite3_ctx_set_bool(ctx, ofs, key, value)
Set boolean in object.
#define lite3_ctx_set_str(ctx, ofs, key, str)
Set string in object.
#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.
@ LITE3_TYPE_STRING
maps to 'string' type in JSON
@ LITE3_TYPE_BOOL
maps to 'boolean' type in JSON; underlying datatype: bool
@ LITE3_TYPE_I64
maps to 'number' type in JSON; underlying datatype: int64_t
@ LITE3_TYPE_NULL
maps to 'null' type in JSON
Lite³ Context API Header.
Struct containing iterator state.
Struct holding a reference to a string inside a Lite³ buffer.
Struct representing a value inside a Lite³ buffer.