Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Embedded and no-alloc use

predsync-core and predsync-schema are no_std. The default alloc feature can be disabled, and every hot path has a caller-storage variant that performs no steady-state allocation.

Feature flags

CrateFeatureEffect
predsync-schemaalloc (default)Enables owned String and Vec schema types.
predsync-corealloc (default)Enables Value, Plan, managed owned slices and Encoder::new.
predsync-corestdEmpty marker for hosts that also link std.
predsync-coretest-supportEnables test-only helpers.

A true no-alloc firmware build uses:

predsync-core = { path = "../../crates/core", default-features = false }
predsync-schema = { path = "../../crates/schema", default-features = false }

The compiler is std-only and is intended for build scripts or offline tooling, not firmware.

Caller storage

The no-alloc API passes all scratch buffers explicitly:

  • EncoderStorage::borrowed(...) for field metadata and predictor state;
  • DecoderStorage / DecoderMessageStorage::borrowed(...) for decode state;
  • plan_into(&[ValueRef], now_ns, &mut PlanBuf) instead of plan;
  • decoder.decode_into(&frame, &mut ParsedBuf, &mut DecodedBufStorage) or the staged parse_into / apply_into path.

predsync_compiler::Builder emits SCHEMA_REF and STORAGE_LAYOUT constants. Use predsync_core::storage::try_required_storage with that layout to size buffers at compile time. examples/generated_example/tests/generated.rs shows the whole borrowed path, and tests/qemu/scenario is the shared no-alloc scenario used by the determinism check.

Values without allocation

ValueRef borrows scalars, lists and strings. BoundedValue<MAX_LIST, MAX_STR> owns inline heapless::Vec / String storage for hosts that need an owned value but cannot use a global allocator. Both convert with as_ref() so the same encoder logic serves alloc and no-alloc callers.

Custom predictors in firmware

A custom predictor is selected by name in the schema. Link-time registration uses the Predictor and PredictorBuilder traits; runtime registries require alloc and are aimed at hosts. A generated PredictorSet implements both traits for the predictors declared in a schema.

Custom callbacks are outside the cross-platform bit-exactness guarantee when they use floating point. Keep them deterministic on the target.

Framing and concurrency

The decoder expects exactly one complete frame per call. A UART, CAN or USB stream needs a host framing layer; the serial/COBS example is a small allocation-free implementation. Do not concatenate frames or feed partial buffers.

There is no global state and no internal locking. Use one encoder per sender and one decoder per incoming stream. On a single-core firmware this is usually one of each per periodic task.

Cross-builds

The CI tasks cross-build the no-alloc paths for thumbv7em-none-eabihf:

pixi run embedded-build
pixi run schema-embedded-build
pixi run generated-embedded-build
pixi run serial-cobs-embedded-build
pixi run qemu-determinism

qemu-determinism runs the same scenario on the host and under QEMU and compares frame bytes, decoded views and predictor-state hashes.