40 perror(
"Failed to create lite3_ctx *ctx");
52 perror(
"Failed to build message");
55 printf(
"buflen: %zu\n", ctx->buflen);
57 perror(
"Failed to print JSON");
70 perror(
"Failed to read message");
73 printf(
"\ntitle: %s\n",
LITE3_STR(ctx->buf, title));
74 printf(
"language: %s\n",
LITE3_STR(ctx->buf, language));
75 printf(
"price_usd: %f\n", price_usd);
76 printf(
"pages: %li\n", pages);
77 printf(
"in_stock: %s\n\n", in_stock ?
"true" :
"false");
80 printf(
"No reviews to display.\n");
83 printf(
"\nTitle field exists: %s\n",
lite3_ctx_exists(ctx, 0,
"title") ?
"true" :
"false");
84 printf(
"Price field exists: %s\n",
lite3_ctx_exists(ctx, 0,
"price_usd") ?
"true" :
"false");
85 printf(
"ISBN field exists: %s\n",
lite3_ctx_exists(ctx, 0,
"isbn") ?
"true" :
"false");
88 printf(
"\nTitle is string type: %s\n", title_type ==
LITE3_TYPE_STRING ?
"true" :
"false");
89 printf(
"Title is integer type: %s\n", title_type ==
LITE3_TYPE_I64 ?
"true" :
"false");
93 perror(
"Failed to get price_usd");
96 printf(
"\nPrice is string type: %s\n", lite3_val_is_str(price_val) ?
"true" :
"false");
97 printf(
"Price is double type: %s\n", lite3_val_is_f64(price_val) ?
"true" :
"false");
99 printf(
"price_val value: %f\n", lite3_val_f64(price_val));
103 uint32_t entry_count;
105 perror(
"Failed to get entry count");
108 printf(
"\nObject entries: %u\n", entry_count);
#define lite3_ctx_get(ctx, ofs, key, out)
Get value from object.
#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_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_obj(lite3_ctx *ctx)
Initialize a Lite³ context as an object.
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_f64(ctx, ofs, key, value)
Set floating point in object.
#define lite3_ctx_set_str(ctx, ofs, key, str)
Set string in object.
#define lite3_ctx_get_type(ctx, ofs, key)
Find value by key and return value type.
static int lite3_ctx_count(lite3_ctx *ctx, size_t ofs, uint32_t *out)
Write back the number of object entries or array elements.
#define lite3_ctx_exists(ctx, ofs, key)
Attempt to find a key.
#define lite3_ctx_is_null(ctx, ofs, key)
Find value by key and test for null type.
lite3_type
enum containing all Lite³ types
#define LITE3_STR(buf, val)
Generational pointer / safe access wrapper.
@ LITE3_TYPE_STRING
maps to 'string' type in JSON
@ LITE3_TYPE_F64
maps to 'number' type in JSON; underlying datatype: double
@ LITE3_TYPE_I64
maps to 'number' type in JSON; underlying datatype: int64_t
static size_t lite3_val_type_size(lite3_val *val)
Returns the size of the value type.
Lite³ Context API Header.
Struct holding a reference to a string inside a Lite³ buffer.
Struct representing a value inside a Lite³ buffer.