Expand description
Public Rust API for predsync.
This is the user-facing crate. It re-exports the schema, codec and compiler
crates under namespace modules and also surfaces the most common types at
the root. The command-line tool is installed with cargo install predsync.
#[cfg(feature = "compiler")]
fn main() {
use predsync::{parse_schema, Decoder, DecoderConfig, Encoder, EncoderConfig, Slot, Value};
let set = parse_schema(
"name: telemetry\nsync: { refresh: 8, reset: 32 }\nfields:\n - name: x\n type: f64\n quantise: 0.01\n range: [-100.0, 100.0]\n",
)
.unwrap()
.set;
let mut encoder = Encoder::new(&set, 0, EncoderConfig::default()).unwrap();
let mut decoder = Decoder::new(&set, DecoderConfig { resync_n: 1 }).unwrap();
let values = [Value::Scalar(Slot::from_f64(1.25))];
let plan = encoder.plan(&values, 0).unwrap();
let mut frame = vec![0u8; plan.len];
let info = encoder.commit(plan, &mut frame).unwrap();
frame.truncate(info.len);
assert_eq!(decoder.feed(&frame).unwrap().fields[0].value, values[0]);
}
#[cfg(not(feature = "compiler"))]
fn main() {}Embedded users should disable defaults. compiler implies std, so a
no_std build needs default-features = false and, if allocation is
available, the alloc feature alone.
Re-exports§
pub use predsync_compiler as compiler;pub use predsync_core as core;pub use predsync_schema as schema;
Structs§
- Builder
- A build-script helper for one or more receiver schema sets.
- Decoded
- A fully validated output frame (allocator-backed convenience form).
- Decoder
- Decoder for one incoming stream; message IDs dispatch within that stream.
- Decoder
Config - Decoder configuration.
- Encode
Info - Statistics and saturation flags returned by a successful commit.
- Encoder
- Encoder for one message of a schema set.
- Encoder
Config - Encoder configuration: tick duration and the optional reset budget.
- EnumDef
- An enum declaration; the wire value is the variant index.
- Field
Out - One decoded field and its trust state.
- Field
Schema - One field of a message, in wire order.
- GeneratedC
- The two halves of a generated C wrapper: a C header fragment and Rust glue.
- Message
Schema - One message type in a schema set.
- Parsed
Schema - A parsed schema set with its non-fatal warnings.
- Plan
- A pure encoding decision; feed it to
Encoder::committo write a frame. - Predictor
Registry - Explicit registry mapping custom predictor names to runtime factories.
- Predictor
Spec - Predictor configuration declared inline on a field.
- Schema
Set - All messages that share one wire contract.
- Slot
- One scalar value: unsigned integer, sign-extended signed integer, float bits or 0/1.
- Storage
Layout - Storage layout for no-alloc engine.
- Sync
Defaults - Message-level recovery defaults.
- Tolerance
Spec - Tolerance bounds on the delivered value of a numeric field.
- Warning
- A non-fatal schema warning.
Enums§
- Bounded
Value - Bounded value for no-alloc encode/decode.
- Codegen
Error - A schema construct that cannot be represented in generated output.
- Config
Error - Configuration errors detected when constructing an encoder.
- Decode
Error - Errors returned by decoder operations.
- Encode
Error - Errors returned by encoding operations.
- Field
Type - The wire type of a field.
- Predictor
Kind - Predictor kinds supported by the schema.
- Predictor
Param Value - A numeric parameter value for a custom predictor.
- Presence
- The two-bit state written for one predictor field.
- Scalar
Type - The scalar types that can be carried in a
Slot. - Schema
Error - Every schema grammar or validation failure.
- Tolerance
Mode - How absolute and relative bounds combine when both are present.
- Validity
- The trust state of one decoded field.
- Value
- A field value at the core alloc API boundary.
- Value
Ref - Borrowed value view used by core encode/decode logic.
- Warning
Kind - Categories of schema warning.
Traits§
Functions§
- generate_
c - Generate C declarations and Rust implementations for every message in
set. - generate_
python - Generate Python message classes for every message in
set. - generate_
rust - Generate one Rust source file for every message in
set. - generate_
rust_ with_ options - Generate Rust with build-time options.
- parse_
schema - Parse YAML into a schema set and hand it to the validator.
- version_
marker - Returns the facade version marker used by the workspace smoke tests.