use pack_io::{Decoder, Encoder};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut buf: Vec<u8> = Vec::with_capacity(256);
for round in 0..3 {
let mut enc = Encoder::into_buffer(buf);
enc.write(&(round as u64))?;
enc.write(&format!("round-{round}"))?;
enc.write(&true)?;
buf = enc.into_inner();
println!(
"round {round} encoded into {} bytes (capacity {})",
buf.len(),
buf.capacity()
);
let mut dec = Decoder::new(&buf);
let n: u64 = dec.read()?;
let s: String = dec.read()?;
let b: bool = dec.read()?;
assert!(dec.is_empty());
println!(" decoded: ({n}, {s:?}, {b})");
buf.clear();
}
Ok(())
}