|
Lite³
A JSON-Compatible Zero-Copy Serialization Format
|
Struct holding a reference to a bytes value inside a Lite³ buffer. More...
#include <lite3.h>
Data Fields | |
| uint32_t | gen |
| generation of the Lite³ buffer when this struct was returned | |
| uint32_t | len |
| byte array length (bytes) | |
| const unsigned char * | ptr |
| byte array pointer to bytes inside Lite³ buffer | |
Struct holding a reference to a bytes value inside a Lite³ buffer.
Returned by lite3_get_bytes() and lite3_ctx_get_bytes().
Lite³ buffers store an internal 'generation count'. Any mutations to the buffer will increment the count.
This struct contains a gen field equal to the generation of the Lite³ buffer when this struct was returned. When the gen field of the reference does not match the buffer's generation count, this means the reference is invalid. We can mitigate 'dangling pointer' scenarios by wrapping the reference with a macro: LITE3_BYTES(buf, lite3_bytes). This macro checks if the buffer's generation count still matches the reference. If so, we return a direct pointer. Otherwise, we receive a NULL pointer.
@important Never dereference .ptr directly! Always use LITE3_BYTES(buf, lite3_bytes) macro wrapper for safe access!
| uint32_t lite3_bytes::gen |
| const unsigned char* lite3_bytes::ptr |