-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] 39 Support Defragment of TDMS File #40
base: main
Are you sure you want to change the base?
Conversation
@@ -11,7 +11,7 @@ mod raw_data; | |||
pub use error::TdmsError; | |||
pub use file::TdmsFile; | |||
pub use file::TdmsFileWriter; | |||
pub use io::data_types::TdmsStorageType; | |||
pub use io::data_types::{TdmsStorageType, DataType}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JamesMc86 I made DataType
public so that I could use it in my high-level tests. Not sure if this is how you want to expose supported datatypes in the API.
// #todo: refactor this into a `copy_channel()` function | ||
|
||
let channel_length = input_file.channel_length(&channel_path).unwrap(); | ||
|
||
// print the channel length | ||
println!("channel_length: {:?}", channel_length); | ||
|
||
|
||
// print the channel type | ||
let channel_type = input_file.get_channel_type(&channel_path); | ||
match channel_type { | ||
Some(t) => println!("channel_type: {:?}", t), | ||
None => println!("channel_type: None"), | ||
} | ||
|
||
let channel_type = input_file.get_channel_type(&channel_path); | ||
|
||
match channel_type { | ||
|
||
Some(DataType::SingleFloat) => { | ||
let mut data: Vec<f32> = vec![0.0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::DoubleFloat) => { | ||
let mut data: Vec<f64> = vec![0.0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::I8) => { | ||
let mut data: Vec<i8> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::I16) => { | ||
let mut data: Vec<i16> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::I32) => { | ||
let mut data: Vec<i32> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::I64) => { | ||
let mut data: Vec<i64> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::U8) => { | ||
let mut data: Vec<u8> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::U16) => { | ||
let mut data: Vec<u16> = vec![0; channel_length as usize]; | ||
}, | ||
Some(DataType::U32) => { | ||
let mut data: Vec<u32> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(DataType::U64) => { | ||
let mut data: Vec<u64> = vec![0; channel_length as usize]; | ||
input_file.read_channel(&channel_path, &mut data).unwrap(); | ||
writer.write_channels(&[channel_path], &data, tedium::DataLayout::Interleaved).unwrap(); | ||
}, | ||
Some(data_type) => println!("Unsupported data type: {}", data_type), | ||
None => println!("None"), | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JamesMc86 this whole block could be refactored into a copy_channel_data
high-level API method
|
||
pub fn get_channel_type(&self, channel: &ChannelPath) -> Option<DataType> { | ||
let data_type = self.index.channel_type(channel); | ||
if let Some(data_type) = data_type { | ||
Some(*data_type) | ||
} else { | ||
None | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JamesMc86 New function allows reading a channel type from a TdmsFile
// Get the data type for the given channel. | ||
/// | ||
/// Returns None if the channel does not exist. | ||
pub fn channel_type(&self, path: &ChannelPath) -> Option<&DataType> { | ||
self.objects | ||
.get(path.path()) | ||
.and_then(|object| { | ||
object | ||
.latest_data_format | ||
.as_ref() | ||
.and_then(|format| match format { | ||
DataFormat::RawData(meta) => Some(&meta.data_type), | ||
}) | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JamesMc86 new function allows getting a channel_type from an Index
so that it can be accessed from higher level APIs
This is looking great - all looks on the right track to me |
Doing some work on a defragment function
Implements #39