diff --git a/Cargo.toml b/Cargo.toml index 717be89..1b283bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,6 @@ default = ["parser", "rustls"] parser = [ "bytes", "chrono", - "env_logger", "regex", ] cli = [ diff --git a/src/error.rs b/src/error.rs index ca3d13d..be71320 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ error module defines the error types used in bgpkit-parser. */ use crate::models::{Afi, Bgp4MpType, BgpState, EntryType, Safi, TableDumpV2Type}; use num_enum::TryFromPrimitiveError; +#[cfg(feature = "oneio")] use oneio::OneIoError; use std::fmt::{Display, Formatter}; use std::io::ErrorKind; @@ -12,6 +13,7 @@ use std::{error::Error, fmt, io}; pub enum ParserError { IoError(io::Error), EofError(io::Error), + #[cfg(feature = "oneio")] OneIoError(OneIoError), EofExpected, ParseError(String), @@ -47,12 +49,14 @@ impl Display for ParserError { ParserError::TruncatedMsg(s) => write!(f, "Error: {}", s), ParserError::Unsupported(s) => write!(f, "Error: {}", s), ParserError::EofExpected => write!(f, "Error: reach end of file"), + #[cfg(feature = "oneio")] ParserError::OneIoError(e) => write!(f, "Error: {}", e), ParserError::FilterError(e) => write!(f, "Error: {}", e), } } } +#[cfg(feature = "oneio")] impl From for ParserErrorWithBytes { fn from(error: OneIoError) -> Self { ParserErrorWithBytes { @@ -62,6 +66,7 @@ impl From for ParserErrorWithBytes { } } +#[cfg(feature = "oneio")] impl From for ParserError { fn from(error: OneIoError) -> Self { ParserError::OneIoError(error) diff --git a/src/parser/iters.rs b/src/parser/iters.rs index a1bd1c2..64470b9 100644 --- a/src/parser/iters.rs +++ b/src/parser/iters.rs @@ -114,7 +114,9 @@ impl Iterator for RecordIterator { } None } - ParserError::OneIoError(_) | ParserError::FilterError(_) => { + #[cfg(feature = "oneio")] + ParserError::OneIoError(_) => None, + ParserError::FilterError(_) => { // this should not happen at this stage None } diff --git a/src/parser/mod.rs b/src/parser/mod.rs index ead492a..3f80b4d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -18,6 +18,7 @@ pub(crate) use self::utils::*; use crate::models::MrtRecord; pub use mrt::mrt_elem::Elementor; +#[cfg(feature = "oneio")] use oneio::{get_cache_reader, get_reader}; pub use crate::error::{ParserError, ParserErrorWithBytes}; @@ -48,7 +49,18 @@ impl Default for ParserOptions { } impl BgpkitParser> { + /// Creating a new parser from an object that implements [Read] trait. + pub fn new_with_reader(reader: Box) -> Self { + BgpkitParser { + reader, + core_dump: false, + filters: vec![], + options: ParserOptions::default(), + } + } + /// Creating a new parser from a object that implements [Read] trait. + #[cfg(feature = "oneio")] pub fn new(path: &str) -> Result { let reader = get_reader(path)?; Ok(BgpkitParser { @@ -64,6 +76,7 @@ impl BgpkitParser> { /// The cache file name is generated by the following format: `cache--`. /// For example, the remote file `http://archive.routeviews.org/route-views.chile/bgpdata/2023.03/RIBS/rib.20230326.0600.bz2` /// will be cached as `cache-682cb1eb-rib.20230326.0600.bz2` in the cache directory. + #[cfg(feature = "oneio")] pub fn new_cached(path: &str, cache_dir: &str) -> Result { let file_name = path.rsplit('/').next().unwrap().to_string(); let new_file_name = format!( @@ -80,6 +93,7 @@ impl BgpkitParser> { } } +#[cfg(feature = "oneio")] fn add_suffix_to_filename(filename: &str, suffix: &str) -> String { let mut parts: Vec<&str> = filename.split('.').collect(); // Split filename by dots if parts.len() > 1 {