sparkplug_b/lib.rs
1//! # `sparkplug_b` — Eclipse Sparkplug B 3.0.0 in Rust
2//!
3//! A standalone, spec-driven implementation of the [Eclipse Sparkplug B 3.0.0]
4//! specification: the wire payload model + codec, the topic namespace, the
5//! sequence/`bdSeq` machinery, and (phased) the Edge Node and Host Application
6//! roles.
7//!
8//! This crate (package `lb-sparkplugb-rs`, library `sparkplug_b`) has **no
9//! dependency** on any SCADA framework. Phase 1 — the payload model, the
10//! `protoc`-free proto2 codec, the topic namespace, and the seq/bdSeq layer —
11//! is implemented and tested. The Edge/Host/transport layers are designed in
12//! `docs/plan-lb-sparkplugb-rs-sparkplug-b.md` and scaffolded in [`edge`],
13//! [`host`], and [`transport`].
14//!
15//! ## Example: build, encode, and decode an NBIRTH-style payload
16//!
17//! ```
18//! use sparkplug_b::{decode, encode, EncodeOptions, Metric, MetricValue, Payload};
19//!
20//! let payload = Payload::new()
21//! .with_timestamp(1_700_000_000_000)
22//! .with_seq(0) // NBIRTH carries seq = 0 (tck-id-topics-nbirth-seq-num)
23//! .with_metric(Metric::new("Temperature", MetricValue::Double(21.5)))
24//! .with_metric(Metric::new("Online", MetricValue::Boolean(true)));
25//!
26//! let bytes = encode(&payload, EncodeOptions::birth());
27//! let decoded = decode(&bytes, None).expect("valid payload round-trips");
28//! assert_eq!(decoded, payload);
29//! ```
30//!
31//! [Eclipse Sparkplug B 3.0.0]: https://sparkplug.eclipse.org/specification/version/3.0/documents/sparkplug-specification-3.0.0.pdf
32
33pub mod alias;
34pub mod codec;
35pub mod datatype;
36pub mod edge;
37pub mod error;
38pub mod host;
39pub mod model;
40pub mod sequence;
41pub mod state;
42pub mod topic;
43pub mod transport;
44pub mod value;
45
46#[cfg(feature = "compression")]
47pub mod compress;
48
49pub use alias::{AliasRegistry, MetricKey};
50pub use codec::{EncodeOptions, decode, encode};
51pub use datatype::DataType;
52pub use edge::{DataSource, EdgeEvent, EdgeNode, EdgeNodeConfig, EdgeState};
53pub use error::{Result, SparkplugError};
54pub use host::{HostApplication, HostConfig, HostEvent};
55pub use model::{
56 DataSet, MetaData, Metric, Parameter, Payload, PropertySet, PropertySetList, Template,
57};
58pub use sequence::{BdSeq, BdSeqStore, FileBdSeqStore, InMemoryBdSeqStore, Seq};
59pub use state::StatePayload;
60pub use topic::{DeviceId, EdgeNodeId, GroupId, MessageType, SparkplugTopic};
61#[cfg(feature = "transport-rumqttc")]
62pub use transport::RumqttcTransport;
63pub use transport::{
64 ConnectOptions, IncomingMessage, MqttTransport, OutboundMessage, Qos, TlsConfig,
65};
66pub use value::{DataSetValue, MetricValue, ParameterValue, PropertyValue};
67
68/// The Sparkplug B namespace token (`spBv1.0`, `tck-id-topic-structure-namespace-a`).
69pub const SPARKPLUG_B_NAMESPACE: &str = topic::NAMESPACE;
70
71/// The reserved `Node Control/Rebirth` metric name (`tck-id-topics-nbirth-rebirth-metric`).
72pub const NODE_CONTROL_REBIRTH: &str = "Node Control/Rebirth";
73
74/// The `bdSeq` metric name carried in NBIRTH/NDEATH (`tck-id-payloads-nbirth-bdseq`).
75pub const BDSEQ_METRIC_NAME: &str = "bdSeq";
76
77/// The `uuid` sentinel marking a compression-envelope payload.
78pub const COMPRESSED_PAYLOAD_UUID: &str = "SPBV1.0_COMPRESSED";