Skip to main content

process_capnp

Function process_capnp 

Source
pub fn process_capnp<R>(reader: R, visitor: &mut dyn TraceVisitor)
where R: BufRead,
Expand description

Process a given Cap’n Proto file calling the visitor for each event found.

§Examples

A simple visitor that will count how many IDs are used.

use std::fs::File;
use std::io::BufReader;

use gwr_track::Id;
use gwr_track::trace_visitor::{TraceVisitor, process_capnp};

struct IdCounter {
    pub count: usize,
}

impl IdCounter {
    fn new() -> Self {
        Self { count: 0 }
    }
}

impl TraceVisitor for IdCounter {
    fn create_entity(&mut self, _created_by: Id, _id: Id, _name: &str) {
        self.count += 1;
    }
}

let f = File::open("capnp.bin")?;
let mut reader = BufReader::new(f);
let mut visitor = IdCounter::new();
process_capnp(&mut reader, &mut visitor);
println!("{} IDs seen", visitor.count);