mdf4_rs/mdf.rs
1use crate::{Result, channel_group::ChannelGroup, parsing::MdfFile};
2
3#[derive(Debug)]
4/// High level representation of an MDF file.
5///
6/// The struct stores the memory mapped file internally and lazily exposes
7/// [`ChannelGroup`] wrappers for easy inspection.
8pub struct MDF {
9 raw: MdfFile,
10}
11
12impl MDF {
13 /// Parse an MDF4 file from disk.
14 ///
15 /// # Arguments
16 /// * `path` - Path to the `.mf4` file.
17 ///
18 /// # Returns
19 /// A new [`MDF`] on success or [`crate::Error`] on failure.
20 pub fn from_file(path: &str) -> Result<Self> {
21 let raw = MdfFile::parse_from_file(path)?;
22 Ok(MDF { raw })
23 }
24
25 /// Access the raw parsed MDF file structure.
26 ///
27 /// Useful for debugging or advanced use cases.
28 pub fn raw(&self) -> &MdfFile {
29 &self.raw
30 }
31
32 /// Retrieve channel groups contained in the file.
33 ///
34 /// Each [`ChannelGroup`] is created lazily and does not decode any samples.
35 pub fn channel_groups(&self) -> Vec<ChannelGroup<'_>> {
36 let mut groups = Vec::new();
37
38 for raw_data_group in &self.raw.data_groups {
39 for raw_channel_group in &raw_data_group.channel_groups {
40 groups.push(ChannelGroup::new(
41 raw_data_group,
42 raw_channel_group,
43 &self.raw.mmap,
44 ));
45 }
46 }
47
48 groups
49 }
50}