pub mod parser_rrc;
use crate::data::AdditionalInfos;
use crate::data::Trace;
use crate::errors::ErrorCode;
use crate::errors::TramexError;
use crate::tramex_error;
use chrono::NaiveTime;
use chrono::Timelike;
pub struct ParsingError {
pub message: String,
pub line_idx: u64,
}
impl ParsingError {
pub fn new(message: String, line_idx: u64) -> Self {
Self { message, line_idx }
}
}
#[inline]
pub fn parsing_error_to_tramex_error(error: ParsingError, idx: u64) -> TramexError {
let index = idx + error.line_idx;
tramex_error!(format!("{} (line {})", error.message, index), ErrorCode::FileParsing)
}
pub trait FileParser {
fn parse_additional_infos(line: &[String]) -> Result<AdditionalInfos, ParsingError>;
fn parse(lines: &[String]) -> Result<Trace, ParsingError>;
}
#[inline]
pub fn time_to_milliseconds(time: &NaiveTime) -> i64 {
let hours_in_ms = time.hour() as i64 * 3_600_000;
let minutes_in_ms = time.minute() as i64 * 60_000;
let seconds_in_ms = time.second() as i64 * 1000;
let milliseconds = time.nanosecond() as i64 / 1_000_000; hours_in_ms + minutes_in_ms + seconds_in_ms + milliseconds
}
#[inline]
pub fn eof_error(line_idx: u64) -> TramexError {
tramex_error!(
format!("End of file (line {})", line_idx),
crate::errors::ErrorCode::EndOfFile
)
}