Struct ockam_core::LocalMessage

source ·
pub struct LocalMessage { /* private fields */ }
Expand description

A message type that is routed locally within a single node.

LocalMessage contains:

  • An onward route for the message
  • A return route
  • A binary payload
  • Additional metadata as LocalInfo in binary format, that can be added by Workers within the same node.

A LocalMessage can be converted from a TransportMessage that has just been deserialized from some binary data arriving on a node.

It can also be converted to a TransportMessage to be serialized and sent to another node.

When a LocalMessage has been processed by a worker, its onward_route and return_route need to be modified before the message is sent to another worker. This is generally done by:

  • popping the first address of the onward route (which should be the worker address)
  • push a new return address at the front of the return route (this can be the current worker address but this can also be the address of another worker, depending on the desired topology).

Therefore, a certain number of functions are available on LocalMessage to manipulate the onward and return routes:

  • pop_front_onward_route: remove the first address of the onward route
  • replace_front_onward_route: replace the first address of the onward route with another address
  • push_front_onward_route: add an address at the front of the onward route
  • prepend_front_onward_route: prepend a whole route at the front of the onward route
  • set_onward_route: set a new route for the onward route

There are similar functions for return routes. All modification functions can be composed. For example:

self.pop_front_onward_route()?.prepend_front_return_route(&new_route)

Implementations§

source§

impl LocalMessage

source

pub fn protocol_version(&self) -> ProtocolVersion

Return the protocol version on the return route

source

pub fn onward_route(&self) -> Route

Return the message onward route

source

pub fn onward_route_ref(&self) -> &Route

Return a reference to the message onward route

source

pub fn next_on_onward_route(&self) -> Result<Address>

Return the next address on the onward route

source

pub fn has_next_on_onward_route(&self) -> bool

Return true if an address exists on the onward route

source

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

Remove the first address of the onward route

source

pub fn push_front_onward_route(self, address: &Address) -> Self

Prepend an address on the onward route

source

pub fn replace_front_onward_route(self, address: &Address) -> Result<Self>

Replace the first address on the onward route

source

pub fn prepend_front_onward_route(self, route: &Route) -> Self

Prepend a route to the onward route

source

pub fn set_onward_route(self, route: Route) -> Self

Set the message onward route

source

pub fn return_route(&self) -> Route

Return the message return route

source

pub fn return_route_ref(&self) -> &Route

Return a reference to the message return route

source

pub fn set_return_route(self, route: Route) -> Self

Set the message return route

source

pub fn push_front_return_route(self, address: &Address) -> Self

Prepend an address to the return route

source

pub fn prepend_front_return_route(self, route: &Route) -> Self

Prepend a route to the return route

source

pub fn step_forward(self, address: &Address) -> Result<Self>

Remove the first address on the onward route and push another address on the return route

source

pub fn into_payload(self) -> Vec<u8>

Return the message payload

source

pub fn payload_ref(&self) -> &[u8]

Return a reference to the message payload

source

pub fn payload_mut(&mut self) -> &mut Vec<u8>

Return a mutable reference to the message payload

source

pub fn set_payload(self, payload: Vec<u8>) -> Self

Set the message payload

source

pub fn local_info(&self) -> Vec<LocalInfo>

Return the message local info

source

pub fn local_info_ref(&self) -> &[LocalInfo]

Return a reference to the message local info

source

pub fn local_info_mut(&mut self) -> &mut Vec<LocalInfo>

Return a mutable reference to the message local info

source

pub fn clear_local_info(&mut self)

Clear all LocalInfo entries

source

pub fn tracing_context(&self) -> OpenTelemetryContext

Get the tracing context associated to this local message

source

pub fn from_transport_message( transport_message: TransportMessage ) -> LocalMessage

Create a LocalMessage from a decoded TransportMessage

source

pub fn into_transport_message(self) -> TransportMessage

source§

impl LocalMessage

source

pub fn new() -> Self

Create a LocalMessage with default values, in order to build it with the withXXX methods

source

pub fn with_onward_route(self, onward_route: Route) -> Self

Specify the onward route for the message

source

pub fn with_return_route(self, return_route: Route) -> Self

Specify the return route for the message

source

pub fn with_payload(self, payload: Vec<u8>) -> Self

Specify the payload for the message

source

pub fn with_local_info(self, local_info: Vec<LocalInfo>) -> Self

Specify the local information for the message

source

pub fn with_tracing_context(self, tracing_context: OpenTelemetryContext) -> Self

Specify the tracing context

source

pub fn with_protocol_version(self, protocol_version: ProtocolVersion) -> Self

Specify the version for the message

Trait Implementations§

source§

impl Clone for LocalMessage

source§

fn clone(&self) -> LocalMessage

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 LocalMessage

source§

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

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

impl Default for LocalMessage

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for LocalMessage

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 Hash for LocalMessage

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for LocalMessage

source§

fn cmp(&self, other: &LocalMessage) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for LocalMessage

source§

fn eq(&self, other: &LocalMessage) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for LocalMessage

source§

fn partial_cmp(&self, other: &LocalMessage) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for LocalMessage

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 Eq for LocalMessage

source§

impl Message for LocalMessage

source§

impl StructuralPartialEq for LocalMessage

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> Encodable for T
where T: Serialize,

source§

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

Encode the type into an Encoded type.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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,

§

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

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

source§

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