API reference
predsync exposes the same protocol through four surfaces:
| Surface | Generated reference | Use it when |
|---|---|---|
| Rust core and compiler | Rust API (rustdoc) | You need the alloc API, fixed-storage API, schema compiler or generated wrappers in Rust. |
| Python bindings | Python API (pdoc) | You are writing host code in Python. |
| C ABI | C API (Doxygen) | You need a stable C interface from C, C++ or another FFI-capable language. |
| Generated wrappers | Language API references | You want typed message structs instead of hand-built value arrays. |
Build all references with pixi run docs and open docs/site/index.html. The
generated directories are not checked in; they are rebuilt from source on every
docs run.
Common rules
All APIs share these rules:
- A schema is parsed once and then shared by one encoder and one decoder. The message ID is derived from the message name and is stable across sets.
- Use one encoder per sender and one decoder per incoming stream. Frames do not carry a sender identity.
now_nsis a monotonic host clock used only to advance frame ticks. The decoder never reads time.Decoder::feed(or its language equivalent) accepts exactly one complete frame. Transport framing is the host’s responsibility.- Check per-field validity before acting on a value.
Predictedis bounded but is not a fresh measurement;Unknownis not a value you should trust.
Choosing a Rust path
The Rust API has three levels:
- Alloc API —
predsync_core::EncoderandDecoderwithValueandVec. This is the default and is what the Rust quickstart uses. - Fixed-storage API — the same types with
with_storage,plan_intoand caller-owned buffers. See Embedded and no-alloc use. - Generated wrappers —
predsync_compiler::Builderemits typed enums, message structs and aPredictorSet; see Generated wrappers.
The C ABI mirrors the alloc API with opaque handles and caller-owned buffers. The Python bindings mirror it with dict/list values and generated classes.
Error handling
| Error kind | Meaning |
|---|---|
EncodeError / predsync.EncodeError | Wrong field count, invalid value, non-finite scalar, time not advancing, stale plan, or output buffer too small. |
DecodeError / predsync.DecodeError | Frame too short, CRC mismatch, unknown message, malformed value, or stale frame. |
| C status | Ok, NullPointer, InvalidSchema, InvalidHandle, BufferTooSmall, InvalidValue, EncodeError, DecodeError, or Panic; a second output carries the detailed code. |
A rejected frame leaves predictor state and field trust unchanged, apart from named diagnostic counters such as the CRC-failure streak.