81 lines
1.8 KiB
Rust
81 lines
1.8 KiB
Rust
use crate::error::UnexpectedError;
|
|
use bzip2::{read::BzDecoder, Decompress};
|
|
use flate2::GzBuilder;
|
|
use std::{
|
|
fs,
|
|
io::{Read, Seek},
|
|
path::Path,
|
|
};
|
|
|
|
pub trait DataBound {}
|
|
|
|
struct Record();
|
|
|
|
impl DataBound for Record {}
|
|
struct Product {
|
|
records: Vec<Record>,
|
|
}
|
|
|
|
impl DataBound for Product {}
|
|
|
|
pub trait Loader {
|
|
type T: DataBound;
|
|
fn load(&self) -> Result<Self::T, UnexpectedError>;
|
|
}
|
|
|
|
struct ProductLoader<'a>(&'a Path);
|
|
|
|
// impl<'a> ProductLoader<'a> {
|
|
// pub fn new<P: AsRef<Path>>(p: P) -> Self {
|
|
// ProductLoader(p.as_ref())
|
|
// }
|
|
// }
|
|
|
|
trait RadarType {}
|
|
|
|
trait RecordParseStrategy {
|
|
fn parse(&self) -> Box<dyn RadarType>;
|
|
}
|
|
|
|
struct DataLoader<'a, T: RecordParseStrategy>(&'a Path, T);
|
|
|
|
impl<'a, T: RecordParseStrategy> DataLoader<'a, T> {
|
|
fn prepare(&self) -> Result<&[u8], UnexpectedError> {
|
|
let _p = self.0;
|
|
let mut _f = fs::File::open(_p)?;
|
|
let mut _magic: [u8; 3] = [0, 0, 0];
|
|
_f.read(&mut _magic)?;
|
|
|
|
match _magic {
|
|
[66, 90, 104] => BzDecoder::new(r),
|
|
[1, 1, 1] => {}
|
|
_ => {
|
|
return Err(UnexpectedError::UnknownFormat);
|
|
}
|
|
}
|
|
|
|
return Ok(());
|
|
}
|
|
pub fn parse(&self) {}
|
|
}
|
|
|
|
// impl<'a, T: RecordParseStrategy> Loader for DataLoader<'a, T> {
|
|
// type T = Record;
|
|
|
|
// fn load(&self) -> Result<Self::T, UnexpectedError> {
|
|
// let _p = self.0;
|
|
// if !_p.is_file() {
|
|
// return Err(std::io::ErrorKind::AddrInUse);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// impl<'a> Loader for ProductLoader<'a> {
|
|
// type T = Product;
|
|
// fn load(&self) -> std::io::Result<Self::T> {
|
|
// let _path = self.0;
|
|
// let _paths = fs::read_dir(_path)?;
|
|
// _paths.filter(|x| x.is_ok_and(|v| !v.path().isdir()))?;
|
|
// }
|
|
// }
|