pub mod default;
pub mod fallible;
mod raw;
mod update;
pub use default::{ElemIterator, RecordIterator};
pub use fallible::{FallibleElemIterator, FallibleRecordIterator};
pub use raw::RawRecordIterator;
pub use update::{
Bgp4MpUpdate, FallibleUpdateIterator, MrtUpdate, TableDumpV2Entry, UpdateIterator,
};
use crate::models::BgpElem;
use crate::models::{MrtMessage, MrtRecord, TableDumpV2Message};
use crate::parser::BgpkitParser;
use crate::Elementor;
use crate::RawMrtRecord;
use std::io::Read;
impl<R: Read> IntoIterator for BgpkitParser<R> {
type Item = BgpElem;
type IntoIter = ElemIterator<R>;
fn into_iter(self) -> Self::IntoIter {
ElemIterator::new(self)
}
}
impl<R> BgpkitParser<R> {
pub fn into_record_iter(self) -> RecordIterator<R> {
RecordIterator::new(self)
}
pub fn into_elem_iter(self) -> ElemIterator<R> {
ElemIterator::new(self)
}
pub fn into_raw_record_iter(self) -> RawRecordIterator<R> {
RawRecordIterator::new(self)
}
pub fn into_update_iter(self) -> UpdateIterator<R> {
UpdateIterator::new(self)
}
pub fn into_fallible_record_iter(self) -> FallibleRecordIterator<R> {
FallibleRecordIterator::new(self)
}
pub fn into_fallible_elem_iter(self) -> FallibleElemIterator<R> {
FallibleElemIterator::new(self)
}
pub fn into_fallible_update_iter(self) -> FallibleUpdateIterator<R> {
FallibleUpdateIterator::new(self)
}
pub fn into_elementor_and_raw_record_iter(
self,
) -> (Elementor, impl Iterator<Item = RawMrtRecord>)
where
R: Read,
{
let mut raw_iter = RawRecordIterator::new(self).peekable();
let elementor = match raw_iter.peek().cloned().and_then(|r| r.parse().ok()) {
Some(MrtRecord {
message: MrtMessage::TableDumpV2Message(TableDumpV2Message::PeerIndexTable(pit)),
..
}) => {
raw_iter.next();
Elementor::with_peer_table(pit)
}
_ => Elementor::new(),
};
(elementor, raw_iter)
}
pub fn into_elementor_and_record_iter(self) -> (Elementor, impl Iterator<Item = MrtRecord>)
where
R: Read,
{
let mut record_iter = RecordIterator::new(self).peekable();
let elementor = match record_iter.peek().cloned() {
Some(MrtRecord {
message: MrtMessage::TableDumpV2Message(TableDumpV2Message::PeerIndexTable(pit)),
..
}) => {
record_iter.next();
Elementor::with_peer_table(pit)
}
_ => Elementor::new(),
};
(elementor, record_iter)
}
}