Lite³
A JSON-Compatible Zero-Copy Serialization Format
Loading...
Searching...
No Matches
lite3_context_api.h File Reference

Lite³ Context API Header. More...

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include "lite3.h"

Go to the source code of this file.

Data Structures

struct  lite3_ctx
 Lite³ context struct. More...
 

Macros

#define LITE3_CONTEXT_BUF_SIZE_MIN
 The minimum buffer size for a Lite³ context.
 
#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_i64(ctx, ofs, key, value)
 Set integer in object.
 
#define lite3_ctx_set_f64(ctx, ofs, key, value)
 Set floating point in object.
 
#define lite3_ctx_set_bytes(ctx, ofs, key, bytes, bytes_len)
 Set bytes in object.
 
#define lite3_ctx_set_str(ctx, ofs, key, str)
 Set string in object.
 
#define lite3_ctx_set_str_n(ctx, ofs, key, str, str_len)
 Set string in object by length.
 
#define lite3_ctx_set_obj(ctx, ofs, key, out_ofs)
 Set object in object.
 
#define lite3_ctx_set_arr(ctx, ofs, key, out_ofs)
 Set array in object.
 
#define lite3_ctx_get_type(ctx, ofs, key)
 Find value by key and return value type.
 
#define lite3_ctx_get_type_size(ctx, ofs, key, out)
 Find value by key and write back type size.
 
#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.
 
#define lite3_ctx_is_bool(ctx, ofs, key)
 Find value by key and test for bool type.
 
#define lite3_ctx_is_i64(ctx, ofs, key)
 Find value by key and test for integer type.
 
#define lite3_ctx_is_f64(ctx, ofs, key)
 Find value by key and test for floating point type.
 
#define lite3_ctx_is_bytes(ctx, ofs, key)
 Find value by key and test for bytes type.
 
#define lite3_ctx_is_str(ctx, ofs, key)
 Find value by key and test for string type.
 
#define lite3_ctx_is_obj(ctx, ofs, key)
 Find value by key and test for object type.
 
#define lite3_ctx_is_arr(ctx, ofs, key)
 Find value by key and test for array type.
 
#define lite3_ctx_get(ctx, ofs, key, out)
 Get value from object.
 
#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.
 
#define lite3_ctx_get_f64(ctx, ofs, key, out)
 Get floating point value by key.
 
#define lite3_ctx_get_bytes(ctx, ofs, key, out)
 Get bytes value by key.
 
#define lite3_ctx_get_str(ctx, ofs, key, out)
 Get string value by key.
 
#define lite3_ctx_get_obj(ctx, ofs, key, out)
 Get object by key.
 
#define lite3_ctx_get_arr(ctx, ofs, key, out)
 Get array by key.
 
#define LITE3_ITER_ITEM
 Return value of lite3_ctx_iter_next(); iterator produced an item, continue;.
 
#define LITE3_ITER_DONE
 Return value of lite3_ctx_iter_next(); iterator finished; stop.
 

Typedefs

typedef struct lite3_ctx lite3_ctx
 Lite³ context struct.
 

Functions

lite3_ctxlite3_ctx_create_with_size (size_t bufsz)
 Create context with custom size.
 
lite3_ctxlite3_ctx_create_from_buf (const unsigned char *buf, size_t buflen)
 Create context by copying from a buffer.
 
lite3_ctxlite3_ctx_create_take_ownership (unsigned char *buf, size_t buflen, size_t bufsz)
 Create context by taking ownership of a buffer.
 
static lite3_ctxlite3_ctx_create (void)
 Create context with minimum size.
 
int lite3_ctx_import_from_buf (lite3_ctx *ctx, const unsigned char *buf, size_t buflen)
 Copy data into existing context.
 
void lite3_ctx_destroy (lite3_ctx *ctx)
 Destroy context.
 
static int lite3_ctx_init_obj (lite3_ctx *ctx)
 Initialize a Lite³ context as an object.
 
static int lite3_ctx_init_arr (lite3_ctx *ctx)
 Initialize a Lite³ context as an array.
 
static int lite3_ctx_arr_append_null (lite3_ctx *ctx, size_t ofs)
 Append null to array.
 
static int lite3_ctx_arr_append_bool (lite3_ctx *ctx, size_t ofs, bool value)
 Append boolean to array.
 
static int lite3_ctx_arr_append_i64 (lite3_ctx *ctx, size_t ofs, int64_t value)
 Append integer to array.
 
static int lite3_ctx_arr_append_f64 (lite3_ctx *ctx, size_t ofs, double value)
 Append floating point to array.
 
static int lite3_ctx_arr_append_bytes (lite3_ctx *ctx, size_t ofs, const unsigned char *__restrict bytes, size_t bytes_len)
 Append bytes to array.
 
