ALEC FFI - C/C++ Bindings
C/C++ bindings for the ALEC (Adaptive Lazy Evolving Compression) library.
Overview
This crate provides a C-compatible FFI layer for ALEC, enabling use from C/C++ firmware and embedded systems.
Quick Start
C Example
int
Building
Build the Library
This produces:
target/release/libalec.a- Static librarytarget/release/libalec.so(Linux) /libalec.dylib(macOS) - Shared library
Compile C Code
With static linking:
With dynamic linking:
# Set library path before running
API Reference
Types
| Type | Description |
|---|---|
AlecEncoder* |
Opaque encoder handle |
AlecDecoder* |
Opaque decoder handle |
AlecResult |
Result code enum |
Result Codes
| Code | Value | Description |
|---|---|---|
ALEC_OK |
0 | Success |
ALEC_ERROR_INVALID_INPUT |
1 | Invalid input data |
ALEC_ERROR_BUFFER_TOO_SMALL |
2 | Output buffer too small |
ALEC_ERROR_ENCODING_FAILED |
3 | Encoding failed |
ALEC_ERROR_DECODING_FAILED |
4 | Decoding failed |
ALEC_ERROR_NULL_POINTER |
5 | NULL pointer provided |
ALEC_ERROR_INVALID_UTF8 |
6 | Invalid UTF-8 string |
ALEC_ERROR_FILE_IO |
7 | File I/O error |
ALEC_ERROR_VERSION_MISMATCH |
8 | Context version mismatch |
Encoder Functions
// Create/destroy
AlecEncoder* ;
AlecEncoder* ;
void ;
// Encoding
AlecResult ;
AlecResult ;
// Context management
AlecResult ;
AlecResult ;
uint32_t ;
Decoder Functions
// Create/destroy
AlecDecoder* ;
AlecDecoder* ;
void ;
// Decoding
AlecResult ;
AlecResult ;
// Context management
AlecResult ;
uint32_t ;
Utility Functions
const char* ;
const char* ;
Using Preloads
Preloads allow instant optimal compression by loading pre-trained contexts:
// Encoder side
AlecEncoder* enc = ;
;
// Decoder side (must use same preload!)
AlecDecoder* dec = ;
;
Cross-Compilation
ARM Cortex-M4
ARM Cortex-M0
Note: Cross-compilation for no_std targets requires additional configuration in the core ALEC library.
Thread Safety
- Each encoder/decoder instance is not thread-safe
- Use separate instances for each thread, or protect access with mutexes
- The library itself has no global state
Memory Management
- All
*_new()functions allocate memory - All
*_free()functions deallocate memory - Never use a handle after calling its
*_free()function - Passing
NULLto*_free()functions is safe (no-op)
License
AGPL-3.0 or Commercial License. See LICENSE file for details.