websocket-sans-io

Crates.iowebsocket-sans-io
lib.rswebsocket-sans-io
version0.1.0
sourcesrc
created_at2023-11-15 20:55:42.76669
updated_at2023-11-15 20:55:42.76669
descriptionLow-level WebSocket library
homepage
repositoryhttps://github.com/vi/websocket-sans-io
max_upload_size
id1036820
size106,568
Vitaly Shukela (vi)

documentation

README

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.
Commit count: 27

cargo fmt