1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
use crate::{compat::vec::Vec, TransportMessage};
use serde::{Deserialize, Serialize};
/// LocalMessage is a message type that is routed locally within one node.
///
/// LocalMessage consists of TransportMessage + local info in binary format, that can be added by
/// Workers within the same node. TransportMessages are used to transfer messages between
/// different nodes using Transport Workers. Upon arrival to receiving Transport Worker,
/// TransportMessage is wrapped inside LocalMessage and forwarded to other Workers inside that node.
///
/// LocalMessage provides mechanism of transporting metadata that is trusted to come
/// from the same node, which is convenient for delegating Authentication/Authorization mechanisms
/// to dedicated local Workers.
///
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
pub struct LocalMessage {
transport_message: TransportMessage,
local_info: Vec<u8>,
}
impl LocalMessage {
/// Underlying transport message
pub fn into_transport_message(self) -> TransportMessage {
self.transport_message
}
/// Underlying transport message
pub fn transport(&self) -> &TransportMessage {
&self.transport_message
}
/// Underlying transport message
pub fn transport_mut(&mut self) -> &mut TransportMessage {
&mut self.transport_message
}
/// LocalInfo added by Workers within the same node
pub fn local_info(&self) -> &Vec<u8> {
&self.local_info
}
}
impl LocalMessage {
/// Constructor
pub fn new(transport_message: TransportMessage, local_info: Vec<u8>) -> Self {
LocalMessage {
transport_message,
local_info,
}
}
}