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

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
 

Detailed Description

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!

Definition at line 572 of file lite3.h.

Field Documentation

◆ gen

uint32_t lite3_bytes::gen

generation of the Lite³ buffer when this struct was returned

Definition at line 573 of file lite3.h.

◆ len

uint32_t lite3_bytes::len

byte array length (bytes)

Definition at line 574 of file lite3.h.

◆ ptr

const unsigned char* lite3_bytes::ptr

byte array pointer to bytes inside Lite³ buffer

Definition at line 575 of file lite3.h.


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