aquatic_ws_protocol: attempt to parse ws message from binary as well

This commit is contained in:
Joakim Frostegård 2021-11-01 19:42:52 +01:00
parent ca415af2b9
commit 77c9ca03e8

View file

@ -23,14 +23,20 @@ impl InMessage {
#[inline] #[inline]
pub fn from_ws_message(ws_message: tungstenite::Message) -> ::anyhow::Result<Self> { pub fn from_ws_message(ws_message: tungstenite::Message) -> ::anyhow::Result<Self> {
use tungstenite::Message::Text; use tungstenite::Message;
let mut text = if let Text(text) = ws_message { match ws_message {
text Message::Text(mut text) => {
} else { ::simd_json::serde::from_str(&mut text)
return Err(anyhow::anyhow!("Message is not text")); .context("deserialize from text xwith serde")
}; },
Message::Binary(mut bytes) => {
return ::simd_json::serde::from_str(&mut text).context("deserialize with serde"); ::simd_json::serde::from_slice(&mut bytes[..])
.context("deserialize from binary with serde")
},
_ => {
Err(anyhow::anyhow!("Message is neither text nor binary"))
}
}
} }
} }