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
impl LocalMessage
sourcepub fn onward_route(&self) -> Route
pub fn onward_route(&self) -> Route
Return the message onward route
sourcepub fn onward_route_ref(&self) -> &Route
pub fn onward_route_ref(&self) -> &Route
Return a reference to the message onward route
sourcepub fn next_on_onward_route(&self) -> Result<Address>
pub fn next_on_onward_route(&self) -> Result<Address>
Return the next address on the onward route
sourcepub fn has_next_on_onward_route(&self) -> bool
pub fn has_next_on_onward_route(&self) -> bool
Return true if an address exists on the onward route
sourcepub fn pop_front_onward_route(self) -> Result<Self>
pub fn pop_front_onward_route(self) -> Result<Self>
Remove the first address of the onward route
sourcepub fn push_front_onward_route(self, address: &Address) -> Self
pub fn push_front_onward_route(self, address: &Address) -> Self
Prepend an address on the onward route
sourcepub fn replace_front_onward_route(self, address: &Address) -> Result<Self>
pub fn replace_front_onward_route(self, address: &Address) -> Result<Self>
Replace the first address on the onward route
sourcepub fn prepend_front_onward_route(self, route: &Route) -> Self
pub fn prepend_front_onward_route(self, route: &Route) -> Self
Prepend a route to the onward route
sourcepub fn set_onward_route(self, route: Route) -> Self
pub fn set_onward_route(self, route: Route) -> Self
Set the message onward route
sourcepub fn return_route(&self) -> Route
pub fn return_route(&self) -> Route
Return the message return route
sourcepub fn return_route_ref(&self) -> &Route
pub fn return_route_ref(&self) -> &Route
Return a reference to the message return route
sourcepub fn set_return_route(self, route: Route) -> Self
pub fn set_return_route(self, route: Route) -> Self
Set the message return route
sourcepub fn push_front_return_route(self, address: &Address) -> Self
pub fn push_front_return_route(self, address: &Address) -> Self
Prepend an address to the return route
sourcepub fn prepend_front_return_route(self, route: &Route) -> Self
pub fn prepend_front_return_route(self, route: &Route) -> Self
Prepend a route to the return route
sourcepub fn step_forward(self, address: &Address) -> Result<Self>
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
sourcepub fn into_payload(self) -> Vec<u8> ⓘ
pub fn into_payload(self) -> Vec<u8> ⓘ
Return the message payload
sourcepub fn payload_ref(&self) -> &[u8] ⓘ
pub fn payload_ref(&self) -> &[u8] ⓘ
Return a reference to the message payload
sourcepub fn payload_mut(&mut self) -> &mut Vec<u8> ⓘ
pub fn payload_mut(&mut self) -> &mut Vec<u8> ⓘ
Return a mutable reference to the message payload
sourcepub fn set_payload(self, payload: Vec<u8>) -> Self
pub fn set_payload(self, payload: Vec<u8>) -> Self
Set the message payload
sourcepub fn local_info(&self) -> Vec<LocalInfo>
pub fn local_info(&self) -> Vec<LocalInfo>
Return the message local info
sourcepub fn local_info_ref(&self) -> &[LocalInfo]
pub fn local_info_ref(&self) -> &[LocalInfo]
Return a reference to the message local info
sourcepub fn local_info_mut(&mut self) -> &mut Vec<LocalInfo>
pub fn local_info_mut(&mut self) -> &mut Vec<LocalInfo>
Return a mutable reference to the message local info
sourcepub fn clear_local_info(&mut self)
pub fn clear_local_info(&mut self)
Clear all LocalInfo
entries
sourcepub fn tracing_context(&self) -> OpenTelemetryContext
pub fn tracing_context(&self) -> OpenTelemetryContext
Get the tracing context associated to this local message
sourcepub fn from_transport_message(
transport_message: TransportMessage
) -> LocalMessage
pub fn from_transport_message( transport_message: TransportMessage ) -> LocalMessage
Create a LocalMessage
from a decoded TransportMessage
sourcepub fn into_transport_message(self) -> TransportMessage
pub fn into_transport_message(self) -> TransportMessage
Create a TransportMessage
from a LocalMessage
source§impl LocalMessage
impl LocalMessage
sourcepub fn new() -> Self
pub fn new() -> Self
Create a LocalMessage
with default values, in order to build it with
the withXXX methods
sourcepub fn with_onward_route(self, onward_route: Route) -> Self
pub fn with_onward_route(self, onward_route: Route) -> Self
Specify the onward route for the message
sourcepub fn with_return_route(self, return_route: Route) -> Self
pub fn with_return_route(self, return_route: Route) -> Self
Specify the return route for the message
sourcepub fn with_payload(self, payload: Vec<u8>) -> Self
pub fn with_payload(self, payload: Vec<u8>) -> Self
Specify the payload for the message
sourcepub fn with_local_info(self, local_info: Vec<LocalInfo>) -> Self
pub fn with_local_info(self, local_info: Vec<LocalInfo>) -> Self
Specify the local information for the message
sourcepub fn with_tracing_context(self, tracing_context: OpenTelemetryContext) -> Self
pub fn with_tracing_context(self, tracing_context: OpenTelemetryContext) -> Self
Specify the tracing context
Trait Implementations§
source§impl Clone for LocalMessage
impl Clone for LocalMessage
source§fn clone(&self) -> LocalMessage
fn clone(&self) -> LocalMessage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for LocalMessage
impl Debug for LocalMessage
source§impl Default for LocalMessage
impl Default for LocalMessage
source§impl<'de> Deserialize<'de> for LocalMessage
impl<'de> Deserialize<'de> for LocalMessage
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Hash for LocalMessage
impl Hash for LocalMessage
source§impl Ord for LocalMessage
impl Ord for LocalMessage
source§fn cmp(&self, other: &LocalMessage) -> Ordering
fn cmp(&self, other: &LocalMessage) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for LocalMessage
impl PartialEq for LocalMessage
source§fn eq(&self, other: &LocalMessage) -> bool
fn eq(&self, other: &LocalMessage) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for LocalMessage
impl PartialOrd for LocalMessage
source§fn partial_cmp(&self, other: &LocalMessage) -> Option<Ordering>
fn partial_cmp(&self, other: &LocalMessage) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more