NetMessage

Struct NetMessage 

Source
pub struct NetMessage {
    pub envelope: LnmpEnvelope,
    pub kind: MessageKind,
    pub priority: u8,
    pub ttl_ms: u32,
    pub class: Option<String>,
}
Expand description

Network message with semantic classification and QoS metadata

Wraps an LNMP envelope (which contains the record + operational metadata) with network behavior metadata: message kind, priority, TTL, and optional class.

§Examples

use lnmp_core::{LnmpRecord, LnmpField, LnmpValue};
use lnmp_envelope::EnvelopeBuilder;
use lnmp_net::{MessageKind, NetMessage};

// Create a record
let mut record = LnmpRecord::new();
record.add_field(LnmpField { fid: 42, value: LnmpValue::Int(100) });

// Create envelope with timestamp
let envelope = EnvelopeBuilder::new(record)
    .timestamp(1700000000000)
    .source("sensor-01")
    .build();

// Create network message
let msg = NetMessage::new(envelope, MessageKind::Event);

Network message wrapping an LNMP envelope with network behavior metadata.

Combines LNMP record data (via envelope) with network-level information (kind, priority, TTL, class) for intelligent routing and LLM integration.

Fields§

§envelope: LnmpEnvelope

LNMP envelope containing record and operational metadata

§kind: MessageKind

Message semantic classification

§priority: u8

Priority (0-255): 0-50 low, 51-200 normal, 201-255 critical

§ttl_ms: u32

Time-to-live in milliseconds

§class: Option<String>

Optional domain classification (e.g., “health”, “safety”, “traffic”)

Implementations§

Source§

impl NetMessage

Source

pub fn new(envelope: LnmpEnvelope, kind: MessageKind) -> Self

Creates a new network message with defaults from MessageKind

Uses kind.default_priority() and kind.default_ttl_ms() for QoS fields.

Source

pub fn with_qos( envelope: LnmpEnvelope, kind: MessageKind, priority: u8, ttl_ms: u32, ) -> Self

Creates a new network message with custom priority and TTL

Source

pub fn is_expired(&self, now_ms: u64) -> Result<bool>

Checks if the message has expired based on current time

Returns Err(NetError::MissingTimestamp) if envelope has no timestamp.

§Arguments
  • now_ms - Current time in epoch milliseconds
§Examples
use lnmp_core::LnmpRecord;
use lnmp_envelope::EnvelopeBuilder;
use lnmp_net::{MessageKind, NetMessage};

let envelope = EnvelopeBuilder::new(LnmpRecord::new())
    .timestamp(1000)
    .build();

let msg = NetMessage::with_qos(envelope, MessageKind::Event, 100, 5000);

assert!(!msg.is_expired(5000).unwrap()); // Age = 4000ms, TTL = 5000ms
assert!(msg.is_expired(7000).unwrap());  // Age = 6000ms > 5000ms
Source

pub fn age_ms(&self, now_ms: u64) -> Option<u64>

Returns the age of the message in milliseconds

Returns None if envelope has no timestamp.

Source

pub fn source(&self) -> Option<&str>

Returns the source identifier from envelope metadata

Source

pub fn trace_id(&self) -> Option<&str>

Returns the trace ID from envelope metadata

Source

pub fn timestamp(&self) -> Option<u64>

Returns the timestamp from envelope metadata

Source

pub fn record(&self) -> &LnmpRecord

Returns a reference to the underlying LNMP record

Source

pub fn validate(&self) -> Result<()>

Validates the message (envelope + QoS fields)

Trait Implementations§

Source§

impl Clone for NetMessage

Source§

fn clone(&self) -> NetMessage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.