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]
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 {
text
} else {
return Err(anyhow::anyhow!("Message is not text"));
};
return ::simd_json::serde::from_str(&mut text).context("deserialize with serde");
match ws_message {
Message::Text(mut text) => {
::simd_json::serde::from_str(&mut text)
.context("deserialize from text xwith serde")
},
Message::Binary(mut bytes) => {
::simd_json::serde::from_slice(&mut bytes[..])
.context("deserialize from binary with serde")
},
_ => {
Err(anyhow::anyhow!("Message is neither text nor binary"))
}
}
}
}