|
Lite³
A JSON-Compatible Zero-Copy Serialization Format
|
Struct holding a reference to a string 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 |
| char array length (characters, exclusive of NULL-terminator) | |
| const char * | ptr |
| char array pointer to string inside Lite³ buffer | |
Struct holding a reference to a string inside a Lite³ buffer.
Returned by lite3_get_str() and lite3_ctx_get_str().
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_STR(buf, lite3_str). 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.
len struct member is exclusive of the NULL-terminator.@important Never dereference .ptr directly! Always use LITE3_STR(buf, lite3_str) macro wrapper for safe access!
| uint32_t lite3_str::gen |
| uint32_t lite3_str::len |
| const char* lite3_str::ptr |