pub struct Message {
pub msg_type: MessageType,
pub payload: BytesMut,
}Expand description
A protocol message
Fields§
§msg_type: MessageTypeMessage type
payload: BytesMutMessage payload
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(msg_type: MessageType, payload: BytesMut) -> Self
pub fn new(msg_type: MessageType, payload: BytesMut) -> Self
Create a new message
Sourcepub fn empty(msg_type: MessageType) -> Self
pub fn empty(msg_type: MessageType) -> Self
Create an empty message
Sourcepub fn encode(&self) -> BytesMut
pub fn encode(&self) -> BytesMut
Encode message to bytes.
Pre-sizes the buffer to the exact final length (1 tag + 4 length +
payload) so a forwarded message never pays reallocation growth on the
hot path — BytesMut::new() starts at capacity 0 and would realloc as
the tag/length/payload are appended.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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