Expand description
Message codec.
Codec provides encode/decode for WebSocket text frames. A blanket
implementation via serde_json is provided for any Serialize + DeserializeOwned.
§The wire message model: Frame
WebSocket (RFC 6455) carries two data frame kinds: text (must be valid
UTF-8) and binary (opaque bytes). Since 0.4.0 ws-kit models both in
Frame:
Frame::Text— UTF-8 payloads; the only kindCodecandJsonCodecoperate on.Frame::Binary— opaque bytes, carried verbatim.
§Security posture (binary is never text)
A Frame::Binary payload is never parsed as text or JSON by any
ws-kit code path. Codec::decode/JsonCodec::decode take &str — the
type system makes it impossible to feed binary bytes into the JSON
decoder without an explicit, reviewer-visible UTF-8 conversion. Rooms,
the hub, and (0.4.0) the Redis adapter move binary payloads opaquely:
no sniffing, no best-effort decoding, no shell-out to text heuristics.
Conversely, text is guaranteed UTF-8 end to end — a Frame::Text can
only be constructed from a String, so downstream JSON decode cannot
hit invalid-UTF-8 surprises.
Authentication is unaffected by frame kind: TokenExtractor reads the
HTTP upgrade request (headers/query), never frame payloads.
Structs§
- Json
Codec - JSON codec helper for types that don’t want to implement
Codecdirectly or where you need associated functions without trait dispatch.
Enums§
- Frame
- A wire message: the union of WebSocket text and binary data frames.
Traits§
- Codec
- Trait for encoding/decoding WebSocket messages.