Skip to main content

CannedMessageEvent

Struct CannedMessageEvent 

Source
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: CannedMessage

The message type

§source_node: NodeId

Source node that sent this message

§target_node: Option<NodeId>

Target node (if directed message, e.g., ACK to specific node)

§timestamp: u64

Timestamp in milliseconds (epoch or boot time)

§sequence: u32

Sequence number for deduplication

Implementations§

Source§

impl CannedMessageEvent

Source

pub fn new( message: CannedMessage, source_node: NodeId, target_node: Option<NodeId>, timestamp: u64, ) -> Self

Create a new canned message event.

Source

pub fn with_sequence( message: CannedMessage, source_node: NodeId, target_node: Option<NodeId>, timestamp: u64, sequence: u32, ) -> Self

Create with explicit sequence number.

Source

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.

Source

pub fn decode(data: &[u8]) -> Option<Self>

Decode from wire format.

Returns None if data is malformed.

Source

pub fn is_newer_than(&self, other: &Self) -> bool

Check if this event is newer than another from the same source.

Source

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)
Source

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.

Source

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);
Source

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.

Source

pub fn is_unsigned_format(data: &[u8]) -> bool

Check if wire data is in unsigned format (22 bytes).

Source

pub fn decode_auto(data: &[u8]) -> Option<(Self, Option<[u8; 64]>)>

Decode from either signed or unsigned format.

Returns (event, Some(signature)) for signed format, or (event, None) for unsigned format.

§Returns

Some((event, optional_signature)) if valid format, None if malformed.

Trait Implementations§

Source§

impl Clone for CannedMessageEvent

Source§

fn clone(&self) -> CannedMessageEvent

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 CannedMessageEvent

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CannedMessageEvent

Source§

fn eq(&self, other: &CannedMessageEvent) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for CannedMessageEvent

Source§

impl Eq for CannedMessageEvent

Source§

impl StructuralPartialEq for CannedMessageEvent

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.