pub struct OutgoingMessage { /* private fields */ }Expand description
A message to be sent to the peer.
OutgoingMessages are generated when the protocol requires data to be sent to the peer.
Unless the connection is terminated, they should not be dropped, but can be sent in any order.
A message that spans one or more frames must have its internal frame order preserved. In
general, the OutgoingMessage::frames() iterator should be used, even for single-frame
messages.
Implementations§
Source§impl OutgoingMessage
impl OutgoingMessage
Sourcepub const fn is_multi_frame(&self, max_frame_size: MaxFrameSize) -> bool
pub const fn is_multi_frame(&self, max_frame_size: MaxFrameSize) -> bool
Returns whether or not a message will span multiple frames.
Sourcepub fn frame_iter(
self,
max_frame_size: MaxFrameSize,
) -> impl Iterator<Item = OutgoingFrame>
pub fn frame_iter( self, max_frame_size: MaxFrameSize, ) -> impl Iterator<Item = OutgoingFrame>
Creates an iterator over all frames in the message with a fixed maximum frame size.
A slightly more convenient frames method, with a fixed max_frame_size. The resulting
iterator will use slightly more memory than the equivalent FrameIter.
Sourcepub const fn non_header_len(&self) -> usize
pub const fn non_header_len(&self) -> usize
Calculates the total number of bytes that are not header data that will be transmitted with this message (the payload + its variable length encoded length prefix).
Sourcepub const fn num_frames(&self, max_frame_size: MaxFrameSize) -> usize
pub const fn num_frames(&self, max_frame_size: MaxFrameSize) -> usize
Calculates the number of frames this message will produce.
Sourcepub const fn total_len(&self, max_frame_size: MaxFrameSize) -> usize
pub const fn total_len(&self, max_frame_size: MaxFrameSize) -> usize
Calculates the total length in bytes of all frames produced by this message.
Sourcepub fn iter_bytes(self, max_frame_size: MaxFrameSize) -> ByteIter
pub fn iter_bytes(self, max_frame_size: MaxFrameSize) -> ByteIter
Creates an byte-iterator over all frames in the message.
The returned ByteIter will return all frames in sequence using the bytes::Buf trait,
with no regard for frame boundaries, thus it is only suitable to send all frames of the
message with no interleaved data.
Sourcepub fn to_bytes(self, max_frame_size: MaxFrameSize) -> Bytes
pub fn to_bytes(self, max_frame_size: MaxFrameSize) -> Bytes
Writes out all frames as they should be sent out on the wire into a Bytes struct.
Consider using the frames() or bytes() methods instead to avoid additional copies. This
method is not zero-copy, but still consumes self to avoid a conversion of a potentially
unshared payload buffer.
Sourcepub fn truncate_to_single_frame(&mut self, max_frame_size: MaxFrameSize)
pub fn truncate_to_single_frame(&mut self, max_frame_size: MaxFrameSize)
Truncates the message payload so that it fits into the first frame.
Trait Implementations§
Source§impl Clone for OutgoingMessage
impl Clone for OutgoingMessage
Source§fn clone(&self) -> OutgoingMessage
fn clone(&self) -> OutgoingMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more