Lite³
A JSON-Compatible Zero-Copy Serialization Format
Loading...
Searching...
No Matches
lite3_str Struct Reference

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
 

Detailed Description

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.

Warning
The 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!

Definition at line 601 of file lite3.h.

Field Documentation

◆ gen

uint32_t lite3_str::gen

generation of the Lite³ buffer when this struct was returned

Definition at line 602 of file lite3.h.

◆ len

uint32_t lite3_str::len

char array length (characters, exclusive of NULL-terminator)

Definition at line 603 of file lite3.h.

◆ ptr

const char* lite3_str::ptr

char array pointer to string inside Lite³ buffer

Definition at line 604 of file lite3.h.


The documentation for this struct was generated from the following file: