aboutsummaryrefslogtreecommitdiff
path: root/server/client-lib/src/network/tokio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/client-lib/src/network/tokio.rs')
-rw-r--r--server/client-lib/src/network/tokio.rs54
1 files changed, 27 insertions, 27 deletions
diff --git a/server/client-lib/src/network/tokio.rs b/server/client-lib/src/network/tokio.rs
index 9fce3909..d42d0fc1 100644
--- a/server/client-lib/src/network/tokio.rs
+++ b/server/client-lib/src/network/tokio.rs
@@ -20,7 +20,7 @@ use futures_util::{
stream::{SplitSink, SplitStream, StreamExt},
SinkExt, TryStreamExt,
};
-use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
+use hurrycurry_protocol::{PacketC, PacketS, VERSION};
use log::{debug, info, warn};
use std::sync::atomic::{AtomicBool, Ordering};
use tokio::{net::TcpStream, sync::RwLock};
@@ -35,7 +35,7 @@ use tungstenite::{
pub struct Network {
sock_recv: RwLock<SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>>,
sock_send: RwLock<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>,
- use_bincode: AtomicBool,
+ use_binary: AtomicBool,
}
impl Network {
@@ -82,7 +82,7 @@ impl Network {
Ok(Self {
sock_recv: RwLock::new(sock_recv),
sock_send: RwLock::new(sock_send),
- use_bincode: false.into(),
+ use_binary: false.into(),
})
}
@@ -101,7 +101,7 @@ impl Network {
{
if *minor == VERSION.0 && *major == VERSION.1 && *supports_bincode {
info!("Binary protocol format enabled.");
- self.use_bincode.store(true, Ordering::Relaxed);
+ self.use_binary.store(true, Ordering::Relaxed);
}
}
return Ok(Some(packet));
@@ -110,16 +110,16 @@ impl Network {
warn!("invalid json packet: {e:?}");
}
},
- Some(Message::Binary(packet)) => {
- match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
- Ok((packet, _)) => {
- debug!("<- {packet:?}");
- return Ok(Some(packet));
- }
- Err(e) => {
- warn!("invalid bincode packet: {e:?}");
- }
- }
+ Some(Message::Binary(_packet)) => {
+ // match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
+ // Ok((packet, _)) => {
+ // debug!("<- {packet:?}");
+ // return Ok(Some(packet));
+ // }
+ // Err(e) => {
+ // warn!("invalid bincode packet: {e:?}");
+ // }
+ // }
}
_ => (),
};
@@ -128,19 +128,19 @@ impl Network {
pub async fn send(&self, packet: PacketS) -> anyhow::Result<()> {
debug!("-> {packet:?}");
let mut g = self.sock_send.write().await;
- if self.use_bincode.load(Ordering::Relaxed) {
- g.send(Message::Binary(
- bincode::encode_to_vec(&packet, BINCODE_CONFIG)
- .unwrap()
- .into(),
- ))
- .await?;
- } else {
- g.send(Message::Text(
- serde_json::to_string(&packet).unwrap().into(),
- ))
- .await?;
- }
+ // if self.use_binary.load(Ordering::Relaxed) {
+ // g.send(Message::Binary(
+ // bincode::encode_to_vec(&packet, BINCODE_CONFIG)
+ // .unwrap()
+ // .into(),
+ // ))
+ // .await?;
+ // } else {
+ g.send(Message::Text(
+ serde_json::to_string(&packet).unwrap().into(),
+ ))
+ .await?;
+ // }
Ok(())
}
}