Crate websocket_sans_io

Source
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§

FrameInfo
Information about WebSocket frame header.
WebsocketFrameDecoder
A low-level WebSocket frames decoder.
WebsocketFrameDecoderAddDataResult
Return value of WebsocketFrameDecoder::add_data call.
WebsocketFrameEncoder
A low-level WebSocket frames decoder.

Enums§

Opcode
WebSocket frame type.
WebsocketFrameEvent
Information that WebsocketFrameDecoder gives in return to bytes being fed to it.

Constants§

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

Functions§

apply_mask
Apply WebSocket masking to the giben block of data.

Type Aliases§

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