use crate::error::MdfError;
use crate::parsing::mdf_file::MdfFile;
use crate::api::channel_group::ChannelGroup;
use crate::block_layout::FileLayout;
#[derive(Debug)]
pub struct MDF {
raw: MdfFile,
}
impl MDF {
#[cfg(not(target_arch = "wasm32"))]
pub fn from_file(path: &str) -> Result<Self, MdfError> {
let raw = MdfFile::parse_from_file(path)?;
Ok(MDF { raw })
}
pub fn from_bytes(data: Vec<u8>) -> Result<Self, MdfError> {
let raw = MdfFile::parse_from_bytes(data)?;
Ok(MDF { raw })
}
pub fn channel_groups(&self) -> Vec<ChannelGroup<'_>> {
let mut groups = Vec::new();
for raw_data_group in &self.raw.data_groups {
for raw_channel_group in &raw_data_group.channel_groups {
groups.push(ChannelGroup::new(
raw_data_group,
raw_channel_group,
&self.raw.mmap,
));
}
}
groups
}
pub fn start_time_ns(&self) -> Option<u64> {
let time = self.raw.header.abs_time;
if time == 0 {
None
} else {
Some(time)
}
}
pub fn file_layout(&self) -> Result<FileLayout, MdfError> {
FileLayout::from_bytes(&self.raw.mmap)
}
}