|
Lite³
A JSON-Compatible Zero-Copy Serialization Format
|
Conversion between Lite³ and JSON. More...
Functions | |
| 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. | |
Conversion between Lite³ and JSON.
All JSON functionality is enabled internally by the yyjson library.
JSON encode functions read buflen to know the currently used portion of the buffer.
The ofs (offset) field is used to target an object or array inside the Lite³ buffer. To target the root-level object/array, use ofs == 0.
int64_t.double with correct rounding.int64_t, it is converted to double.double number overflows (reaches infinity), an error is returned.See: enum lite3_type
Makefile for more details. Also LITE3_JSON must be defined inside the lite3.h header or using compiler -D flags. See Library Configuration Options.| 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³
The number of bytes written to *buf never exceeds bufsz.
malloc(). | [in] | buf | Lite³ buffer pointer |
| [out] | out_buflen | buffer used length (bytes, out value) |
| [in] | bufsz | buffer max size (bytes) |
| [in] | json_str | JSON input string (string) |
| [in] | json_len | JSON input string length (bytes, including or excluding NULL-terminator) |
| 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³
The number of bytes written to *buf never exceeds bufsz.
malloc(). | [in] | buf | Lite³ buffer pointer |
| [out] | out_buflen | buffer used length (bytes, out value) |
| [in] | bufsz | buffer max size (bytes) |
| [in] | path | JSON file path (string) |
| 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³
The number of bytes written to *buf never exceeds bufsz.
malloc(). | [in] | buf | Lite³ buffer pointer |
| [out] | out_buflen | buffer used length (bytes, out value) |
| [in] | bufsz | buffer max size (bytes) |
| [in] | fp | JSON file pointer |
| 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 * pointer to the JSON string on success NULL on errormalloc().LITE3_TYPE_BYTES are automatically converted to a base64 string.free() on the pointer returned by this function. | [in] | buf | Lite³ buffer |
| [in] | buflen | buffer used length (bytes) |
| [in] | ofs | start offset (0 == root) |
| [out] | out_len | string length excluding NULL-terminator (if not needed, pass NULL) |
| 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.
malloc().LITE3_TYPE_BYTES are automatically converted to a base64 string. | [in] | buf | Lite³ buffer |
| [in] | buflen | Lite³ buffer used length (bytes) |
| [in] | ofs | start offset (0 == root) |
| [in] | json_buf | JSON output buffer |
| [in] | json_bufsz | JSON output buffer max size (bytes) |
| 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.
The prettified string uses a tab space indent of 4.
char * pointer to the JSON string on success NULL on errormalloc().LITE3_TYPE_BYTES are automatically converted to a base64 string.free() on the pointer returned by this function. | [in] | buf | Lite³ buffer |
| [in] | buflen | Lite³ buffer used length (bytes) |
| [in] | ofs | start offset (0 == root) |
| [out] | out_len | string length excluding NULL-terminator (if not needed, pass NULL) |
| 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.
The prettified string uses a tab space indent of 4.
malloc().LITE3_TYPE_BYTES are automatically converted to a base64 string. | [in] | buf | Lite³ buffer |
| [in] | buflen | Lite³ buffer used length (bytes) |
| [in] | ofs | start offset (0 == root) |
| [in] | json_buf | JSON output buffer |
| [in] | json_bufsz | JSON output buffer max size (bytes) |
| int lite3_json_print | ( | const unsigned char * | buf, |
| size_t | buflen, | ||
| size_t | ofs | ||
| ) |
Print Lite³ buffer as JSON to stdout
Very useful to make Lite³ structures human-readable inside a terminal. The ofs parameter can be used to selectively print an internal object or array. To print out the entire structure, call from the root using ofs == 0.
malloc().LITE3_TYPE_BYTES are automatically converted to a base64 string. | [in] | buf | Lite³ buffer |
| [in] | buflen | buffer used length (bytes) |
| [in] | ofs | start offset (0 == root) |