Lite³
A JSON-Compatible Zero-Copy Serialization Format
Loading...
Searching...
No Matches
Library Custom Types

Custom types of the Lite³ library. More...

Data Structures

struct  lite3_val
 Struct representing a value inside a Lite³ buffer. More...
 
struct  lite3_bytes
 Struct holding a reference to a bytes value inside a Lite³ buffer. More...
 
struct  lite3_str
 Struct holding a reference to a string inside a Lite³ buffer. More...
 
struct  lite3_iter
 Struct containing iterator state. More...
 
struct  lite3_ctx
 Lite³ context struct. More...
 

Macros

#define LITE3_BYTES(buf, val)
 Generational pointer / safe access wrapper.
 
#define LITE3_STR(buf, val)
 Generational pointer / safe access wrapper.
 

Typedefs

typedef struct lite3_ctx lite3_ctx
 Lite³ context struct.
 

Enumerations

enum  lite3_type {
  LITE3_TYPE_NULL , LITE3_TYPE_BOOL , LITE3_TYPE_I64 , LITE3_TYPE_F64 ,
  LITE3_TYPE_BYTES , LITE3_TYPE_STRING , LITE3_TYPE_OBJECT , LITE3_TYPE_ARRAY ,
  LITE3_TYPE_INVALID , LITE3_TYPE_COUNT
}
 enum containing all Lite³ types More...
 

Detailed Description

Custom types of the Lite³ library.

Macro Definition Documentation

◆ LITE3_BYTES

#define LITE3_BYTES (   buf,
  val 
)

Generational pointer / safe access wrapper.

Every Lite³ buffer stores a generation count which is incremented on every mutation. lite3_bytes accessed through the LITE3_BYTES() macro will return a direct pointer if lite3_bytes.gen matches the generation count of the buffer. Othewise, it returns NULL.

When a Lite³ structure is modified via set() or delete(), pointed to data could be moved or deleted; therefore it is no longer safe to dereference previously obtained pointers. This macro prevents dangerous situations with dangling pointers.

Example usage:

lite3_str data;
if (lite3_get_bytes(buf, buflen, 0, "data_field", &data) < 0)
return 1;
memcpy(dest_ptr, data.ptr, data.len); // ❌ Unsafe! Always use wrapper macro!
memcpy(dest_ptr, LITE3_BYTES(buf, data), data.len); // ✅ Safe dereference
// For context API: LITE3_BYTES(ctx->buf, data)
#define lite3_get_bytes(buf, buflen, ofs, key, out)
Get bytes value by key.
Definition lite3.h:2244
#define LITE3_BYTES(buf, val)
Generational pointer / safe access wrapper.
Definition lite3.h:637
Struct holding a reference to a string inside a Lite³ buffer.
Definition lite3.h:601
uint32_t len
char array length (characters, exclusive of NULL-terminator)
Definition lite3.h:603
const char * ptr
char array pointer to string inside Lite³ buffer
Definition lite3.h:604
Parameters
[in]bufthe Lite³ buffer to which lite3_bytes is pointing
[in]valthe lite3_bytes struct (passed by value, not by reference)

Definition at line 637 of file lite3.h.

◆ LITE3_STR

#define LITE3_STR (   buf,
  val 
)

Generational pointer / safe access wrapper.

Every Lite³ buffer stores a generation count which is incremented on every mutation. lite3_str accessed through the LITE3_STR() macro will return a direct pointer if lite3_str.gen matches the generation count of the buffer. Othewise, it returns NULL.

When a Lite³ structure is modified via set() or delete(), pointed to data could be moved or deleted; therefore it is no longer safe to dereference previously obtained pointers. This macro prevents dangerous situations with dangling pointers.

Example usage:

if (lite3_get_str(buf, buflen, 0, "str_field", &str) < 0)
return 1;
memcpy(dest_ptr, str.ptr, str.len); // ❌ Unsafe! Always use wrapper macro!
memcpy(dest_ptr, LITE3_STR(buf, str), str.len); // ✅ Safe dereference
// For context API: LITE3_STR(ctx->buf, str)
#define lite3_get_str(buf, buflen, ofs, key, out)
Get string value by key.
Definition lite3.h:2284
#define LITE3_STR(buf, val)
Generational pointer / safe access wrapper.
Definition lite3.h:666
Parameters
[in]bufthe Lite³ buffer to which lite3_str is pointing
[in]valthe lite3_str struct (passed by value, not by reference)

Definition at line 666 of file lite3.h.

Typedef Documentation

◆ lite3_ctx

typedef struct lite3_ctx lite3_ctx

Lite³ context struct.

See Context API.

Enumeration Type Documentation

◆ lite3_type

enum lite3_type

enum containing all Lite³ types

Lite³ prefixes all values with a 1-byte type tag, similar to tagged unions.

Enumerator
LITE3_TYPE_NULL 

maps to 'null' type in JSON

LITE3_TYPE_BOOL 

maps to 'boolean' type in JSON; underlying datatype: bool

LITE3_TYPE_I64 

maps to 'number' type in JSON; underlying datatype: int64_t

LITE3_TYPE_F64 

maps to 'number' type in JSON; underlying datatype: double

LITE3_TYPE_BYTES 

coverted to base64 string in JSON

LITE3_TYPE_STRING 

maps to 'string' type in JSON

LITE3_TYPE_OBJECT 

maps to 'object' type in JSON

LITE3_TYPE_ARRAY 

maps to 'array' type in JSON

LITE3_TYPE_INVALID 

any type value equal or greater than this is considered invalid

LITE3_TYPE_COUNT 

not an actual type, only used for counting

Definition at line 510 of file lite3.h.