code beautifying

This commit is contained in:
Martin Brodbeck 2023-10-03 19:59:11 +02:00
parent 4f714c1be1
commit e2b995a788

View file

@ -14,13 +14,6 @@ struct Client {
time: DateTime<Local>, time: DateTime<Local>,
} }
fn print_msg(msg: &[u8]) {
for elem in msg {
print!("{:08b} ", elem);
}
println!("");
}
fn strip_header(msg: &[u8]) -> Vec<u8> { fn strip_header(msg: &[u8]) -> Vec<u8> {
//print_msg(msg); //print_msg(msg);
let mut stripped = Vec::new(); let mut stripped = Vec::new();
@ -103,12 +96,6 @@ fn mopp(speed: u8, data: &[u8]) -> Vec<u8> {
m.replace_range(m.len() - 2.., "11"); // EOW m.replace_range(m.len() - 2.., "11"); // EOW
println!(
"MOPP: {1:0$}",
(8 as f32 * (m.len() as f32 / 8 as f32).ceil()) as usize,
m
);
m = format!( m = format!(
"{1:0<0$}", "{1:0<0$}",
(8 as f32 * (m.len() as f32 / 8 as f32).ceil()) as usize, (8 as f32 * (m.len() as f32 / 8 as f32).ceil()) as usize,
@ -156,10 +143,10 @@ fn main() -> std::io::Result<()> {
let data = &buf[0..number_of_bytes]; let data = &buf[0..number_of_bytes];
if receivers.iter().any(|x| x.name == client_addr) { if receivers.iter().any(|x| x.name == client_addr) {
println!("Client already known."); //println!("Client already known.");
broadcast(&socket, &receivers, &client, data); broadcast(&socket, &receivers, &client, data);
} else if strip_header(data) == strip_header(mopp(speed, b"hi").as_slice()) { } else if strip_header(data) == strip_header(mopp(speed, b"hi").as_slice()) {
println!("Welcome!"); //println!("Welcome!");
if receivers.len() < MAX_CLIENTS { if receivers.len() < MAX_CLIENTS {
receivers.insert(client.clone()); receivers.insert(client.clone());
socket socket
@ -171,7 +158,7 @@ fn main() -> std::io::Result<()> {
.unwrap(); .unwrap();
} }
} else { } else {
println!("Unknown client - Ignoring"); //println!("Unknown client - Ignoring");
} }
let timestamp = Local::now(); let timestamp = Local::now();