mrt-rs 1.1.1

A library for parsing Multi-Threaded Routing Toolkit (MRT) formatted streams.
Documentation

The mrt-rs crate provides functionality to parse an MRT-formatted streams.

Examples

Reading a MRT file containing BPG messages

use std::fs::File;
use std::io::Cursor;
use std::io::Read;
use std::io::BufReader;
use mrt_rs::{Reader, Record};
use mrt_rs::bgp4mp::BGP4MP;
use libflate::gzip::Decoder;

fn main() {
// Open an MRT-formatted file.
let file = File::open("res/updates.20190101.0000.gz").unwrap();

// Decode the GZIP stream using BufReader for better performance.
let mut decoder = Decoder::new(BufReader::new(file)).unwrap();

// Create a new Reader with a Cursor such that we can keep track of the position.
let mut reader = Reader { stream: decoder };

// Keep reading (Header, Record) tuples till the end of the file has been reached.
while let Ok(Some((header, record))) = reader.read() {
match record {
Record::BGP4MP(x) => match x {
BGP4MP::MESSAGE(y) => println!("{:?}", y),
BGP4MP::MESSAGE_AS4(y) => println!("{:?}", y),
_ => continue,
},
_ => continue,
}
}
}