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: MessageIdUnique message identifier.
sender: UserIdSender’s user ID.
recipient: UserIdRecipient’s user ID.
app_id: AppIdApplication ID that this message belongs to.
priority: MessagePriorityMessage priority.
ttl: TTLTime-to-live: maximum hops remaining.
hop_count: HopCountNumber of hops this message has traversed.
timestamp: TimestampTimestamp when the message was created (wall-clock, for display only).
lamport_clock: LamportClockLamport logical clock for causal ordering across devices.
content_type: ContentTypeThe type of content this message carries.
content: StringMessage 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: boolWhether 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
impl Message
Sourcepub fn new(
sender: UserId,
recipient: UserId,
app_id: AppId,
content: impl Into<String>,
) -> Self
pub fn new( sender: UserId, recipient: UserId, app_id: AppId, content: impl Into<String>, ) -> Self
Creates a new message.
§Arguments
sender- Sender’s user IDrecipient- Recipient’s user IDapp_id- Application IDcontent- Message content
Sourcepub fn builder(
sender: UserId,
recipient: UserId,
app_id: AppId,
) -> MessageBuilder
pub fn builder( sender: UserId, recipient: UserId, app_id: AppId, ) -> MessageBuilder
Creates a message builder for more control over message creation.
Sourcepub fn increment_hop(&mut self) -> Result<()>
pub fn increment_hop(&mut self) -> Result<()>
Sourcepub fn decrement_ttl(&mut self) -> Result<()>
pub fn decrement_ttl(&mut self) -> Result<()>
Sourcepub fn is_ttl_exhausted(&self) -> bool
pub fn is_ttl_exhausted(&self) -> bool
Checks if the message’s TTL is exhausted.
Sourcepub fn transport_peer_id(&self) -> Option<&str>
pub fn transport_peer_id(&self) -> Option<&str>
Returns the transport-verified peer identity, if set.
Sourcepub fn wire_codec(&self) -> WireCodec
pub fn wire_codec(&self) -> WireCodec
Returns the wire codec selected for this message’s next serialization.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>>
pub fn to_bytes(&self) -> Result<Vec<u8>>
Serializes the message to binary (MessagePack-like JSON bytes).
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserializes a message from binary.
Sourcepub fn to_wire_v1_bytes(&self) -> Result<Vec<u8>>
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.
Sourcepub fn from_wire_v1_bytes(data: &[u8]) -> Result<Self>
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.