Struct tungstenite::protocol::frame::Frame

source ·
pub struct Frame {
    header: FrameHeader,
    payload: Vec<u8>,
}
Expand description

A struct representing a WebSocket frame.

Fields§

§header: FrameHeader§payload: Vec<u8>

Implementations§

source§

impl Frame

source

pub fn len(&self) -> usize

Get the length of the frame. This is the length of the header + the length of the payload.

source

pub fn is_empty(&self) -> bool

Check if the frame is empty.

source

pub fn header(&self) -> &FrameHeader

Get a reference to the frame’s header.

source

pub fn header_mut(&mut self) -> &mut FrameHeader

Get a mutable reference to the frame’s header.

source

pub fn payload(&self) -> &Vec<u8>

Get a reference to the frame’s payload.

source

pub fn payload_mut(&mut self) -> &mut Vec<u8>

Get a mutable reference to the frame’s payload.

source

pub(crate) fn is_masked(&self) -> bool

Test whether the frame is masked.

source

pub(crate) fn set_random_mask(&mut self)

Generate a random mask for the frame.

This just generates a mask, payload is not changed. The actual masking is performed either on format() or on apply_mask() call.

source

pub(crate) fn apply_mask(&mut self)

This method unmasks the payload and should only be called on frames that are actually masked. In other words, those frames that have just been received from a client endpoint.

source

pub fn into_data(self) -> Vec<u8>

Consume the frame into its payload as binary.

source

pub fn into_string(self) -> StdResult<String, FromUtf8Error>

Consume the frame into its payload as string.

source

pub fn to_text(&self) -> Result<&str, Utf8Error>

Get frame payload as &str.

source

pub(crate) fn into_close(self) -> Result<Option<CloseFrame<'static>>>

Consume the frame into a closing frame.

source

pub fn message(data: Vec<u8>, opcode: OpCode, is_final: bool) -> Frame

Create a new data frame.

source

pub fn pong(data: Vec<u8>) -> Frame

Create a new Pong control frame.

source

pub fn ping(data: Vec<u8>) -> Frame

Create a new Ping control frame.

source

pub fn close(msg: Option<CloseFrame<'_>>) -> Frame

Create a new Close control frame.

source

pub fn from_payload(header: FrameHeader, payload: Vec<u8>) -> Self

Create a frame from given header and data.

source

pub fn format(self, output: &mut impl Write) -> Result<()>

Write a frame out to a buffer

Trait Implementations§

source§

impl Clone for Frame

source§

fn clone(&self) -> Frame

Returns a copy 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 Frame

source§

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

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

impl Display for Frame

source§

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

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

impl PartialEq for Frame

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Frame

source§

impl StructuralPartialEq for Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnwindSafe for Frame

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> 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T