Struct PlainMessage

Source
pub struct PlainMessage<T = Value> {
Show 13 fields pub id: String, pub typ: String, pub type_: String, pub body: T, pub from: String, pub to: Vec<String>, pub thid: Option<String>, pub pthid: Option<String>, pub extra_headers: HashMap<String, Value>, pub created_time: Option<u64>, pub expires_time: Option<u64>, pub from_prior: Option<String>, pub attachments: Option<Vec<Attachment>>,
}
Expand description

Wrapper for plain message. Provides helpers for message building and packing/unpacking. Adapted from https://github.com/sicpa-dlab/didcomm-rust/blob/main/src/message/message.rs

Fields§

§id: String

Message id. Must be unique to the sender.

§typ: String

Optional, if present it must be “application/didcomm-plain+json”

§type_: String

Message type attribute value MUST be a valid Message Type URI, that when resolved gives human readable information about the message. The attribute’s value also informs the content of the message, or example the presence of other attributes and how they should be processed.

§body: T

Message body - strongly typed when T is specified.

§from: String

Sender identifier. The from attribute MUST be a string that is a valid DID or DID URL (without the fragment component) which identifies the sender of the message.

§to: Vec<String>

Identifier(s) for recipients. MUST be an array of strings where each element is a valid DID or DID URL (without the fragment component) that identifies a member of the message’s intended audience.

§thid: Option<String>

Uniquely identifies the thread that the message belongs to. If not included the id property of the message MUST be treated as the value of the thid.

§pthid: Option<String>

If the message is a child of a thread the pthid will uniquely identify which thread is the parent.

§extra_headers: HashMap<String, Value>

Custom message headers.

§created_time: Option<u64>

The attribute is used for the sender to express when they created the message, expressed in UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC). This attribute is informative to the recipient, and may be relied on by protocols.

§expires_time: Option<u64>

The expires_time attribute is used for the sender to express when they consider the message to be expired, expressed in UTC Epoch Seconds (seconds since 1970-01-01T00:00:00Z UTC). This attribute signals when the message is considered no longer valid by the sender. When omitted, the message is considered to have no expiration by the sender.

§from_prior: Option<String>

from_prior is a compactly serialized signed JWT containing FromPrior value

§attachments: Option<Vec<Attachment>>

Implementations§

Source§

impl<T> PlainMessage<T>

Source

pub fn new(id: String, type_: String, body: T, from: String) -> Self

Create a new PlainMessage with the given body

Source

pub fn with_recipients(self, to: Vec<String>) -> Self

Builder method to set recipients

Source

pub fn with_recipient(self, recipient: &str) -> Self

Builder method to add a single recipient

Source

pub fn with_thread_id(self, thid: Option<String>) -> Self

Builder method to set thread ID

Source

pub fn with_parent_thread_id(self, pthid: Option<String>) -> Self

Builder method to set parent thread ID

Source

pub fn with_expires_at(self, expires_time: u64) -> Self

Builder method to set expiration time

Source

pub fn with_attachments(self, attachments: Vec<Attachment>) -> Self

Builder method to add attachments

Source

pub fn with_header(self, key: String, value: Value) -> Self

Builder method to add a custom header

Source§

impl<T> PlainMessage<T>

Source

pub fn new_typed(body: T, from: &str) -> Self

Create a new typed message

Source

pub fn to_plain_message(self) -> Result<PlainMessage<Value>>

Convert to untyped PlainMessage for serialization/transport

Source

pub fn extract_participants(&self) -> Vec<String>

Extract recipients based on the message body participants

Source§

impl<T> PlainMessage<T>

Source

pub fn extract_participants_with_context(&self) -> Vec<String>

Extract participants using MessageContext

Source

pub fn new_typed_with_context(body: T, from: &str) -> Self

Create a typed message with automatic recipient detection

Source

pub fn routing_hints(&self) -> RoutingHints

Get routing hints from the message body

Source

pub fn transaction_context(&self) -> Option<TransactionContext>

Get transaction context from the message body

Source§

impl PlainMessage<Value>

Source

pub fn from_untyped(plain_msg: PlainMessage<Value>) -> Self

Create a typed message from an untyped PlainMessage

Source

pub fn parse_body<T: TapMessageBody>(self) -> Result<PlainMessage<T>>

Try to parse the body into a specific TAP message type

Source

pub fn parse_tap_message(&self) -> Result<TapMessage>

Parse into the TapMessage enum for runtime dispatch

Trait Implementations§

Source§

impl<T: Clone> Clone for PlainMessage<T>

Source§

fn clone(&self) -> PlainMessage<T>

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 Connectable for PlainMessage

Source§

fn with_connection(&mut self, connection_id: &str) -> &mut Self

Connect this message to a prior Connect message by setting the parent thread ID (pthid). Read more
Source§

fn has_connection(&self) -> bool

Check if this message is connected to a prior Connect message. Read more
Source§

fn connection_id(&self) -> Option<&str>

Get the connection ID if present. Read more
Source§

impl<T: Debug> Debug for PlainMessage<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for PlainMessage<T>

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<T: PartialEq> PartialEq for PlainMessage<T>

Source§

fn eq(&self, other: &PlainMessage<T>) -> 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 PlainMessageExt<Value> for PlainMessage<Value>

Source§

fn into_typed(self) -> PlainMessage<Value>

Convert to a typed message
Source§

fn parse_as<U: TapMessageBody>(self) -> Result<PlainMessage<U>>

Try to parse as a specific message type
Source§

impl<T> Serialize for PlainMessage<T>

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

impl TapMessage for PlainMessage

Source§

fn validate(&self) -> Result<()>

Validates a TAP message. Read more
Source§

fn is_tap_message(&self) -> bool

Checks if this message is a TAP message.
Source§

fn get_tap_type(&self) -> Option<String>

Gets the TAP message type from this message.
Source§

fn body_as<T: TapMessageBody>(&self) -> Result<T>

Extract a specific message body type from this message. Read more
Source§

fn get_all_participants(&self) -> Vec<String>

Get all participant DIDs from this message. Read more
Source§

fn thread_id(&self) -> Option<&str>

Get the thread ID for this message
Source§

fn parent_thread_id(&self) -> Option<&str>

Get the parent thread ID for this message
Source§

fn message_id(&self) -> &str

Get the message ID for this message
Source§

fn create_reply<T: TapMessageBody>( &self, body: &T, creator_did: &str, ) -> Result<PlainMessage>

Create a reply to this message. Read more
Source§

impl<T: TapMessageBody> TryFrom<PlainMessage<T>> for TapMessage
where TapMessage: From<T>,

Helper to convert between typed messages and TapMessage enum

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(typed: PlainMessage<T>) -> Result<Self>

Performs the conversion.
Source§

impl<T: Eq> Eq for PlainMessage<T>

Source§

impl<T> StructuralPartialEq for PlainMessage<T>

Auto Trait Implementations§

§

impl<T> Freeze for PlainMessage<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PlainMessage<T>
where T: RefUnwindSafe,

§

impl<T> Send for PlainMessage<T>
where T: Send,

§

impl<T> Sync for PlainMessage<T>
where T: Sync,

§

impl<T> Unpin for PlainMessage<T>
where T: Unpin,

§

impl<T> UnwindSafe for PlainMessage<T>
where T: UnwindSafe,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,