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

Configuration options for the Lite³ library. More...

Macros

#define LITE3_ZERO_MEM_DELETED
 Overwrite deleted values with NULL bytes (0x00).
 
#define LITE3_ZERO_MEM_EXTRA
 Overwrite any unused bytes inside the Lite³ buffer with NULL bytes (0x00).
 
#define LITE3_PREFETCHING
 Speeds up iterators, but may cause crashes on non-x86 platforms like ARM.
 
#define LITE3_ERROR_MESSAGES
 Print library-specific error messages to stdout.
 
#define LITE3_DEBUG
 Print library-specific debug information to stdout.
 
#define LITE3_BUF_SIZE_MAX
 Maximum Lite³ buffer size.
 
#define LITE3_NODE_ALIGNMENT
 B-tree node alignment configuration.
 
#define LITE3_NODE_SIZE
 B-tree node size setting.
 
#define LITE3_TREE_HEIGHT_MAX
 Maximum B-tree height.
 
#define LITE3_NODE_SIZE_KC_OFFSET
 Offset of the size_kc field inside struct node.
 
#define LITE3_KEY_HASH_COMPILE_TIME
 Macro to calculate DJB2 key hashes at compile-time.
 
#define LITE3_JSON
 Enable JSON-related functions for conversion between Lite³ and JSON.
 
#define LITE3_JSON_NESTING_DEPTH_MAX
 Maximum nesting limit for JSON documents being encoded or decoded.
 
#define LITE3_CONTEXT_BUF_SIZE_MIN
 The minimum buffer size for a Lite³ context.
 

Detailed Description

Configuration options for the Lite³ library.

Configuration options can be toggled either by manually (un)commenting #define inside the header include/lite3.h, or by passing -D flags to your compiler.

For example, library error messages are disabled by default. However it is recommended to enable them to receive feedback during development. To do this, either:

  1. uncomment the line // #define LITE3_ERROR_MESSAGES inside the header file: include/lite3.h
  2. build the library using compilation flag -DLITE3_ERROR_MESSAGES

Macro Definition Documentation

◆ LITE3_BUF_SIZE_MAX

#define LITE3_BUF_SIZE_MAX

Maximum Lite³ buffer size.

Because of 32-bit indexes used inside the structure, Lite³ can only physically support a size up to UINT32_MAX. For safety reasons or to preserve resources, it may be desirable to set a lower maximum size.

Definition at line 259 of file lite3.h.

◆ LITE3_CONTEXT_BUF_SIZE_MIN

#define LITE3_CONTEXT_BUF_SIZE_MIN

The minimum buffer size for a Lite³ context.

Must be greater than LITE3_NODE_ALIGNMENT

Definition at line 130 of file lite3_context_api.h.

◆ LITE3_DEBUG

#define LITE3_DEBUG

Print library-specific debug information to stdout.

Disabled by default.

The output mainly consists of print statements for every value that gets inserted. Enabling this also turns on LITE3_ZERO_MEM_DELETED and LITE3_ZERO_MEM_EXTRA features to make the binary structure more readable in memory.

Also enables the function lite3_print(const unsigned char *buf, size_t buflen) to view the internal structure of Lite³ buffers.

Definition at line 225 of file lite3.h.

◆ LITE3_ERROR_MESSAGES

#define LITE3_ERROR_MESSAGES

Print library-specific error messages to stdout.

Disabled by default.

It is recommended to enable this during development.

Definition at line 200 of file lite3.h.

◆ LITE3_JSON

#define LITE3_JSON

Enable JSON-related functions for conversion between Lite³ and JSON.

Definition at line 2811 of file lite3.h.

◆ LITE3_JSON_NESTING_DEPTH_MAX

#define LITE3_JSON_NESTING_DEPTH_MAX

Maximum nesting limit for JSON documents being encoded or decoded.

Default: 32

The conversion process is recursive and could otherwise risk a stack overflow with too many nesting layers.

Definition at line 2828 of file lite3.h.

◆ LITE3_KEY_HASH_COMPILE_TIME

#define LITE3_KEY_HASH_COMPILE_TIME

Macro to calculate DJB2 key hashes at compile-time.

Lite³ compares hash digest of keys instead of direct string comparisons. The hashes are stored inside the nodes of the B-tree, and the algorithm will traverse them to find a given key.

Calculating such key hashes adds runtime cost and is inside the critical path for tree traversal. Fortunately, for string literals we can calculate them at compile time and eliminate the runtime cost completely. This technique makes the API somewhat macro-heavy, but the savings are significant enough to justify it.

One downside is that this can noticably increase compile times due to pressure on the preprocessor. Therefore this feature can be disabled to speed up build times during development.

