diff options
| author | Matthieu <matthieu@developershouse.xyz> | 2021-11-05 19:04:58 +0400 |
|---|---|---|
| committer | Matthieu <matthieu@developershouse.xyz> | 2021-11-05 19:04:58 +0400 |
| commit | 7ddb5d3820c15ce4202e6f43057310a9fbb7178a (patch) | |
| tree | e61f4fd5bd6c515a5317adf8c8cbb10a362d91ff /gateway/src/connection/utils.rs | |
| parent | b73f3c90ec2a491d59275818e3f61826471452ba (diff) | |
use twilight for deserialization and gateway
Diffstat (limited to 'gateway/src/connection/utils.rs')
| -rw-r--r-- | gateway/src/connection/utils.rs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/gateway/src/connection/utils.rs b/gateway/src/connection/utils.rs deleted file mode 100644 index bb425da..0000000 --- a/gateway/src/connection/utils.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::str::from_utf8; -use tokio_tungstenite::tungstenite::Message; -use common::log::info; - -use crate::error::GatewayError; - -use super::Connection; - -impl Connection { - - /// Handles the websocket events and calls the _handle_discord_message function for the deserialization. - pub(super) async fn _handle_message( - &mut self, - data: &Message, - ) -> Result<crate::payloads::gateway::Message, GatewayError> { - match data { - Message::Text(text) => self._handle_discord_message(&text).await, - Message::Binary(message) => { - match from_utf8(message) { - Ok(data) => self._handle_discord_message(data).await, - Err(err) => Err(GatewayError::from(err.to_string())), - } - }, - Message::Close(close_frame) => { - info!("Discord connection closed {:?}", close_frame); - Err(GatewayError::from("connection closed".to_string())) - }, - _ => Err(GatewayError::from(format!("unknown variant of message specified to the handler {}", data).to_string())), - } - } - - /// Handle the decompression and deserialization process of a discord payload. - pub(super) async fn _handle_discord_message( - &mut self, - raw_message: &str, - ) -> Result<crate::payloads::gateway::Message, GatewayError> { - match serde_json::from_str(raw_message) { - Ok(message) => Ok(message), - Err(err) => Err(GatewayError::from(err.to_string())), - } - } -} |
