parser
This commit is contained in:
parent
8e785025d9
commit
207faa5ff4
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
||||
146
Cargo.lock
generated
Normal file
146
Cargo.lock
generated
Normal file
@ -0,0 +1,146 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "CINRad"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bzip2",
|
||||
"flate2",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.11+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.142"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
|
||||
dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "CINRad"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
flate2 = "1.0.25"
|
||||
thiserror = "1.0.40"
|
||||
bzip2 = "0.4.4"
|
||||
15
src/error.rs
Normal file
15
src/error.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use std::{error, io};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum UnexpectedError {
|
||||
#[error("Hei")]
|
||||
IOError {
|
||||
#[from]
|
||||
source: io::Error,
|
||||
},
|
||||
|
||||
#[error("")]
|
||||
UnknownFormat,
|
||||
}
|
||||
5
src/main.rs
Normal file
5
src/main.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod error;
|
||||
mod product;
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
80
src/product.rs
Normal file
80
src/product.rs
Normal file
@ -0,0 +1,80 @@
|
||||
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()))?;
|
||||
// }
|
||||
// }
|
||||
Loading…
Reference in New Issue
Block a user