Skip to content

Commit 9d0d712

Browse files
Implemented Display for DataValue and added an example for reading Type 2000 frames.
1 parent ffc749f commit 9d0d712

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bluefile"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2021"
55
license = "Apache-2.0"
66
readme = "README.md"

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,36 @@ Add the following to your project's `Cargo.toml`:
1111
bluefile = "*"
1212
```
1313

14-
Examples usage can be found in the `tests` directory.
14+
### Reading Type 2000 frames
15+
16+
```rust
17+
use std::path::PathBuf;
18+
19+
use bluefile::bluefile::BluefileReader;
20+
use bluefile::data_type::DataValue;
21+
use bluefile::type2000::Type2000Reader;
22+
23+
fn main() {
24+
let args: Vec<String> = std::env::args().collect();
25+
let path = PathBuf::from(&args[1]);
26+
let reader = Type2000Reader::new(&path).unwrap();
27+
let adj_header = &reader.get_adj_header();
28+
let frame_size: usize = adj_header.subsize.try_into().unwrap();
29+
let data_reader = &mut reader.get_data_iter().unwrap();
30+
31+
loop {
32+
let frame: Vec<DataValue> = data_reader.take(frame_size).collect();
33+
34+
if frame.len() < frame_size {
35+
break;
36+
}
37+
38+
dbg!(frame);
39+
}
40+
}
41+
```
42+
43+
More examples can be found in the `tests` directory.
1544

1645
## Running Tests
1746

src/data_type.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
use num::complex::Complex;
24

35
use crate::endian::Endianness;
@@ -117,6 +119,25 @@ pub enum DataValue {
117119
CD(Complex<f64>),
118120
}
119121

122+
impl fmt::Display for DataValue {
123+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
124+
match self {
125+
DataValue::SB(x) => write!(f, "SB({})", x),
126+
DataValue::SI(x) => write!(f, "SI({})", x),
127+
DataValue::SL(x) => write!(f, "SL({})", x),
128+
DataValue::SX(x) => write!(f, "SX({})", x),
129+
DataValue::SF(x) => write!(f, "SF({})", x),
130+
DataValue::SD(x) => write!(f, "SD({})", x),
131+
DataValue::CB(x) => write!(f, "CB({})", x),
132+
DataValue::CI(x) => write!(f, "CI({})", x),
133+
DataValue::CL(x) => write!(f, "CL({})", x),
134+
DataValue::CX(x) => write!(f, "CX({})", x),
135+
DataValue::CF(x) => write!(f, "CF({})", x),
136+
DataValue::CD(x) => write!(f, "CD({})", x),
137+
}
138+
}
139+
}
140+
120141
/// Converts raw bytes to a bluefile data type.
121142
pub fn bytes_to_data_value(data_type: &DataType, endianness: Endianness, buf: &Vec<u8>) -> Result<DataValue> {
122143
match data_type {

0 commit comments

Comments
 (0)