Skip to main content

Message

Struct Message 

Source
pub struct Message {
Show 18 fields pub id: MessageId, pub sender: UserId, pub recipient: UserId, pub app_id: AppId, pub priority: MessagePriority, pub ttl: TTL, pub hop_count: HopCount, pub timestamp: Timestamp, pub lamport_clock: LamportClock, pub content_type: ContentType, pub content: String, pub binary_content: Option<Vec<u8>>, pub media_metadata: Option<MediaMetadata>, pub metadata: HashMap<String, String>, pub requires_ack: bool, pub reply_to_msg: Option<MessageId>, pub forwarded_from: Option<ForwardInfo>, pub reply_context: Option<ReplyContext>, /* private fields */
}
Expand description

A message in the Offline Protocol.

Fields§

§id: MessageId

Unique message identifier.

§sender: UserId

Sender’s user ID.

§recipient: UserId

Recipient’s user ID.

§app_id: AppId

Application ID that this message belongs to.

§priority: MessagePriority

Message priority.

§ttl: TTL

Time-to-live: maximum hops remaining.

§hop_count: HopCount

Number of hops this message has traversed.

§timestamp: Timestamp

Timestamp when the message was created (wall-clock, for display only).

§lamport_clock: LamportClock

Lamport logical clock for causal ordering across devices.

§content_type: ContentType

The type of content this message carries.

§content: String

Message content (text, JSON-serialized file chunk metadata, etc.).

§binary_content: Option<Vec<u8>>

Raw payload for file chunk data carried by the message envelope. This avoids wrapping chunk bytes in FileChunk JSON/base64 content. Note: current transport serialization still uses JSON for Message.

§media_metadata: Option<MediaMetadata>

Media metadata (present for non-text content types).

§metadata: HashMap<String, String>

Optional metadata for application-specific use.

§requires_ack: bool

Whether this message requires an ACK.

§reply_to_msg: Option<MessageId>

ID of the message this is replying to (optional).

§forwarded_from: Option<ForwardInfo>

Forwarding attribution (present when this message was forwarded from another user).

§reply_context: Option<ReplyContext>

Quoted-reply context (present when this message quotes another).

Implementations§

Source§

impl Message

Source

pub fn new( sender: UserId, recipient: UserId, app_id: AppId, content: impl Into<String>, ) -> Self

Creates a new message.

§Arguments
  • sender - Sender’s user ID
  • recipient - Recipient’s user ID
  • app_id - Application ID
  • content - Message content
Source

pub fn builder( sender: UserId, recipient: UserId, app_id: AppId, ) -> MessageBuilder

Creates a message builder for more control over message creation.

Source

pub fn increment_hop(&mut self) -> Result<()>

Increments the hop count.

§Returns

Returns Ok(()) if successful, Err if hop count overflows.

Source

pub fn decrement_ttl(&mut self) -> Result<()>

Decrements the TTL.

§Returns

Returns Ok(()) if successful, Err if TTL is exhausted.

Source

pub fn is_ttl_exhausted(&self) -> bool

Checks if the message’s TTL is exhausted.

Source

pub fn to_json(&self) -> Result<String>

Serializes the message to JSON.

Source

pub fn from_json(json: &str) -> Result<Self>

Deserializes a message from JSON.

Source

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

Returns the transport-verified peer identity, if set.

Source

pub fn wire_codec(&self) -> WireCodec

Returns the wire codec selected for this message’s next serialization.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

Serializes the message to binary (MessagePack-like JSON bytes).

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Deserializes a message from binary.

Source

pub fn to_wire_v1_bytes(&self) -> Result<Vec<u8>>

Serializes the message using the compact binary wire codec (v1).

See crate::wire for the format. This is an additive alternative to to_bytes (JSON); the two are distinguishable by their first byte, so a receiver can accept either without negotiation.

Source

pub fn from_wire_v1_bytes(data: &[u8]) -> Result<Self>

Deserializes a message from a compact binary wire frame (v1).

Runs the same identifier and Lamport-clock validation as the JSON path by routing every field through its validating constructor, so a hostile binary frame is rejected identically to a hostile JSON one. The transport-verified peer identity is never on the wire and is left unset.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

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

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Message

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more