polynode 0.7.0

Rust SDK for the PolyNode API — real-time Polymarket data
Documentation
//! Frame decoding — handles text and compressed binary frames.

use std::io::Read;
use tokio_tungstenite::tungstenite::Message;
use crate::error::{Error, Result};

/// Decode a WebSocket frame into a UTF-8 string.
/// Binary frames are decompressed with raw deflate (RFC 1951).
/// Text frames are returned as-is.
pub fn decode_frame(msg: Message) -> Result<Option<String>> {
    match msg {
        Message::Text(text) => Ok(Some(text.to_string())),
        Message::Binary(data) => {
            let mut decoder = flate2::read::DeflateDecoder::new(&data[..]);
            let mut output = String::new();
            decoder.read_to_string(&mut output)
                .map_err(|e| Error::Decompression(e.to_string()))?;
            Ok(Some(output))
        }
        Message::Ping(_) | Message::Pong(_) => Ok(None),
        Message::Close(_) => Err(Error::ConnectionClosed),
        _ => Ok(None),
    }
}