Skip to main content

Crate predsync_compiler

Crate predsync_compiler 

Source
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.rs helper 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.
FieldSchema
One field of a message, in wire order.
MessageSchema
One message type in a schema set.
ParsedSchema
A parsed schema set with its non-fatal warnings.
PredictorSpec
Predictor configuration declared inline on a field.
SchemaSet
All messages that share one wire contract.
SyncDefaults
Message-level recovery defaults.
ToleranceSpec
Tolerance bounds on the delivered value of a numeric field.
Warning
A non-fatal schema warning.

Enums§

FieldType
The wire type of a field.
PredictorKind
Predictor kinds supported by the schema.
PredictorParamValue
A numeric parameter value for a custom predictor.
ScalarType
A v1 scalar type, including enum references and list element types.
SchemaError
Every schema grammar or validation failure.
ToleranceMode
How absolute and relative bounds combine when both are present.
WarningKind
Categories of schema warning.

Functions§

compiler_smoke_value
Returns a fixed value used by the M0 scaffolding smoke test.