I am trying to read a ProtoBuffer file. I am using Prost and trying to use the prost::Message::decode_length_delimited function .
If I pass the Vector I get an error saying the Buf trait is not implemented. Passing the Cursor also results in the same error ( cannot infer type )
I understand that it does not make sense to read the entire file at once and this will be a kind of server . But I am trying to initially play around before moving to a different approach
Any help appreciated.
But I always get the following error
cargo run Compiling dnstap v0.1.0 (/home/hvram/projects/dnstap) warning: unused import: `prost::Message` --> src/main.rs:6:5 | 6 | use prost::Message; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default error[E0283]: type annotations needed --> src/main.rs:30:5 | 30 | prost::Message::decode_length_delimited(&mut buffer); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type | = note: cannot satisfy `_: prost::Message` = note: required by `decode_length_delimited` error: aborting due to previous error; 1 warning emitted For more information about this error, try `rustc --explain E0283`. error: could not compile `dnstap` To learn more, run the command again with --verbose.
fn main() -> Result<(), Box> {
println!("Hello, world!");
let mut f = File::open("dnstap.log")?;
let mut reader = BufReader::new(f);
let capacity = reader.capacity();
let mut buffer = reader.fill_buf()?;
//let mut buffer = Vec::new();
// read the whole file
//let msg = f.read_to_end(&mut buffer)?;
//let mut cursor: Cursor<Vec<u8>> = Cursor::new(buffer);
//println!("Finished Reading! {}",buffer.len());
prost::Message::decode_length_delimited(&mut buffer);
//println!("Finished Reading! {}",m1);
Ok(())
}