pub struct Parser;Expand description
WebSocket frame parser.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn parse(
src: &mut BytesMut,
server: bool,
max_size: usize,
) -> Result<Option<(bool, OpCode, Option<Bytes>)>, ProtocolError>
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.
Sourcepub fn parse_close_payload(
payload: &[u8],
) -> Result<Option<CloseReason>, ProtocolError>
pub fn parse_close_payload( payload: &[u8], ) -> Result<Option<CloseReason>, ProtocolError>
Sourcepub fn write_message<B>(
dst: &mut BytePages,
pl: B,
op: OpCode,
fin: bool,
mask: bool,
) -> Result<(), ProtocolError>
pub fn write_message<B>( dst: &mut BytePages, pl: B, op: OpCode, fin: bool, mask: bool, ) -> Result<(), ProtocolError>
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.
Sourcepub fn write_close(
dst: &mut BytePages,
reason: Option<CloseReason>,
mask: bool,
) -> Result<(), ProtocolError>
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§
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnsafeUnpin for Parser
impl UnwindSafe for Parser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more