Expand description
YAML parsing, validation and deterministic code generation.
parse_schema turns one YAML document into a ParsedSchema and runs
the same validation as the compiler. Builder additionally checks a set
of schemas for message-ID collisions before emitting Rust wrappers.
use predsync_compiler::parse_schema;
use predsync_core::{Decoder, DecoderConfig, Encoder, EncoderConfig, Slot, Value};
const SCHEMA: &str = r#"
name: telemetry
sync: { refresh: 8, reset: 32 }
fields:
- name: x
type: f64
quantise: 0.01
range: [-100.0, 100.0]
predictor: { type: linear, window: 4 }
tolerance: { abs: 0.01 }
"#;
let set = parse_schema(SCHEMA).unwrap().set;
let mut encoder = Encoder::new(&set, 0, EncoderConfig::default()).unwrap();
let mut decoder = Decoder::new(&set, DecoderConfig { resync_n: 1 }).unwrap();
for tick in 0..3u64 {
let values = [Value::Scalar(Slot::from_f64(1.25))];
let plan = encoder.plan(&values, tick * 1_000_000).unwrap();
let mut frame = vec![0u8; plan.len];
encoder.commit(plan, &mut frame).unwrap();
let decoded = decoder.feed(&frame).unwrap();
assert_eq!(decoded.fields[0].value, values[0]);
}Re-exports§
pub use builder::Builder;pub use c_codegen::GeneratedC;pub use c_codegen::generate_c;pub use codegen::CodegenError;pub use codegen::generate_python;pub use codegen::generate_rust;pub use codegen::generate_rust_with_options;pub use yaml::parse_schema;
Modules§
- builder
build.rshelper that checks schemas and writes generated Rust wrappers.- c_
codegen - Deterministic C declarations and matching Rust glue for typed message wrappers.
- check
- Receiver schema-set collision checks and deterministic table output.
- codegen
- Deterministic typed Rust wrapper generation from validated schema sets.
- validate
- Semantic validation of parsed schema types.
- yaml
- YAML front end: parses the v1 grammar into schema types without validating it.
Structs§
- EnumDef
- An enum declaration; the wire value is the variant index.
- Field
Schema - One field of a message, in wire order.
- Message
Schema - One message type in a schema set.
- Parsed
Schema - A parsed schema set with its non-fatal warnings.
- Predictor
Spec - Predictor configuration declared inline on a field.
- Schema
Set - All messages that share one wire contract.
- 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§
- 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.
- Scalar
Type - A v1 scalar type, including enum references and list element types.
- Schema
Error - Every schema grammar or validation failure.
- Tolerance
Mode - How absolute and relative bounds combine when both are present.
- Warning
Kind - Categories of schema warning.
Functions§
- compiler_
smoke_ value - Returns a fixed value used by the M0 scaffolding smoke test.