mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +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]
|
#[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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue