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: LnmpEnvelopeLNMP envelope containing record and operational metadata
kind: MessageKindMessage semantic classification
priority: u8Priority (0-255): 0-50 low, 51-200 normal, 201-255 critical
ttl_ms: u32Time-to-live in milliseconds
class: Option<String>Optional domain classification (e.g., “health”, “safety”, “traffic”)
Implementations§
Source§impl NetMessage
impl NetMessage
Sourcepub fn new(envelope: LnmpEnvelope, kind: MessageKind) -> Self
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.
Sourcepub fn with_qos(
envelope: LnmpEnvelope,
kind: MessageKind,
priority: u8,
ttl_ms: u32,
) -> Self
pub fn with_qos( envelope: LnmpEnvelope, kind: MessageKind, priority: u8, ttl_ms: u32, ) -> Self
Creates a new network message with custom priority and TTL
Sourcepub fn is_expired(&self, now_ms: u64) -> Result<bool>
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 > 5000msSourcepub fn age_ms(&self, now_ms: u64) -> Option<u64>
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.
Sourcepub fn record(&self) -> &LnmpRecord
pub fn record(&self) -> &LnmpRecord
Returns a reference to the underlying LNMP record
Trait Implementations§
Source§impl Clone for NetMessage
impl Clone for NetMessage
Source§fn clone(&self) -> NetMessage
fn clone(&self) -> NetMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more