Skip to content

Commit

Permalink
Implemented Display for DataValue and added an example for reading Ty…
Browse files Browse the repository at this point in the history
…pe 2000 frames.
  • Loading branch information
ballenspectric committed Jul 24, 2024
1 parent ffc749f commit 9d0d712
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bluefile"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,36 @@ Add the following to your project's `Cargo.toml`:
bluefile = "*"
```

Examples usage can be found in the `tests` directory.
### Reading Type 2000 frames

```rust
use std::path::PathBuf;

use bluefile::bluefile::BluefileReader;
use bluefile::data_type::DataValue;
use bluefile::type2000::Type2000Reader;

fn main() {
let args: Vec<String> = std::env::args().collect();
let path = PathBuf::from(&args[1]);
let reader = Type2000Reader::new(&path).unwrap();
let adj_header = &reader.get_adj_header();
let frame_size: usize = adj_header.subsize.try_into().unwrap();
let data_reader = &mut reader.get_data_iter().unwrap();

loop {
let frame: Vec<DataValue> = data_reader.take(frame_size).collect();

if frame.len() < frame_size {
break;
}

dbg!(frame);
}
}
```

More examples can be found in the `tests` directory.

## Running Tests

Expand Down
21 changes: 21 additions & 0 deletions src/data_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

use num::complex::Complex;

use crate::endian::Endianness;
Expand Down Expand Up @@ -117,6 +119,25 @@ pub enum DataValue {
CD(Complex<f64>),
}

impl fmt::Display for DataValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
DataValue::SB(x) => write!(f, "SB({})", x),
DataValue::SI(x) => write!(f, "SI({})", x),
DataValue::SL(x) => write!(f, "SL({})", x),
DataValue::SX(x) => write!(f, "SX({})", x),
DataValue::SF(x) => write!(f, "SF({})", x),
DataValue::SD(x) => write!(f, "SD({})", x),
DataValue::CB(x) => write!(f, "CB({})", x),
DataValue::CI(x) => write!(f, "CI({})", x),
DataValue::CL(x) => write!(f, "CL({})", x),
DataValue::CX(x) => write!(f, "CX({})", x),
DataValue::CF(x) => write!(f, "CF({})", x),
DataValue::CD(x) => write!(f, "CD({})", x),
}
}
}

/// Converts raw bytes to a bluefile data type.
pub fn bytes_to_data_value(data_type: &DataType, endianness: Endianness, buf: &Vec<u8>) -> Result<DataValue> {
match data_type {
Expand Down

0 comments on commit 9d0d712

Please sign in to comment.