Skip to main content

Parser

Struct Parser 

Source
pub struct Parser;
Expand description

WebSocket frame parser.

Implementations§

Source§

impl Parser

Source

pub fn parse( src: &mut BytesMut, server: bool, max_size: usize, ) -> Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>

Parses one WebSocket frame from src.

server selects the expected masking direction: server-side parsing requires masked frames, while client-side parsing rejects them. max_size limits the frame payload size.

Returns the final-fragment flag, opcode, and optional payload when a complete frame is available. Returns None without consuming a partial frame.

Source

pub fn parse_close_payload( payload: &[u8], ) -> Result<Option<CloseReason>, ProtocolError>

Parses a close-frame payload.

Returns None for an empty payload.

§Errors

Returns an error for a one-byte payload, an invalid close status code, or a description that is not valid UTF-8.

Source

pub fn write_message<B>( dst: &mut BytePages, pl: B, op: OpCode, fin: bool, mask: bool, ) -> Result<(), ProtocolError>
where BytePage: From<B>,

Encodes a WebSocket frame into dst.

fin controls the final-fragment bit and mask controls whether a new random masking key is applied.

§Errors

Returns an error if a control frame is fragmented or has a payload larger than 125 bytes.

Source

pub fn write_close( dst: &mut BytePages, reason: Option<CloseReason>, mask: bool, ) -> Result<(), ProtocolError>

Encodes a final close control frame into dst.

§Errors

Returns an error if the close code cannot be sent or the encoded close payload would exceed 125 bytes.

Trait Implementations§

Source§

impl Debug for Parser

Source§

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

Formats the value using the given formatter. Read more

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