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: MetadataMap,
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: MetadataMapOptional 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
Requires the std feature: this stamps a fresh MessageId and
Timestamp, neither of which a bare-metal target can mint. Build the
struct literally from wire-supplied parts instead.
Sourcepub fn from_parts(
id: MessageId,
sender: UserId,
recipient: UserId,
app_id: AppId,
content: impl Into<String>,
timestamp: Timestamp,
) -> Self
pub fn from_parts( id: MessageId, sender: UserId, recipient: UserId, app_id: AppId, content: impl Into<String>, timestamp: Timestamp, ) -> Self
Creates a message from parts the caller supplies, reading no clock and drawing no entropy.
This is Message::new with its two ambient inputs made explicit, and
it is the constructor a bare-metal target uses, because that target has
neither. Every other field takes the same default new gives it.
Message::new delegates here, so there is one struct literal for an
outbound message rather than two that drift.
§Why this exists
ADR 0020
made this crate build without std on the reading that a constrained
node “receives frames rather than minting them”. That is true of a node
which only forwards, and false the moment one answers: a leaf node
running MLS mints a key package, a confirmation and every sealed reply.
Without this, such a node cannot produce a Message at all, because
the struct has a private field and no other public constructor is
available without std.
§Supplying the two inputs
A device with no entropy still needs a unique MessageId. Deriving
one from a persisted counter and the device’s own identity is enough:
ids are compared for equality by the deduplicator, never assumed
unpredictable. The timestamp is display metadata and is not a security
input, so a device whose clock is only as good as its last pairing is
no less safe, only less legible in a log.
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.
Requires the std feature, because the message it builds is stamped.
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.