Struct ockam::OckamMessage

source ·
#[non_exhaustive]
pub struct OckamMessage { pub data: Vec<u8>, pub scope: Vec<Vec<u8>>, pub generic: Option<Metadata>, }
Expand description

A message metadata wrapper type

This message wraps around a well-typed Message type, with additional metadata. Metadata is split between the “scope” and “generic” sections.

Scope metadata

This metadata is passed around in a particular metadata scope. For example, a worker that adds some behaviour to message sending may chose to embed “scope” metadata. When wrapping this message in another scope the previously scoped metadata becomes part of the opaque data section.

Thus it is not possible to retrieve metadata from a different nested scope!

Generic metadata

When creating an OckamMessage it’s also possible to attach generic metadata. This data is passed around for every nested scope and must be re-attached to the outest-most scope when peeling a nested message stack.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§data: Vec<u8>

Main data section of this message

§scope: Vec<Vec<u8>>

Metadata for this specific scope

§generic: Option<Metadata>

Metadata that is carried to the final recipient of the message

Implementations§

source§

impl OckamMessage

source

pub fn new<M: Message>(msg: M) -> Result<Self>

Create a new OckamMessage with the data from msg.

source

pub fn from_any(msg: Routed<Any>) -> Result<Self>

Create a new OckamMessage from an untyped Any message

source

pub fn wrap(prev: Self) -> Result<Self>

Create a new OckamMessage by nesting a previous one

source

pub fn into_routed( self, msg_addr: Address, src_addr: Address, onward_route: Route, return_route: Route ) -> Result<Routed<Self>>

Wrap this OckamMessage with a new Routed message type

source

pub fn scope_data(self, meta: Vec<u8>) -> Self

Add some metadata to this scope

source

pub fn generic_data<S: Into<String>>(self, key: S, val: Vec<u8>) -> Self

Add to the generic metadata section

source

pub fn peel(self) -> Result<Self>

Dissolve this outer layer of Message and reveal nested message

Will throw a deserialisation error if the inner data is NOT an OckamMessage!

source

pub fn data<M: Message>(&self) -> Result<M>

Decode the data section of this OckamMessage

Trait Implementations§

source§

impl Clone for OckamMessage

source§

fn clone(&self) -> OckamMessage

Returns a copy 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 OckamMessage

source§

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

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

impl<'de> Deserialize<'de> for OckamMessage

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 OckamMessage

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 Message for OckamMessage

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<D> AsyncTryClone for D
where D: Clone + Sync,

source§

fn async_try_clone<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<D, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, D: 'async_trait,

Try cloning a object and return an Err in case of failure.
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> Decodable for T

source§

fn decode(encoded: &[u8]) -> Result<T, Error>

Decode a slice.
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> Encodable for T
where T: Serialize,

source§

fn encode(&self) -> Result<Vec<u8>, Error>

Encode the type into an Encoded type.
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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

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

§

fn vzip(self) -> V

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

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