Struct veloren_network::message::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 !Freeze for Message
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more