Definition at line 375 of file lite3.h.

◆ LITE3_NODE_ALIGNMENT

#define LITE3_NODE_ALIGNMENT

B-tree node alignment configuration.

Set to 4-byte alignment by default. For the vast majority of applications, this setting should never need changing.

This determines the alignment at which nodes are placed inside a Lite³ buffer. *buf pointers passed to Lite³ functions must also be N-byte aligned according to LITE3_NODE_ALIGNMENT. The minimum alignment is 4 bytes according to the struct's largest member variable (uint32_t). A higher alignment setting will insert more padding and increase total message size.

An alignment can be chosen such that nodes always start on cache line boundaries. In this case, the alignment should equal the cache line size of the target architecture (usually 64 bytes). Unlike node size, this setting can be changed without loss of compatibility with other configurations.

Keep in mind that in many cases, the message bloat from increased padding will worsen performance more than any benefit from aligned node access.

How to change: uncomment the preferred setting.

Warning
On 64-bit machines, libc malloc() only guarantees 16-byte alignment for allocations >= 16 byte. Using the default alignment, this should not be a problem. However, increasing the alignment setting might need specially aligned allocations. Failing to do so is confirmed to cause crashes on x86-64 with compiler optimizations enabled.
Stack alignment only works for global or static variables. Example of a properly aligned stack buffer (fixed-size only):
unsigned char buf[1024] __attribute__((aligned(LITE3_NODE_ALIGNMENT)));
#define LITE3_NODE_ALIGNMENT
B-tree node alignment configuration.
Definition lite3.h:299
For heap allocation, use manually aligned pointers or aligned_alloc():
unsigned char *buf = aligned_alloc(LITE3_NODE_ALIGNMENT, 1024);
if (!buf) {
// handle allocation error
}
In builds compiled with -DNDEBUG there are no assert() protections against unaligned access potentially triggering a crash.

@important Do not change this setting unless performance profiling shows real improvements and you know what you are doing.

Definition at line 299 of file lite3.h.

◆ LITE3_NODE_SIZE

#define LITE3_NODE_SIZE

B-tree node size setting.

Set to 96 bytes (1.5 cache lines) by default. For the vast majority of applications, this setting should never need changing.

Note
Changing this setting also requires changing other settings. See struct node inside lite3.c for more info.

@important Do not change this setting unless performance profiling shows real improvements and you know what you are doing.

Definition at line 321 of file lite3.h.

◆ LITE3_NODE_SIZE_KC_OFFSET

#define LITE3_NODE_SIZE_KC_OFFSET

Offset of the size_kc field inside struct node.

Can only be changed together with LITE3_NODE_SIZE.

Note
Changing this setting also requires changing other settings. See struct node inside lite3.c for more info.

Definition at line 350 of file lite3.h.

◆ LITE3_PREFETCHING

#define LITE3_PREFETCHING

Speeds up iterators, but may cause crashes on non-x86 platforms like ARM.

Enabled by default.

This may happen when:

  1. reading near unallocated page boundaries
  2. untrusted messages contain invalid offsets

Definition at line 184 of file lite3.h.

◆ LITE3_TREE_HEIGHT_MAX

#define LITE3_TREE_HEIGHT_MAX

Maximum B-tree height.

Limits the number of node traversals during a lookup. Can only be changed together with LITE3_NODE_SIZE.

Note
Changing this setting also requires changing other settings. See struct node inside lite3.c for more info.

Definition at line 336 of file lite3.h.

◆ LITE3_ZERO_MEM_DELETED

#define LITE3_ZERO_MEM_DELETED

Overwrite deleted values with NULL bytes (0x00).

Enabled by default.

This is a safety feature since not doing so would leave 'deleted' entries intact inside the datastructure until they are overwritten by other values. Disable if you do not care about leaking deleted data.

Note
When following canoncial encoding rules, features LITE3_ZERO_MEM_DELETED and LITE3_ZERO_MEM_EXTRA are required.

Definition at line 152 of file lite3.h.

◆ LITE3_ZERO_MEM_EXTRA

#define LITE3_ZERO_MEM_EXTRA

Overwrite any unused bytes inside the Lite³ buffer with NULL bytes (0x00).

Enabled by default.

This is a safety feature to prevent leaking uninitialized memory bytes into messages. It is also useful for debugging, as it makes the structure a lot more readable. If you plan to use compression, this option makes Lite³ structures achieve better compression ratios.

Note
When following canoncial encoding rules, features LITE3_ZERO_MEM_DELETED and LITE3_ZERO_MEM_EXTRA are required.

Definition at line 169 of file lite3.h.