Skip to main content

Crate moddef_core

Crate moddef_core 

Source
Expand description

ModDef runtime for Rust (spec v0.4).

Layering (spec §32):

Embedded targets use generated static descriptor tables (see moddef-codegen) and never parse documents at runtime; servers/gateways parse .moddef files at runtime and use the dynamic facade. Both paths share this codec.

Re-exports§

pub use desc::Access;
pub use desc::AddressSpace;
pub use desc::DateTimeEncoding;
pub use desc::FieldDesc;
pub use desc::NaDesc;
pub use desc::PointDesc;
pub use desc::Rational;
pub use desc::ScaleMode;
pub use desc::ScaleRefDesc;
pub use desc::SelectorCaseDesc;
pub use desc::SelectorDesc;
pub use desc::StorageType;
pub use desc::StringPadding;
pub use desc::StringTermination;
pub use desc::ValueKind;
pub use desc::WriteDesc;
pub use error::ConstraintKind;
pub use error::DecodeError;
pub use error::EncodeError;
pub use error::Error;
pub use transport::Transport;
pub use value::Reading;
pub use value::Value;
pub use device::Device;
pub use measurand::MeasurandQuery;
pub use value::DecodedValue;
pub use document::detect_format;
pub use document::load;
pub use document::parse_document;
pub use document::serialize_document;
pub use document::DocumentFormat;
pub use document::ParseError;

Modules§

codec
Codec core (spec §8–§15): pure functions over crate::desc::PointDesc, no_std and allocation-free. Kept in behavioral lockstep with go/codec and moddef-ts’s codec (shared vector suite in the conformance tests).
convert
prost schema::PointPointDesc conversion (alloc). The codec core is heap-free, so descriptors borrow: strings and allowed_values borrow the prost message directly; flag/field/case/na tables need owned side-buffers (DescBufs) because their layout differs from the wire form. Two-step use:
desc
Lightweight, heap-free point descriptors — the codec core’s view of a point (spec §7–§15). Generated code emits static tables of these; the alloc feature converts prost Points into them (see convert).
device
Runtime device facade (spec §32.4): binds a Transport to one parsed device profile for point- and measurand-based reads/writes, with no codegen. Port of moddef-ts Device / go/client/client.go.
document
Document layer (spec §4): parse and serialize the three equivalent encodings — .moddef.yaml, .moddef.json, .moddef (proto binary). YAML and JSON follow proto3 JSON (protojson) semantics via the pbjson-generated serde impls; unknown fields and invalid enum values are rejected, matching the Go implementation and the fixtures under moddef/fixtures/invalid. YAML goes through a YAML→JSON value conversion (numeric keys stringified) — the same round-trip the Go loader uses.
error
Typed errors (spec §26.3/§26.4, §32). Structured variants rather than strings; Display always, std::error::Error under std.
measurand
Measurand queries (spec §22, §26.1). A query selects points by their semantic tuple; unspecified qualifiers are wildcards, base_quantity is required. Mirrors go/client measurandMatches and moddef-ts measurand.ts.
resolve
Import resolution (spec §19). Import URIs follow the package form moddef:<namespace>:<name>:<version> (e.g. moddef:stdlib:measurands:1.0.0), resolved against package roots as <root>/<name>/<version>/<name>.moddef.{yaml,json,binary} — the layout of moddef/stdlib and the Go resolver’s MODDEF_PACKAGE_ROOTS.
rt
Runtime support for generated clients (spec §31). no_std, allocation free: generated code (moddef-codegen) drives the codec core over its static POINTS table and calls into these helpers so the emitted method bodies stay small. Not a stable public API surface — pinned by the generator, may change with it.
schema
Generated protobuf schema types (spec §27), compiled by build.rs from the vendored proto/moddef/v1/*.proto via protox + prost-build. Under std, pbjson-generated serde impls give protojson-semantics JSON (and, via document, YAML) for every message.
transport
Transport abstraction (spec §32.2). Implementations wrap a Modbus client (see moddef-tokio-modbus) or an in-memory register map for tests.
value
Decoded value model (spec §8, §13). The no_std core surfaces Value (no heap: strings decode into caller buffers, flags stay a raw mask with name iteration via the descriptor); the alloc feature adds the owned DecodedValue mirroring the Go/TS union.