Skip to main content

EdgeNode

Struct EdgeNode 

Source
pub struct EdgeNode<T, S> { /* private fields */ }
Expand description

The Edge Node engine.

Implementations§

Source§

impl<T: MqttTransport, S: BdSeqStore> EdgeNode<T, S>

Source

pub fn new(config: EdgeNodeConfig, transport: T, bdseq_store: S) -> Self

Create an engine. Call EdgeNode::connect to start the session.

Source

pub fn state(&self) -> EdgeState

The current lifecycle state.

Source

pub fn bd_seq(&self) -> u8

The bdSeq value bound to the current connection.

Source

pub async fn connect<D: DataSource>(&mut self, source: &D) -> Result<()>

Connect to the broker (registering the NDEATH will), subscribe to NCMD / per-device DCMD (and the primary host’s STATE if configured), then publish the birth sequence unless gated on a primary host.

§Errors

Propagates any transport error.

Source

pub async fn publish_birth_sequence<D: DataSource>( &mut self, source: &D, ) -> Result<()>

Publish NBIRTH (seq = 0) followed by each Device’s DBIRTH.

§Errors

Propagates any transport error.

Source

pub async fn publish_node_data(&mut self, metrics: Vec<Metric>) -> Result<()>

Publish an NDATA (report-by-exception) with the next sequence number.

§Errors

Returns SparkplugError::InvalidTopic if not online, or a transport error.

Source

pub async fn publish_device_data( &mut self, device: &str, metrics: Vec<Metric>, ) -> Result<()>

Publish a DDATA for a born device.

§Errors

Returns an error if the device is not born or on transport failure.

Source

pub async fn publish_device_death(&mut self, device: &str) -> Result<()>

Publish a DDEATH for a born device and mark it offline. DDEATH carries a sequence number (tck-id-payloads-ddeath-seq) at QoS 0, retain=false.

§Errors

Returns an error if the device is not born, or on transport failure.

Source

pub async fn handle_incoming<D: DataSource>( &mut self, message: &IncomingMessage, source: &D, ) -> Result<EdgeEvent>

Handle one inbound message, driving rebirth / primary-host transitions.

A Node Control/Rebirth = true NCMD re-publishes the birth sequence (resetting seq to 0 and reusing the connection’s bdSeq), subject to the rebirth debounce.

§Errors

Returns a decode/transport error; a malformed topic/payload is surfaced rather than panicking.

Source

pub async fn recv_and_handle<D: DataSource>( &mut self, source: &D, ) -> Result<Option<EdgeEvent>>

Receive the next inbound message and handle it; None if the stream closed.

§Errors

Propagates transport/decode errors.

Source

pub async fn disconnect(&mut self) -> Result<()>

Gracefully disconnect: publish the NDEATH explicitly (so the broker need not deliver the will), then disconnect.

§Errors

Propagates any transport error.

Auto Trait Implementations§

§

impl<T, S> Freeze for EdgeNode<T, S>
where T: Freeze, S: Freeze,

§

impl<T, S> RefUnwindSafe for EdgeNode<T, S>

§

impl<T, S> Send for EdgeNode<T, S>
where T: Send, S: Send,

§

impl<T, S> Sync for EdgeNode<T, S>
where T: Sync, S: Sync,

§

impl<T, S> Unpin for EdgeNode<T, S>
where T: Unpin, S: Unpin,

§

impl<T, S> UnsafeUnpin for EdgeNode<T, S>
where T: UnsafeUnpin, S: UnsafeUnpin,

§

impl<T, S> UnwindSafe for EdgeNode<T, S>
where T: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.