C API
The C ABI is declared in crates/ffi/include/predsync.h. The complete generated
reference is here.
Regenerate the header with pixi run c-header; pixi run c-header-check fails
if it is stale.
Handle and status model
Every entry point returns a PredsyncStatus. Ok means success; other values
are NullPointer, InvalidSchema, InvalidHandle, BufferTooSmall,
InvalidValue, EncodeError, DecodeError and Panic. Encode and decode
functions also write a detailed error code into a caller-provided uint32_t.
All objects are opaque handles:
PredsyncSetowns a parsed schema set.PredsyncEncoderandPredsyncDecoderown one engine each.PredsyncDecodedowns one decoded frame until freed.PredsyncRegistryowns custom predictor callbacks.
Free handles in reverse order with predsync_set_free,
predsync_encoder_free, predsync_decoder_free, predsync_decoded_free and
predsync_registry_free. No function takes ownership of caller memory.
Values
A PredsyncValue is a tagged union represented as a plain struct:
| Field | Meaning |
|---|---|
kind | Scalar, Str or List. |
element | Scalar type of a scalar or list element, including Enum for a variant index. |
scalar | Eight-byte slot bits for a scalar. |
ptr | Borrowed bytes for a string or slot bits for a list. |
len | Byte count for a string, element count for a list. |
cap | Capacity of caller-owned decode storage. |
On encode, ptr is borrowed for the duration of predsync_encode. On decode,
set cap to your buffer capacity; the library returns BufferTooSmall rather
than writing past it.
Minimal sequence
PredsyncSet *set = NULL;
PredsyncEncoder *encoder = NULL;
uint8_t frame[256];
uintptr_t frame_len = 0;
uint32_t error = 0;
PredsyncEncodeInfo info;
if (predsync_set_from_yaml(yaml, yaml_len, &set) != Ok) { /* handle error */ }
if (predsync_encoder_new(set, 0, 1'000'000ULL, 0xffffu, &encoder) != Ok) { /* ... */ }
if (predsync_encode(encoder, values, field_count, now_ns,
frame, sizeof(frame), &frame_len, &info, &error) != Ok) { /* ... */ }
0xffff for max_resets_per_frame selects the library default. The frame bytes
are the first frame_len entries of frame; pass exactly that slice to
predsync_decode_feed.
A complete program is in examples/c/quickstart.c. It is compiled with
-Wall -Wextra -Werror and run by pixi run c-abi.
Generated typed wrappers
For demo schemas, the compiler also emits demo_telemetry_pack,
demo_telemetry_unpack, DemoTelemetry and DemoTelemetryMode. The pack
helper writes into caller-owned PredsyncValue storage and a scratch word
array; the unpack helper fills a fixed-capacity struct. These wrappers are
generated from the same schema as the Rust and Python classes.
Safety notes
C callbacks for custom predictors must be deterministic and must not call back
into the encoder or decoder. The FFI layer catches Rust panics and returns
Panic, but a callback that mutates shared state from another thread is still a
caller error. Each entry point documents its preconditions in the header.