pub struct Message { /* private fields */ }
Expand description
A message to be communicated between clients.
Contains a MessageKind
, sender UUID, and message UUID.
Implementations§
source§impl Message
impl Message
sourcepub fn new(inner: MessageKind, sender: Uuid, uuid: Uuid) -> Self
pub fn new(inner: MessageKind, sender: Uuid, uuid: Uuid) -> Self
Creates a new message.
sourcepub fn inner(&self) -> &MessageKind
pub fn inner(&self) -> &MessageKind
Get the inner MessageKind
.
This contains all the data of the message.
sourcepub fn inner_mut(&mut self) -> &mut MessageKind
pub fn inner_mut(&mut self) -> &mut MessageKind
Get a mutable reference to the inner MessageKind
.
This contains all the data of the message.
sourcepub fn into_inner(self) -> MessageKind
pub fn into_inner(self) -> MessageKind
Get the inner MessageKind
.
This contains all the data of the message.
sourcepub fn recipient(&self) -> Recipient
pub fn recipient(&self) -> Recipient
Get the specific recipient if the MessageKind
is targeted.
Can be used to determine to send this message to only one pier or all.
sourcepub fn from_bin(slice: &[u8]) -> Result<Self, DecodeError>
pub fn from_bin(slice: &[u8]) -> Result<Self, DecodeError>
Errors
Returns an appropriate error if the deserialisation failed.
sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Converts the message to a plain text compatible encoding, namely Base64.
This is a optimised version of converting
Self::to_bin()
to Base64. Since I’m using readers and writers, less allocations are needed.
sourcepub fn from_base64(string: &str) -> Result<Self, DecodeError>
pub fn from_base64(string: &str) -> Result<Self, DecodeError>
Errors
Returns an appropriate error if the deserialisation failed.
If the Base64 encoding is wrong, the error returned is
bincode::error::DecodeError::OtherString
which (always) starts with base64 decoding failed
.