Make fields of RawNetworkMessage non public
provide accessor method and new for downstream libs. This is done in order to more easily change the struct without impacting downstream and also in order to add another field while preserving struct invariant in future commit.
This commit is contained in:
parent
c11e5aecb3
commit
8560baaca2
|
@ -149,10 +149,8 @@ crate::error::impl_std_error!(CommandStringError);
|
||||||
/// A Network message
|
/// A Network message
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct RawNetworkMessage {
|
pub struct RawNetworkMessage {
|
||||||
/// Magic bytes to identify the network these messages are meant for
|
magic: Magic,
|
||||||
pub magic: Magic,
|
payload: NetworkMessage,
|
||||||
/// The actual message data
|
|
||||||
pub payload: NetworkMessage,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Network message payload. Proper documentation is available on at
|
/// A Network message payload. Proper documentation is available on at
|
||||||
|
@ -302,6 +300,22 @@ impl NetworkMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawNetworkMessage {
|
impl RawNetworkMessage {
|
||||||
|
|
||||||
|
/// Creates a [RawNetworkMessage]
|
||||||
|
pub fn new(magic: Magic, payload: NetworkMessage) -> Self {
|
||||||
|
Self { magic, payload }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The actual message data
|
||||||
|
pub fn payload(&self) -> &NetworkMessage {
|
||||||
|
&self.payload
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Magic bytes to identify the network these messages are meant for
|
||||||
|
pub fn magic(&self) -> &Magic {
|
||||||
|
&self.magic
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the message command as a static string reference.
|
/// Return the message command as a static string reference.
|
||||||
///
|
///
|
||||||
/// This returns `"unknown"` for [NetworkMessage::Unknown],
|
/// This returns `"unknown"` for [NetworkMessage::Unknown],
|
||||||
|
|
Loading…
Reference in New Issue