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>
impl<'f> Frame<'f>
sourcepub fn new(
fin: bool,
opcode: OpCode,
mask: Option<[u8; 4]>,
payload: Payload<'f>
) -> Self
pub fn new( fin: bool, opcode: OpCode, mask: Option<[u8; 4]>, payload: Payload<'f> ) -> Self
Creates a new WebSocket Frame
.
sourcepub fn text(payload: Payload<'f>) -> Self
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.
sourcepub fn binary(payload: Payload<'f>) -> Self
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)
.
sourcepub fn close(code: u16, reason: &[u8]) -> Self
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.
sourcepub fn close_raw(payload: Payload<'f>) -> Self
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.
sourcepub fn pong(payload: Payload<'f>) -> Self
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)
.
pub fn mask(&mut self)
sourcepub fn unmask(&mut self)
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
.
sourcepub fn fmt_head(&mut self, head: &mut [u8]) -> usize
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)