aboutsummaryrefslogtreecommitdiff
path: root/server/client-lib/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'server/client-lib/src/network')
-rw-r--r--server/client-lib/src/network/sync.rs41
-rw-r--r--server/client-lib/src/network/tokio.rs54
2 files changed, 48 insertions, 47 deletions
diff --git a/server/client-lib/src/network/sync.rs b/server/client-lib/src/network/sync.rs
index eaee72c4..4d6919c9 100644
--- a/server/client-lib/src/network/sync.rs
+++ b/server/client-lib/src/network/sync.rs
@@ -16,7 +16,7 @@
*/
use anyhow::Result;
-use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
+use hurrycurry_protocol::{PacketC, PacketS, VERSION};
use log::{debug, info, warn};
use std::{collections::VecDeque, net::TcpStream};
use tungstenite::{
@@ -104,17 +104,18 @@ impl Network {
None
}
},
- Ok(Message::Binary(packet)) => {
- match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
- Ok((packet, _)) => {
- debug!("<- {packet:?}");
- Some(packet)
- }
- Err(e) => {
- warn!("invalid bincode packet: {e:?}");
- None
- }
- }
+ Ok(Message::Binary(_packet)) => {
+ // match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
+ // Ok((packet, _)) => {
+ // debug!("<- {packet:?}");
+ // Some(packet)
+ // }
+ // Err(e) => {
+ // warn!("invalid bincode packet: {e:?}");
+ // None
+ // }
+ // }
+ None
}
Ok(_) => None,
Err(e) => {
@@ -130,14 +131,14 @@ impl Network {
for packet in self.queue_out.drain(..) {
debug!("-> {packet:?}");
- if self.use_bincode {
- self.sock.write(Message::Binary(
- bincode::encode_to_vec(&packet, BINCODE_CONFIG)?.into(),
- ))?;
- } else {
- self.sock
- .write(Message::Text(serde_json::to_string(&packet)?.into()))?;
- }
+ // if self.use_bincode {
+ // self.sock.write(Message::Binary(
+ // bincode::encode_to_vec(&packet, BINCODE_CONFIG)?.into(),
+ // ))?;
+ // } else {
+ self.sock
+ .write(Message::Text(serde_json::to_string(&packet)?.into()))?;
+ // }
}
self.sock.flush()?;
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(())
}
}