Skip to main content

process_file/
process_file.rs

1use std::fs::File;
2
3use libaprs_engine::{
4    read_all_with_limit, Engine, EngineResult, LineTransport, Policy, DEFAULT_TRANSPORT_READ_LIMIT,
5};
6
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 } => println!("{}", packet.to_json()),
19            EngineResult::Rejected { reason, .. } => eprintln!("rejected: {}", reason.code()),
20            EngineResult::ParseError(error) => eprintln!("malformed: {}", error.code()),
21        }
22    }
23
24    Ok(())
25}