static int lite3_ctx_arr_append_str (lite3_ctx *ctx, size_t ofs, const char *__restrict str)
 Append string to array.
 
static int lite3_ctx_arr_append_str_n (lite3_ctx *ctx, size_t ofs, const char *__restrict str, size_t str_len)
 Append string to array by length.
 
static int lite3_ctx_arr_append_obj (lite3_ctx *ctx, size_t ofs, size_t *__restrict out_ofs)
 Append object to array.
 
static int lite3_ctx_arr_append_arr (lite3_ctx *ctx, size_t ofs, size_t *__restrict out_ofs)
 Append array to array.
 
static int lite3_ctx_arr_set_null (lite3_ctx *ctx, size_t ofs, uint32_t index)
 Set null in array.
 
static int lite3_ctx_arr_set_bool (lite3_ctx *ctx, size_t ofs, uint32_t index, bool value)
 Set boolean in array.
 
static int lite3_ctx_arr_set_i64 (lite3_ctx *ctx, size_t ofs, uint32_t index, int64_t value)
 Set integer in array.
 
static int lite3_ctx_arr_set_f64 (lite3_ctx *ctx, size_t ofs, uint32_t index, double value)
 Set float in array.
 
static int lite3_ctx_arr_set_bytes (lite3_ctx *ctx, size_t ofs, uint32_t index, const unsigned char *__restrict bytes, size_t bytes_len)
 Set bytes in array.
 
static int lite3_ctx_arr_set_str (lite3_ctx *ctx, size_t ofs, uint32_t index, const char *__restrict str)
 Set string in array.
 
static int lite3_ctx_arr_set_str_n (lite3_ctx *ctx, size_t ofs, uint32_t index, const char *__restrict str, size_t str_len)
 Set string in array by length.
 
static int lite3_ctx_arr_set_obj (lite3_ctx *ctx, size_t ofs, uint32_t index, size_t *__restrict out_ofs)
 Set object in array.
 
static int lite3_ctx_arr_set_arr (lite3_ctx *ctx, size_t ofs, uint32_t index, size_t *__restrict out_ofs)
 Set array in array.
 
static void lite3_ctx_print (lite3_ctx *ctx)
 View the internal structure of a Lite³ buffer.
 
static int lite3_ctx_count (lite3_ctx *ctx, size_t ofs, uint32_t *out)
 Write back the number of object entries or array elements.
 
static int lite3_ctx_arr_get_bool (lite3_ctx *ctx, size_t ofs, uint32_t index, bool *out)
 Get boolean value by index.
 
static int lite3_ctx_arr_get_i64 (lite3_ctx *ctx, size_t ofs, uint32_t index, int64_t *out)
 Get integer value by index.
 
static int lite3_ctx_arr_get_f64 (lite3_ctx *ctx, size_t ofs, uint32_t index, double *out)
 Get floating point value by index.
 
static int lite3_ctx_arr_get_bytes (lite3_ctx *ctx, size_t ofs, uint32_t index, lite3_bytes *out)
 Get bytes value by index.
 
static int lite3_ctx_arr_get_str (lite3_ctx *ctx, size_t ofs, uint32_t index, lite3_str *out)
 Get string value by index.
 
static int lite3_ctx_arr_get_obj (lite3_ctx *ctx, size_t ofs, uint32_t index, size_t *__restrict out_ofs)
 Get object by index.
 
static int lite3_ctx_arr_get_arr (lite3_ctx *ctx, size_t ofs, uint32_t index, size_t *__restrict out_ofs)
 Get array by index.
 
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_dec (lite3_ctx *ctx, const char *__restrict json_str, size_t json_len)
 Convert JSON string to Lite³
 
static int lite3_ctx_json_dec_file (lite3_ctx *ctx, const char *__restrict path)
 Convert JSON from file path to Lite³
 
static int lite3_ctx_json_dec_fp (lite3_ctx *ctx, FILE *fp)
 Convert JSON from file pointer to Lite³
 
static int lite3_ctx_json_print (lite3_ctx *ctx, size_t ofs)
 Print Lite³ buffer as JSON to stdout
 
static char * lite3_ctx_json_enc (lite3_ctx *ctx, size_t ofs, size_t *__restrict out_len)
 Convert Lite³ to JSON string.
 
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 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 int64_t lite3_ctx_json_enc_pretty_buf (lite3_ctx *ctx, size_t ofs, char *__restrict json_buf, size_t json_bufsz)
 Convert Lite³ to prettified JSON and write to output buffer.
 

Detailed Description

Lite³ Context API Header.

Author
Elias de Jong
Date
2025-09-20

Definition in file lite3_context_api.h.