pub struct CannedMessageEvent {
pub message: CannedMessage,
pub source_node: NodeId,
pub target_node: Option<NodeId>,
pub timestamp: u64,
pub sequence: u32,
}Expand description
A canned message event with metadata.
Contains the message code plus source, optional target, timestamp, and sequence number for deduplication.
Fields§
§message: CannedMessageThe message type
source_node: NodeIdSource node that sent this message
target_node: Option<NodeId>Target node (if directed message, e.g., ACK to specific node)
timestamp: u64Timestamp in milliseconds (epoch or boot time)
sequence: u32Sequence number for deduplication
Implementations§
Source§impl CannedMessageEvent
impl CannedMessageEvent
Sourcepub fn new(
message: CannedMessage,
source_node: NodeId,
target_node: Option<NodeId>,
timestamp: u64,
) -> Self
pub fn new( message: CannedMessage, source_node: NodeId, target_node: Option<NodeId>, timestamp: u64, ) -> Self
Create a new canned message event.
Sourcepub fn with_sequence(
message: CannedMessage,
source_node: NodeId,
target_node: Option<NodeId>,
timestamp: u64,
sequence: u32,
) -> Self
pub fn with_sequence( message: CannedMessage, source_node: NodeId, target_node: Option<NodeId>, timestamp: u64, sequence: u32, ) -> Self
Create with explicit sequence number.
Sourcepub fn encode(&self) -> Vec<u8, 22>
pub fn encode(&self) -> Vec<u8, 22>
Encode to wire format.
Format:
┌──────┬──────────┬──────────┬──────────┬───────────┬──────┐
│ 0xAF │ msg_code │ src_node │ tgt_node │ timestamp │ seq │
│ 1B │ 1B │ 4B │ 4B (opt) │ 8B │ 4B │
└──────┴──────────┴──────────┴──────────┴───────────┴──────┘If target_node is None, those 4 bytes are 0x00000000.
Sourcepub fn decode(data: &[u8]) -> Option<Self>
pub fn decode(data: &[u8]) -> Option<Self>
Decode from wire format.
Returns None if data is malformed.
Sourcepub fn is_newer_than(&self, other: &Self) -> bool
pub fn is_newer_than(&self, other: &Self) -> bool
Check if this event is newer than another from the same source.
Sourcepub fn encode_signed(&self, signature: &[u8; 64]) -> Vec<u8, 86>
pub fn encode_signed(&self, signature: &[u8; 64]) -> Vec<u8, 86>
Encode to signed wire format with Ed25519 signature.
Format:
┌──────┬──────────┬──────────┬──────────┬───────────┬──────┬───────────┐
│ 0xAF │ msg_code │ src_node │ tgt_node │ timestamp │ seq │ signature │
│ 1B │ 1B │ 4B │ 4B │ 8B │ 4B │ 64B │
└──────┴──────────┴──────────┴──────────┴───────────┴──────┴───────────┘The signature should cover the first 22 bytes (marker through seq). Caller is responsible for computing the signature using their identity.
§Arguments
signature- Ed25519 signature over the unsigned payload (22 bytes)
Sourcepub fn decode_signed(data: &[u8]) -> Option<(Self, [u8; 64])>
pub fn decode_signed(data: &[u8]) -> Option<(Self, [u8; 64])>
Decode from signed wire format.
Returns the event and signature if the data is exactly 86 bytes and has a valid marker.
Note: This does NOT verify the signature. Caller must verify using the sender’s public key from the identity registry.
§Returns
Some((event, signature)) if valid signed format, None otherwise.
Sourcepub fn signable_payload(&self) -> Vec<u8, 22>
pub fn signable_payload(&self) -> Vec<u8, 22>
Get the payload bytes that should be signed.
Returns the 22-byte unsigned wire format suitable for signing. Use this with your identity’s sign() method:
let payload = event.signable_payload();
let signature = identity.sign(&payload);
let wire = event.encode_signed(&signature);Sourcepub fn is_signed_format(data: &[u8]) -> bool
pub fn is_signed_format(data: &[u8]) -> bool
Check if wire data is in signed format (86 bytes) vs unsigned (22 bytes).
Useful for protocol negotiation and backward compatibility.
Sourcepub fn is_unsigned_format(data: &[u8]) -> bool
pub fn is_unsigned_format(data: &[u8]) -> bool
Check if wire data is in unsigned format (22 bytes).
Trait Implementations§
Source§impl Clone for CannedMessageEvent
impl Clone for CannedMessageEvent
Source§fn clone(&self) -> CannedMessageEvent
fn clone(&self) -> CannedMessageEvent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more