Skip to main content

Crate sparkplug_b

Crate sparkplug_b 

Source
Expand description

§sparkplug_b — Eclipse Sparkplug B 3.0.0 in Rust

A standalone, spec-driven implementation of the Eclipse Sparkplug B 3.0.0 specification: the wire payload model + codec, the topic namespace, the sequence/bdSeq machinery, and (phased) the Edge Node and Host Application roles.

This crate (package lb-sparkplugb-rs, library sparkplug_b) has no dependency on any SCADA framework. Phase 1 — the payload model, the protoc-free proto2 codec, the topic namespace, and the seq/bdSeq layer — is implemented and tested. The Edge/Host/transport layers are designed in docs/plan-lb-sparkplugb-rs-sparkplug-b.md and scaffolded in edge, host, and transport.

§Example: build, encode, and decode an NBIRTH-style payload

use sparkplug_b::{decode, encode, EncodeOptions, Metric, MetricValue, Payload};

let payload = Payload::new()
    .with_timestamp(1_700_000_000_000)
    .with_seq(0) // NBIRTH carries seq = 0 (tck-id-topics-nbirth-seq-num)
    .with_metric(Metric::new("Temperature", MetricValue::Double(21.5)))
    .with_metric(Metric::new("Online", MetricValue::Boolean(true)));

let bytes = encode(&payload, EncodeOptions::birth());
let decoded = decode(&bytes, None).expect("valid payload round-trips");
assert_eq!(decoded, payload);

Re-exports§

pub use alias::AliasRegistry;
pub use alias::MetricKey;
pub use codec::EncodeOptions;
pub use codec::decode;
pub use codec::encode;
pub use datatype::DataType;
pub use edge::DataSource;
pub use edge::EdgeEvent;
pub use edge::EdgeNode;
pub use edge::EdgeNodeConfig;
pub use edge::EdgeState;
pub use error::Result;
pub use error::SparkplugError;
pub use host::HostApplication;
pub use host::HostConfig;
pub use host::HostEvent;
pub use model::DataSet;
pub use model::MetaData;
pub use model::Metric;
pub use model::Parameter;
pub use model::Payload;
pub use model::PropertySet;
pub use model::PropertySetList;
pub use model::Template;
pub use sequence::BdSeq;
pub use sequence::BdSeqStore;
pub use sequence::FileBdSeqStore;
pub use sequence::InMemoryBdSeqStore;
pub use sequence::Seq;
pub use state::StatePayload;
pub use topic::DeviceId;
pub use topic::EdgeNodeId;
pub use topic::GroupId;
pub use topic::MessageType;
pub use topic::SparkplugTopic;
pub use transport::ConnectOptions;
pub use transport::IncomingMessage;
pub use transport::MqttTransport;
pub use transport::OutboundMessage;
pub use transport::Qos;
pub use transport::TlsConfig;
pub use value::DataSetValue;
pub use value::MetricValue;
pub use value::ParameterValue;
pub use value::PropertyValue;

Modules§

alias
Alias registry: the name ↔ alias ↔ datatype bindings established by a BIRTH.
codec
Sparkplug B protobuf (proto2) codec — hand-written and protoc-free (ADR-1).
datatype
Sparkplug B data types (spec §6.4.16 “Data Types”, codes 0..=34).
edge
Edge Node + Device lifecycle (Phase 2).
error
The crate-wide error type and result alias.
host
Host Application + Primary Host (Phase 3).
model
The Sparkplug B payload object model (spec §6.4 “Payload Component Definitions”). Plain data structs — no Java-style getters/setters; values are typed via the enums in crate::value.
sequence
Sequence (seq) and birth/death sequence (bdSeq) counters, plus bdSeq persistence (spec §6.4 sequence rules).
state
Host Application STATE payload (spec §6.4.27).
topic
Topic namespace, message types, and validated identifiers (spec §4).
transport
MQTT transport abstraction (Phase 2+).
value
Typed value enums — the heart of the “make illegal states unrepresentable” design (ADR-2). A MetricValue fuses the Sparkplug datatype with its payload, so the runtime checkType of the Java reference is unnecessary.

Constants§

BDSEQ_METRIC_NAME
The bdSeq metric name carried in NBIRTH/NDEATH (tck-id-payloads-nbirth-bdseq).
COMPRESSED_PAYLOAD_UUID
The uuid sentinel marking a compression-envelope payload.
NODE_CONTROL_REBIRTH
The reserved Node Control/Rebirth metric name (tck-id-topics-nbirth-rebirth-metric).
SPARKPLUG_B_NAMESPACE
The Sparkplug B namespace token (spBv1.0, tck-id-topic-structure-namespace-a).