From 88e7c6c7b66026b6c62bb75d34a5447e1b33a21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=A1?= =?UTF-8?q?=D0=B0=D1=84=D1=80=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Sun, 25 May 2025 20:40:33 +0000 Subject: [PATCH] Update src/main.rs --- src/main.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 96695bd..84942b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,7 @@ fn main() { // Print prompt print_prompt(&host, port); - // Read user input + // Read input input.clear(); io::stdin().read_line(&mut input).expect("Failed to read input"); let input = input.trim(); @@ -81,7 +81,7 @@ fn main() { print_response(&response); } Err(e) => { - eprintln!("Error: {}", e); + eprintln!("Error: {}", e.to_string().replace("KeyDB", "Futriix")); // Check if connection was lost if e.kind() == io::ErrorKind::ConnectionAborted || e.kind() == io::ErrorKind::ConnectionReset { @@ -94,17 +94,14 @@ fn main() { } fn is_valid_command(cmd: &str) -> bool { - // Basic validation - command should not be empty and should contain only printable characters if cmd.is_empty() { return false; } - // Check for control characters if cmd.chars().any(|c| c.is_control()) { return false; } - // Check for valid command structure (at least one non-whitespace character) cmd.split_whitespace().next().is_some() } @@ -115,29 +112,29 @@ fn print_prompt(host: &str, port: u16) { } fn send_command(stream: &TcpStream, command: &str) -> io::Result { - // Parse command into RESP format let parts: Vec<&str> = command.split_whitespace().collect(); let mut resp_command = String::new(); - // RESP protocol: *\r\n$\r\n\r\n... resp_command.push_str(&format!("*{}\r\n", parts.len())); for part in parts { resp_command.push_str(&format!("${}\r\n{}\r\n", part.len(), part)); } - // Send command let mut stream = stream.try_clone()?; stream.write_all(resp_command.as_bytes())?; - // Read response let mut decoder = resp::Decoder::new(&stream); decoder.decode() } fn print_response(value: &resp::Value) { match value { - resp::Value::SimpleString(s) | resp::Value::BulkString(s) => println!("{}", s), - resp::Value::Error(e) => println!("(error) {}", e), + resp::Value::SimpleString(s) | resp::Value::BulkString(s) => { + println!("{}", s.replace("KeyDB", "Futriix")) + }, + resp::Value::Error(e) => { + println!("(error) {}", e.replace("KeyDB", "Futriix")) + }, resp::Value::Integer(i) => println!("(integer) {}", i), resp::Value::Array(arr) => { for (i, item) in arr.iter().enumerate() {