pub fn read_all_with_limit(
reader: impl Read,
max_bytes: usize,
) -> Result<Vec<u8>>Expand description
Reads all available bytes from a reader while enforcing a hard limit.
Examples found in repository?
examples/process_file.rs (line 13)
7fn main() -> std::io::Result<()> {
8 let Some(path) = std::env::args().nth(1) else {
9 eprintln!("usage: process_file <packets.aprs>");
10 std::process::exit(2);
11 };
12
13 let input = read_all_with_limit(File::open(path)?, DEFAULT_TRANSPORT_READ_LIMIT)?;
14 let mut engine = Engine::new(Policy::strict());
15
16 for packet_bytes in LineTransport::new(&input).packets() {
17 match engine.process(packet_bytes) {
18 EngineResult::Accepted { packet } => {
19 let summary = packet.summary();
20 println!(
21 "accepted source={} destination={} semantic={}",
22 String::from_utf8_lossy(summary.source),
23 String::from_utf8_lossy(summary.destination),
24 summary.semantic
25 );
26 }
27 EngineResult::Rejected { reason, .. } => eprintln!("rejected: {}", reason.code()),
28 EngineResult::ParseError(error) => eprintln!("malformed: {}", error.code()),
29 }
30 }
31
32 Ok(())
33}