Struct fastwebsockets::Frame

source ·
pub struct Frame {
    pub fin: bool,
    pub opcode: OpCode,
    pub payload: Vec<u8>,
    /* 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: Vec<u8>

The payload of the frame.

Implementations§

source§

impl Frame

source

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

Creates a new WebSocket Frame.

source

pub fn text(payload: Vec<u8>) -> 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: Vec<u8>) -> 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: Vec<u8>) -> 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: Vec<u8>) -> 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: AsyncReadExt + 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 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more