pub struct Frame {
pub fin: bool,
pub opcode: OpCode,
pub mask: Option<[u8; 4]>,
pub payload: Vec<u8>,
}Fields§
§fin: bool§opcode: OpCode§mask: Option<[u8; 4]>Present only on frames a client sends. A server that masks its frames is as wrong as a client that does not.
payload: Vec<u8>Implementations§
Source§impl Frame
impl Frame
Sourcepub fn server(opcode: OpCode, payload: Vec<u8>) -> Frame
pub fn server(opcode: OpCode, payload: Vec<u8>) -> Frame
A frame as a server sends it: final, and never masked.
Sourcepub fn client(opcode: OpCode, payload: Vec<u8>, mask: [u8; 4]) -> Frame
pub fn client(opcode: OpCode, payload: Vec<u8>, mask: [u8; 4]) -> Frame
A frame as a client sends it. The mask is supplied rather than generated so encoding stays a pure function that a test can pin to exact bytes.
pub fn encode(&self) -> Vec<u8> ⓘ
Sourcepub fn decode(
bytes: &[u8],
role: Role,
max_payload: usize,
) -> WsResult<Option<(Frame, usize)>>
pub fn decode( bytes: &[u8], role: Role, max_payload: usize, ) -> WsResult<Option<(Frame, usize)>>
Decode one frame from the front of bytes.
Returns Ok(None) when the buffer does not hold a whole frame yet — the
caller reads more and asks again — and the number of bytes consumed
alongside the frame so the caller can drain exactly that much.
max_payload is checked against the declared length, before anything
is allocated, so a peer announcing a 4 GiB frame costs nothing.
Trait Implementations§
impl Eq for Frame
impl StructuralPartialEq for Frame
Auto Trait Implementations§
impl Freeze for Frame
impl RefUnwindSafe for Frame
impl Send for Frame
impl Sync for Frame
impl Unpin for Frame
impl UnsafeUnpin for Frame
impl UnwindSafe for Frame
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