Struct veloren_network::Message
source · pub struct Message {
pub(crate) data: Bytes,
pub(crate) compressed: bool,
}
Expand description
Fields§
§data: Bytes
§compressed: bool
Implementations§
source§impl Message
impl Message
sourcepub fn serialize<M: Serialize + ?Sized>(
message: &M,
stream_params: StreamParams
) -> Self
pub fn serialize<M: Serialize + ?Sized>( message: &M, stream_params: StreamParams ) -> Self
This serializes any message, according to the Streams
Promises
.
You can reuse this Message
and send it via other Streams
, if the
Promises
match. E.g. Sending a Message
via a compressed and
uncompressed Stream is dangerous, unless the remote site knows about
this.
Example
for example coding, see send_raw
sourcepub fn deserialize<M: DeserializeOwned>(self) -> Result<M, StreamError>
pub fn deserialize<M: DeserializeOwned>(self) -> Result<M, StreamError>
deserialize this Message
. This consumes the struct, as deserialization
is only expected once. Use this when deserialize a recv_raw
Message
. If you are resending this message, deserialization might need
to copy memory
Example
// Create a Network, listen on Port `2300` and wait for a Stream to be opened, then listen on it
let mut stream_a = participant_a.opened().await?;
//Recv Message
let msg = stream_a.recv_raw().await?;
println!("Msg is {}", msg.deserialize::<String>()?);
drop(network);
pub(crate) fn verify(&self, params: StreamParams)
Auto Trait Implementations§
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more