|
Lite³
A JSON-Compatible Zero-Copy Serialization Format
|
Context API. More...
Modules | |
| Iterators | |
| Create and use iterators for objects/arrays. | |
| Managing Contexts | |
| Managing Contexts. | |
| Object / Array Initialization | |
| Object / array initialization. | |
| Object Set | |
| Set key-value pair in object. | |
| Array Append | |
| Append value to array. | |
| Array Set | |
| Set (or overwrite) value in array. | |
| Utility Functions | |
| Utility functions. | |
| Object Get | |
| Get value from object by key. | |
| Array Get | |
| Get value from array by index. | |
| Iterators | |
| Create and use iterators for objects/arrays. | |
| JSON Conversion | |
| Conversion between Lite³ and JSON. | |
Context API.
Lite³ provides an alternative API called the 'Context API'. Compared to the Buffer API, this API represents a more accessible alternative where memory allocations are hidden from the user, providing all the same functionality without requiring manual buffer management.
Contexts are containers for Lite³ buffers, containing a single buffer for a single message. Instead of buffers being passed directly, functions take a *ctx variable as argument. The context will automatically resize when needed, similar to std::vector in C++.
If you want to access the buffer inside of a context, you can like so:
There is also a ctx->bufsz member that stores the total capacity inside the allocation. Contexts start out with a size of LITE3_CONTEXT_BUF_SIZE_MIN (default: 1024) and will reallocate 4X the current capacity if they run out of space. This happens automatically, though you might occasionally see error messages in your terminal when this happens:
This is nothing to worry about, as the context will use these errors to grow its size.
LITE3_NODE_ALIGNMENT alignment during (re)allocation (see lite3_node_alignment).-1 and set errno to one of several values:| Err | Hex | Var | Description |
|---|---|---|---|
| 2 | 0x02 | ENOENT | No such file or directory |
| 5 | 0x05 | EIO | Input/output error |
| 14 | 0x0e | EFAULT | Bad address |
| 22 | 0x16 | EINVAL | Invalid argument |
| 74 | 0x4a | EBADMSG | Bad message |
| 75 | 0x4b | EOVERFLOW | Value too large for defined data type |
| 90 | 0x5a | EMSGSIZE | Message too long |
| 105 | 0x69 | ENOBUFS | No buffer space available |
struct Point p = { .x = 1, .y = 2 };C11: