2023-03-19 19:06:29 +01:00
|
|
|
mod entry;
|
2023-03-19 17:13:49 +01:00
|
|
|
mod handshake;
|
|
|
|
|
2023-03-19 19:06:29 +01:00
|
|
|
use entry::Entry;
|
|
|
|
use std::io::{BufRead, BufReader};
|
|
|
|
|
|
|
|
const DEFAULT_BUFF_SIZE: usize = 1024;
|
|
|
|
|
2023-03-19 14:59:32 +01:00
|
|
|
fn main() {
|
2023-03-19 17:13:49 +01:00
|
|
|
handshake::read_config();
|
|
|
|
handshake::register_filter();
|
2023-03-19 19:06:29 +01:00
|
|
|
loop {
|
|
|
|
match read_line() {
|
|
|
|
Ok(entry) => {
|
|
|
|
if !entry.is_end_of_message() {
|
|
|
|
println!("Debug: {entry:?}");
|
|
|
|
} else {
|
|
|
|
println!("Debug: end of message: {entry:?}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
eprintln!("{err}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_line() -> Result<Entry, String> {
|
|
|
|
let mut buffer = Vec::with_capacity(DEFAULT_BUFF_SIZE);
|
|
|
|
let mut stdin = BufReader::new(std::io::stdin());
|
|
|
|
if stdin.read_until(b'\n', &mut buffer).unwrap() == 0 {
|
|
|
|
crate::eof();
|
|
|
|
}
|
|
|
|
Entry::from_bytes(&buffer)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eof() {
|
|
|
|
std::process::exit(0x2a)
|
2023-03-19 14:59:32 +01:00
|
|
|
}
|