diff --git a/src/main.rs b/src/main.rs index 43a0887..feee87f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,6 +90,8 @@ async fn main() -> Result<(), Box> { debug!("Sending commands"); + let mut response: fedichat::client::ServerMessage = ServerMessage::Ok; + for message in messages { let mut buf = Vec::new(); @@ -104,7 +106,7 @@ async fn main() -> Result<(), Box> { // Max response should never be this big but we can spare the memory let received = recv.read_to_end(1000 * 1000).await?; - let response: fedichat::client::ServerMessage = rmp_serde::from_slice(&received)?; + response = rmp_serde::from_slice(&received)?; // If we received a message that gave us a new token then update the local copy match response { ServerMessage::Token(ref token) => { @@ -114,12 +116,15 @@ async fn main() -> Result<(), Box> { let mut file = File::create(file_to_write.clone().expect("File path not specified"))?; file.write_all(bytes)?; }, + ServerMessage::Error(_) => { + break; + }, _ => {} } - println!("{:?}",response); } + println!("{}",format_response(response)); // On listen specifically we will stay connected @@ -128,6 +133,13 @@ async fn main() -> Result<(), Box> { Ok(()) - +} + +fn format_response(m: ServerMessage) -> String { + match m { + ServerMessage::Media(_) => "File received".to_string(), + m => format!("{:?}",m) + + } }