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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::{Address, LocalMessage, ProtocolVersion, Route};

/// A message addressed to the relay responsible for delivery of the
/// wrapped [`LocalMessage`]
#[derive(Clone, Debug)]
pub struct RelayMessage {
    source: Address,
    destination: Address,
    local_msg: LocalMessage,
}

impl RelayMessage {
    /// Construct a new message addressed to a user worker
    pub fn new(source: Address, destination: Address, local_msg: LocalMessage) -> Self {
        Self {
            source,
            destination,
            local_msg,
        }
    }

    /// The sender address of the wrapped `LocalMessage`
    /// Note that this may be different from the first hop in the return_route
    /// This address is always equal to the address of the `Context` instance used to
    /// send or forward the message
    pub fn source(&self) -> &Address {
        &self.source
    }

    /// The recipient address for the wrapped `LocalMessage`
    /// Note that this may be different from the first hop in the onward_route, for example while
    /// sending a message to an External address (e.g. TCP) first message will be delivered to the
    /// the TCP Router (and destination address will be the address of the TCP Router), and only
    /// then to the individual connection worker
    pub fn destination(&self) -> &Address {
        &self.destination
    }

    /// Onward route
    pub fn onward_route(&self) -> &Route {
        self.local_msg.onward_route_ref()
    }

    /// Return route
    pub fn return_route(&self) -> &Route {
        self.local_msg.return_route_ref()
    }

    /// Payload
    pub fn payload(&self) -> &[u8] {
        self.local_msg.payload_ref()
    }

    /// Protocol version
    pub fn protocol_version(&self) -> ProtocolVersion {
        self.local_msg.protocol_version()
    }

    /// Local message
    pub fn local_message(&self) -> &LocalMessage {
        &self.local_msg
    }

    /// Take local message
    pub fn into_local_message(self) -> LocalMessage {
        self.local_msg
    }
}