pub struct Parser;Available on crate feature
ws only.Expand description
A struct representing a WebSocket frame.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn parse(
src: &mut BytesMut,
server: bool,
max_size: usize,
) -> Result<Option<(bool, OpCode, Option<BytesMut>)>, ProtocolError>
pub fn parse( src: &mut BytesMut, server: bool, max_size: usize, ) -> Result<Option<(bool, OpCode, Option<BytesMut>)>, ProtocolError>
Parse the input stream into a frame.
Sourcepub fn parse_close_payload(payload: &[u8]) -> Option<CloseReason>
👎Deprecated since 3.13.5: Use Parser::try_parse_close_payload instead.
pub fn parse_close_payload(payload: &[u8]) -> Option<CloseReason>
Use Parser::try_parse_close_payload instead.
Parse the payload of a close frame.
This method preserves the historical behavior of accepting unknown status codes and
replacing invalid UTF-8 in the reason. Use Parser::try_parse_close_payload when the
payload must be validated.
Sourcepub fn try_parse_close_payload(
payload: &[u8],
) -> Result<Option<CloseReason>, ProtocolError>
pub fn try_parse_close_payload( payload: &[u8], ) -> Result<Option<CloseReason>, ProtocolError>
Parse and validate the payload of a close frame.
§Validation
A close payload is either empty or contains a two-byte status code followed by an optional UTF-8 reason. This follows RFC 6455 §5.5.1, with status code rules from RFC 6455 §7.4 and UTF-8 error handling from RFC 6455 §8.1.
Sourcepub fn write_message<B: AsRef<[u8]>>(
dst: &mut BytesMut,
pl: B,
op: OpCode,
fin: bool,
mask: bool,
)
pub fn write_message<B: AsRef<[u8]>>( dst: &mut BytesMut, pl: B, op: OpCode, fin: bool, mask: bool, )
Generate binary representation
Sourcepub fn write_close(dst: &mut BytesMut, reason: Option<CloseReason>, mask: bool)
pub fn write_close(dst: &mut BytesMut, reason: Option<CloseReason>, mask: bool)
Create a new Close control frame.
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