From b1fd887402e4577cbb630fc6517cf9cd6e0d7c8f Mon Sep 17 00:00:00 2001 From: stale Date: Sun, 29 May 2022 23:56:03 -0300 Subject: compression! also bumped edition --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 3dd7f39..66b2cfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -176,6 +176,8 @@ async fn tokio_main(conf: Config) -> Result<(), Box> { // If a move is made, broadcast new board, else just send current board async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver, players: PlayerMapData, bconf: minesweeper::BoardConf) { use minesweeper::*; + use flate2::{ Compression, write::DeflateEncoder }; + use std::io::Write; let mut game = Game::new(bconf); let mut latest_player_name = None; while let Some(req) = move_rx.recv().await { @@ -192,7 +194,10 @@ async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver, p MetaMove::Reset => { game = Game::new(bconf); }, } use warp::ws::Message; - let mut reply = vec![Message::binary(game.board.render())]; + let mut board_encoder = DeflateEncoder::new(Vec::new(), Compression::default()); + board_encoder.write_all(&game.board.render()).unwrap(); + let compressed_board = board_encoder.finish().unwrap(); + let mut reply = vec![Message::binary(compressed_board)]; let lpname = latest_player_name.as_ref().map(|s| s.as_str()).unwrap_or("unknown player"); match game.phase { Phase::Win => { reply.push(Message::text(format!("win {lpname}"))); }, -- cgit v1.2.3