lib/cfl/README.md
CFL is a compact C library of data structures and low-level utilities used by Fluent Bit and its companion telemetry libraries. It provides dynamic strings, intrusive lists, typed variants, arrays, key/value containers, hashing, checksums, atomics, and an optional arena allocator.
CFL started as a C library for Fluent Bit, a.k.a. C:\Floppy.
The library is designed to be embedded. Callers can include the complete public interface with:
#include <cfl/cfl.h>
Individual headers under include/cfl/ can be used when a component needs a
smaller interface.
cfl_variant, cfl_array, and cfl_kvlist.cfl_sds.| Interface | Purpose |
|---|---|
cfl_sds | Growable binary-safe strings with explicit length and capacity |
cfl_list | Intrusive doubly linked lists and safe iteration helpers |
cfl_kv | String key/value entries stored in a CFL list |
cfl_variant | Tagged bool, integer, double, null, reference, string, bytes, array, or map value |
cfl_array | Ordered collection of variants |
cfl_kvlist | String-keyed map of variants |
cfl_object | Generic wrapper for a variant, array, or key/value list |
cfl_arena | Optional shared allocator for bounded CFL object graphs |
Heap-backed constructors remain the default. Applications that construct and
discard complete variant graphs can opt into cfl_arena; see
ARENA.md for its ownership model, API, examples, and tuning advice.
cfl_atomic: 64-bit compare-exchange, store, and load operations with
platform-specific backends.cfl_time: wall-clock timestamps in nanoseconds.cfl_hash: xxHash 64-bit and 128-bit wrappers.cfl_checksum: CRC32C checksums.cfl_utils: string splitting, including quote-aware parsing.cfl_log: runtime error-reporting helpers.cfl_compat, cfl_found, and cfl_info: platform and build integration.CFL requires CMake 3.20 or newer and a C compiler:
cmake -S . -B build
cmake --build build -j8
To build and run the unit tests:
cmake -S . -B build -DCFL_TESTS=On
cmake --build build -j8
ctest --test-dir build --output-on-failure
Useful configuration options are:
| Option | Default | Description |
|---|---|---|
CFL_DEV | No | Enable the debug development configuration and tests |
CFL_TESTS | No | Build unit and public-header tests |
CFL_BENCHMARKS | No | Build allocation and mutation benchmarks |
CFL_INSTALL_BUNDLED_XXHASH_HEADERS | Yes | Install bundled xxHash headers |
For arena performance and memory comparisons, see benchmarks/README.md.
Projects commonly embed CFL with add_subdirectory and link the static target:
add_subdirectory(path/to/cfl)
target_link_libraries(my_target PRIVATE cfl-static)
Applications using installed headers can include either <cfl/cfl.h> or the
specific module headers they require.
cfl_ prefix.NULL when allocation or validation fails.include/cfl/
describe each supported interface.CFL_TESTS and run the suite through CTest as shown above.CFL is distributed under the Apache License 2.0.
Copyright is assigned to the CFL Authors. The contributor list is available on GitHub.