|
Lite³
A JSON-Compatible Zero-Copy Serialization Format
|
Lite³ Buffer API Header. More...
#include <stdint.h>#include <stddef.h>#include <stdbool.h>#include <assert.h>#include <string.h>#include <errno.h>#include <stdio.h>Go to the source code of this file.
Data Structures | |
| struct | lite3_val |
| Struct representing a value inside a Lite³ buffer. More... | |
| struct | lite3_bytes |
| Struct holding a reference to a bytes value inside a Lite³ buffer. More... | |
| struct | lite3_str |
| Struct holding a reference to a string inside a Lite³ buffer. More... | |
| struct | lite3_iter |
| Struct containing iterator state. More... | |
Macros | |
| #define | LITE3_ZERO_MEM_DELETED |
| Overwrite deleted values with NULL bytes (0x00). | |
| #define | LITE3_ZERO_MEM_EXTRA |
| Overwrite any unused bytes inside the Lite³ buffer with NULL bytes (0x00). | |
| #define | LITE3_PREFETCHING |
| Speeds up iterators, but may cause crashes on non-x86 platforms like ARM. | |
| #define | LITE3_ERROR_MESSAGES |
Print library-specific error messages to stdout. | |
| #define | LITE3_DEBUG |
Print library-specific debug information to stdout. | |
| #define | LITE3_BUF_SIZE_MAX |
| Maximum Lite³ buffer size. | |
| #define | LITE3_NODE_ALIGNMENT |
| B-tree node alignment configuration. | |
| #define | LITE3_NODE_SIZE |
| B-tree node size setting. | |
| #define | LITE3_TREE_HEIGHT_MAX |
| Maximum B-tree height. | |
| #define | LITE3_NODE_SIZE_KC_OFFSET |
Offset of the size_kc field inside struct node. | |
| #define | LITE3_KEY_HASH_COMPILE_TIME |
| Macro to calculate DJB2 key hashes at compile-time. | |
| #define | LITE3_BYTES(buf, val) |
| Generational pointer / safe access wrapper. | |
| #define | LITE3_STR(buf, val) |
| Generational pointer / safe access wrapper. | |
| #define | lite3_set_null(buf, inout_buflen, ofs, bufsz, key) |
| Set null in object. | |
| #define | lite3_set_bool(buf, inout_buflen, ofs, bufsz, key, value) |
| Set boolean in object. | |
| #define | lite3_set_i64(buf, inout_buflen, ofs, bufsz, key, value) |
| Set integer in object. | |
| #define | lite3_set_f64(buf, inout_buflen, ofs, bufsz, key, value) |
| Set floating point in object. | |
| #define | lite3_set_bytes(buf, inout_buflen, ofs, bufsz, key, bytes, bytes_len) |
| Set bytes in object. | |
| #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_obj(buf, inout_buflen, ofs, bufsz, key, out_ofs) |
| Set object in object. | |
| #define | lite3_set_arr(buf, inout_buflen, ofs, bufsz, key, out_ofs) |
| Set array in object. | |
| #define | lite3_get_type(buf, buflen, ofs, key) |
| Find value by key and return value type. | |
| #define | lite3_get_type_size(buf, buflen, ofs, key, out) |
| Find value by key and write back type size. | |
| #define | lite3_exists(buf, buflen, ofs, key) |
| Attempt to find a key. | |
| #define | lite3_is_null(buf, buflen, ofs, key) |
| Find value by key and test for null type. | |
| #define | lite3_is_bool(buf, buflen, ofs, key) |
| Find value by key and test for bool type. | |
| #define | lite3_is_i64(buf, buflen, ofs, key) |
| Find value by key and test for integer type. | |
| #define | lite3_is_f64(buf, buflen, ofs, key) |
| Find value by key and test for floating point type. | |
| #define | lite3_is_bytes(buf, buflen, ofs, key) |
| Find value by key and test for bytes type. | |
| #define | lite3_is_str(buf, buflen, ofs, key) |
| Find value by key and test for string type. | |
| #define | lite3_is_obj(buf, buflen, ofs, key) |
| Find value by key and test for object type. | |
| #define | lite3_is_arr(buf, buflen, ofs, key) |
| Find value by key and test for array type. | |
| #define | lite3_get(buf, buflen, ofs, key, out) |
| Get value from object. | |
| #define | lite3_get_bool(buf, buflen, ofs, key, out) |
| Get boolean value by key. | |
| #define | lite3_get_i64(buf, buflen, ofs, key, out) |
| Get integer value by key. | |
| #define | lite3_get_f64(buf, buflen, ofs, key, out) |
| Get floating point value by key. | |
| #define | lite3_get_bytes(buf, buflen, ofs, key, out) |
| Get bytes value by key. | |
| #define | lite3_get_str(buf, buflen, ofs, key, out) |
| Get string value by key. | |
| #define | lite3_get_obj(buf, buflen, ofs, key, out) |
| Get object by key. | |
| #define | lite3_get_arr(buf, buflen, ofs, key, out) |
| Get array by key. | |
| #define | LITE3_ITER_ITEM |
Return value of lite3_iter_next(); iterator produced an item, continue;. | |
| #define | LITE3_ITER_DONE |
Return value of lite3_iter_next(); iterator finished; stop. | |
| #define | LITE3_JSON |
| Enable JSON-related functions for conversion between Lite³ and JSON. | |
| #define | LITE3_JSON_NESTING_DEPTH_MAX |
| Maximum nesting limit for JSON documents being encoded or decoded. | |
Enumerations | |
| enum | lite3_type { LITE3_TYPE_NULL , LITE3_TYPE_BOOL , LITE3_TYPE_I64 , LITE3_TYPE_F64 , LITE3_TYPE_BYTES , LITE3_TYPE_STRING , LITE3_TYPE_OBJECT , LITE3_TYPE_ARRAY , LITE3_TYPE_INVALID , LITE3_TYPE_COUNT } |
enum containing all Lite³ types More... | |
Functions | |
| int | lite3_init_obj (unsigned char *buf, size_t *__restrict out_buflen, size_t bufsz) |
| Initialize a Lite³ buffer as an object. | |
| int | lite3_init_arr (unsigned char *buf, size_t *__restrict out_buflen, size_t bufsz) |
| Initialize a Lite³ buffer as an array. | |
| static int | lite3_arr_append_null (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz) |
| Append null to array. | |
| static int | lite3_arr_append_bool (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, bool value) |
| Append boolean to array. | |
| static int | lite3_arr_append_i64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, int64_t value) |
| Append integer to array. | |
| static int | lite3_arr_append_f64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, double value) |
| Append floating point to array. | |
| static int | lite3_arr_append_bytes (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, const unsigned char *__restrict bytes, size_t bytes_len) |
| Append bytes to array. | |
| static int | lite3_arr_append_str (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, const char *__restrict str) |
| Append string to array. | |
| static int | lite3_arr_append_str_n (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, const char *__restrict str, size_t str_len) |
| Append string to array by length. | |
| static int | lite3_arr_append_obj (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, size_t *__restrict out_ofs) |
| Append object to array. | |
| static int | lite3_arr_append_arr (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, size_t *__restrict out_ofs) |
| Append array to array. | |
| static int | lite3_arr_set_null (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index) |
| Set null in array. | |
| static int | lite3_arr_set_bool (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, bool value) |
| Set boolean in array. | |
| static int | lite3_arr_set_i64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, int64_t value) |
| Set integer in array. | |
| static int | lite3_arr_set_f64 (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, double value) |
| Set float in array. | |
| static int | lite3_arr_set_bytes (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, const unsigned char *__restrict bytes, size_t bytes_len) |
| Set bytes in array. | |
| static int | lite3_arr_set_str (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, const char *__restrict str) |
| Set string in array. | |
| static int | lite3_arr_set_str_n (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, const char *__restrict str, size_t str_len) |
| Set string in array by length. | |
| static int | lite3_arr_set_obj (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, size_t *__restrict out_ofs) |
| Set object in array. | |
| static int | lite3_arr_set_arr (unsigned char *buf, size_t *__restrict inout_buflen, size_t ofs, size_t bufsz, uint32_t index, size_t *__restrict out_ofs) |
| Set array in array. | |
| static int | lite3_count (unsigned char *buf, size_t buflen, size_t ofs, uint32_t *out) |
| Write back the number of object entries or array elements. | |
| static int | lite3_arr_get_bool (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, bool *out) |
| Get boolean value by index. | |
| static int | lite3_arr_get_i64 (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, int64_t *out) |
| Get integer value by index. | |
| static int | lite3_arr_get_f64 (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, double *out) |
| Get floating point value by index. | |
| static int | lite3_arr_get_bytes (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, lite3_bytes *out) |
| Get bytes value by index. | |
| static int | lite3_arr_get_str (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, lite3_str *out) |
| Get string value by index. | |
| static int | lite3_arr_get_obj (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, size_t *__restrict out_ofs) |
| Get object by index. | |
| static int | lite3_arr_get_arr (const unsigned char *buf, size_t buflen, size_t ofs, uint32_t index, size_t *__restrict out_ofs) |
| Get array by index. | |
| static int | lite3_iter_create (const unsigned char *buf, size_t buflen, size_t ofs, lite3_iter *out) |
| Create a lite3 iterator for the given object or array. | |
| int | lite3_iter_next (const unsigned char *buf, size_t buflen, lite3_iter *iter, lite3_str *out_key, size_t *out_val_ofs) |
| Get the next item from a lite3 iterator. | |
| static enum lite3_type | lite3_val_type (lite3_val *val) |
Returns the value type of *val | |
| static size_t | lite3_val_type_size (lite3_val *val) |
| Returns the size of the value type. | |
| static bool | lite3_val_is_null (lite3_val *val) |
| static bool | lite3_val_is_bool (lite3_val *val) |
| static bool | lite3_val_is_i64 (lite3_val *val) |
| static bool | lite3_val_is_f64 (lite3_val *val) |
| static bool | lite3_val_is_bytes (lite3_val *val) |
| static bool | lite3_val_is_str (lite3_val *val) |
| static bool | lite3_val_is_obj (lite3_val *val) |
| static bool | lite3_val_is_arr (lite3_val *val) |
| static bool | lite3_val_bool (lite3_val *val) |
| static int64_t | lite3_val_i64 (lite3_val *val) |
| static double | lite3_val_f64 (lite3_val *val) |
| static const char * | lite3_val_str (lite3_val *val) |
| static const char * | lite3_val_str_n (lite3_val *val, size_t *out_len) |
| static const unsigned char * | lite3_val_bytes (lite3_val *val, size_t *out_len) |
| int | lite3_json_dec (unsigned char *buf, size_t *__restrict out_buflen, size_t bufsz, const char *__restrict json_str, size_t json_len) |
| Convert JSON string to Lite³ | |
| int | lite3_json_dec_file (unsigned char *buf, size_t *__restrict out_buflen, size_t bufsz, const char *__restrict path) |
| Convert JSON from file path to Lite³ | |
| int | lite3_json_dec_fp (unsigned char *buf, size_t *__restrict out_buflen, size_t bufsz, FILE *fp) |
| Convert JSON from file pointer to Lite³ | |
| int | lite3_json_print (const unsigned char *buf, size_t buflen, size_t ofs) |
Print Lite³ buffer as JSON to stdout | |
| char * | lite3_json_enc (const unsigned char *buf, size_t buflen, size_t ofs, size_t *__restrict out_len) |
| Convert Lite³ to JSON string. | |
| char * | lite3_json_enc_pretty (const unsigned char *buf, size_t buflen, size_t ofs, size_t *__restrict out_len) |
| Convert Lite³ to JSON prettified string. | |
| int64_t | lite3_json_enc_buf (const unsigned char *buf, size_t buflen, size_t ofs, char *__restrict json_buf, size_t json_bufsz) |
| Convert Lite³ to JSON and write to output buffer. | |
| int64_t | lite3_json_enc_pretty_buf (const unsigned char *buf, size_t buflen, size_t ofs, char *__restrict json_buf, size_t json_bufsz) |
| Convert Lite³ to prettified JSON and write to output buffer. | |
Lite³ Buffer API Header.
Definition in file lite3.h.