use std::io::prelude::*;
use std::net::TcpStream;
use std::str;
use rotating_buffer::RotatingBuffer;
fn main() -> std::io::Result<()> {
let mut buf = RotatingBuffer::<u8, 5>::new();
let mut stream = TcpStream::connect("127.0.0.1:34254")?;
loop {
let read_size = stream.read(buf.get_append_only())?;
if read_size != 0 {
let _buf_size = buf.add_len(read_size);
}
let incoming = str::from_utf8(buf.as_slice()).unwrap();
if !incoming.ends_with("EOF\n") && read_size != 0 || incoming.len() > 4 {
if let Some(index) = incoming.rfind(',') {
for value in incoming[..index].split(',') {
println!("{}", value);
}
buf.rotate_right_and_resize_at(index + 1);
} else {
print!("{}", incoming);
buf.resize(0);
}
} else {
return Ok(());
}
}
}