OutgoingMessage

Struct OutgoingMessage 

Source
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

Source

pub const fn is_multi_frame(&self, max_frame_size: MaxFrameSize) -> bool

Returns whether or not a message will span multiple frames.

Source

pub const fn frames(self) -> FrameIter

Creates an iterator over all frames in the message.

Source

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.

Source

pub const fn header(&self) -> Header

Returns the outgoing message’s header.

Source

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).

Source

pub const fn num_frames(&self, max_frame_size: MaxFrameSize) -> usize

Calculates the number of frames this message will produce.

Source

pub const fn total_len(&self, max_frame_size: MaxFrameSize) -> usize

Calculates the total length in bytes of all frames produced by this message.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> OutgoingMessage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OutgoingMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for OutgoingMessage

Source§

fn eq(&self, other: &OutgoingMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for OutgoingMessage

Source§

impl StructuralPartialEq for OutgoingMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.