Struct fastwebsockets::Frame

source ·
pub struct Frame<'f> {
    pub fin: bool,
    pub opcode: OpCode,
    pub payload: Payload<'f>,
    /* private fields */
}
Expand description

Represents a WebSocket frame.

Fields§

§fin: bool

Indicates if this is the final frame in a message.

§opcode: OpCode

The opcode of the frame.

§payload: Payload<'f>

The payload of the frame.

Implementations§

source§

impl<'f> Frame<'f>

source

pub fn new( fin: bool, opcode: OpCode, mask: Option<[u8; 4]>, payload: Payload<'f> ) -> Self

Creates a new WebSocket Frame.

source

pub fn text(payload: Payload<'f>) -> Self

Create a new WebSocket text Frame.

This is a convenience method for Frame::new(true, OpCode::Text, None, payload).

This method does not check if the payload is valid UTF-8.

source

pub fn binary(payload: Payload<'f>) -> Self

Create a new WebSocket binary Frame.

This is a convenience method for Frame::new(true, OpCode::Binary, None, payload).

source

pub fn close(code: u16, reason: &[u8]) -> Self

Create a new WebSocket close Frame.

This is a convenience method for Frame::new(true, OpCode::Close, None, payload).

This method does not check if code is a valid close code and reason is valid UTF-8.

source

pub fn close_raw(payload: Payload<'f>) -> Self

Create a new WebSocket close Frame with a raw payload.

This is a convenience method for Frame::new(true, OpCode::Close, None, payload).

This method does not check if payload is valid Close frame payload.

source

pub fn pong(payload: Payload<'f>) -> Self

Create a new WebSocket pong Frame.

This is a convenience method for Frame::new(true, OpCode::Pong, None, payload).

source

pub fn is_utf8(&self) -> bool

Checks if the frame payload is valid UTF-8.

source

pub fn mask(&mut self)

source

pub fn unmask(&mut self)

Unmasks the frame payload in-place. This method does nothing if the frame is not masked.

Note: By default, the frame payload is unmasked by WebSocket::read_frame.

source

pub fn fmt_head(&mut self, head: &mut [u8]) -> usize

Formats the frame header into the head buffer. Returns the size of the length field.

Panics

This method panics if the head buffer is not at least n-bytes long, where n is the size of the length field (0, 2, 4, or 10)

source

pub async fn writev<S>(&mut self, stream: &mut S) -> Result<(), Error>
where S: AsyncWriteExt + Unpin,

source

pub fn write<'a>(&mut self, buf: &'a mut Vec<u8>) -> &'a [u8]

Writes the frame to the buffer and returns a slice of the buffer containing the frame.

Auto Trait Implementations§

§

impl<'f> RefUnwindSafe for Frame<'f>

§

impl<'f> Send for Frame<'f>

§

impl<'f> Sync for Frame<'f>

§

impl<'f> Unpin for Frame<'f>

§

impl<'f> !UnwindSafe for Frame<'f>

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

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

§

fn vzip(self) -> V