mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_ws_protocol: attempt to parse ws message from binary as well
This commit is contained in:
parent
ca415af2b9
commit
77c9ca03e8
1 changed files with 14 additions and 8 deletions
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue