Skip to main content

decode_frame

Function decode_frame 

Source
pub fn decode_frame<T: DeserializeOwned>(text: &str) -> Option<WsFrame<T>>
Expand description

Decode text into a WsFrame<T> with a single pass of whatever JSON parser is fastest for its size.

  • Small frames: serde_json::from_str on the &str directly — no alloc.
  • Large frames (≥ SIMD_CROSSOVER_BYTES, simd-json feature on): copy to a Vec<u8> once, then simd_json::serde::from_slice with SIMD-accelerated tokenisation.

Returns None on parse failure; callers typically log and drop such frames. Dispatch rule between single and array: first non-whitespace byte is [ → array; else single object. Matches polymarket / kalshi WS behaviour (both forms are observed in the wild).