Expand description

Low-level WebSocket (RFC 6455) library which implements WebSocket frame encoding and decoding.

  • No memory allocations. Only minimal state is kept in memory, all payload content remains in user-supplied buffers. The crate is no_std-friendly.
  • No input or output. It only helps you to turn raw bytes into sensible structures and back.
  • Frame payloads may be divided into arbitrary chunks.
  • No validation - you can set or access reserved bits or opcodes if needed.
  • Encoder and decoder states are rather small. You can shrink the decoder further by opting out of large_frames crate feature.
  • Masking should re reasonably fast and SIMD-friendly. You can adjust crate features to opt out the optimisation (for smaller code) or to adjust SIMD slice size.
  • Encoder and decoder instances are const-initialisable.

It is also user’s job to handle pings, HTTP upgrades, masking and close frames properly. There is no automatic assembling of messages from frames or splitting messages into frames. WebSocket text frames are handled the same way as binary frames - you need to convert to a string yourself.

Examples

  • encode_frame - Encode one simple text WebSocket message and decode it with Tungstenite.
  • decode_frame - Encode one simple text message with Tungstenite and decode it with this library. Though no control or fragmented messages actually appears in this case, it tried to handle them properly to server as a template for other code.
  • mirror_client - Connect to a WebSocket server that is listening on 127.0.0.1:1234 and send back all frames which come from it, announcing each frame on console. Uses Tokio and hyper v1. Demonstrates how to validate incoming frames.

See WebsocketFrameEncoder and WebsocketFrameDecoder for continuation of the documentation.

Structs

Enums

Constants

  • Maximum number of bytes in a WebSocket frame header. Less if large_frames crate feature is off.

Functions

  • Apply WebSocket masking to the giben block of data.

Type Aliases

  • When large_frames` crate feature is on (by default), any bytes can be decoded, so no error possible.
  • Type alias for payload length. u64 by default, u16 when large_frames crate feature is off.