use crate::lib::{default, fmt, Cell, String, Vec};
pub mod consts {
pub const FIXED_HEADER_LEN: usize = 40;
pub const CASTAGOLI_OFFSET: usize = 28;
}
macro_rules! fversion {
($fixhd:expr) => {
$fixhd[2]
};
}
macro_rules! flags {
($fixhd:expr) => {
$fixhd[3]
};
}
macro_rules! nanosecond {
($fixhd:expr) => {
u32::from_le_bytes([$fixhd[4], $fixhd[5], $fixhd[6], $fixhd[7]])
};
}
macro_rules! year {
($fixhd:expr) => {
u16::from_le_bytes([$fixhd[8], $fixhd[9]])
};
}
macro_rules! day_of_year {
($fixhd:expr) => {
u16::from_le_bytes([$fixhd[10], $fixhd[11]])
};
}
macro_rules! hour {
($fixhd:expr) => {
$fixhd[12]
};
}
macro_rules! minute {
($fixhd:expr) => {
$fixhd[13]
};
}
macro_rules! second {
($fixhd:expr) => {
$fixhd[14]
};
}
macro_rules! data_payload_encoding {
($fixhd:expr) => {
$fixhd[15]
};
}
macro_rules! sample_rate {
($fixhd:expr) => {
f64::from_le_bytes([
$fixhd[16], $fixhd[17], $fixhd[18], $fixhd[19], $fixhd[20], $fixhd[21], $fixhd[22],
$fixhd[23],
])
};
}
macro_rules! sample_count {
($fixhd:expr) => {
u32::from_le_bytes([$fixhd[24], $fixhd[25], $fixhd[26], $fixhd[27]])
};
}
macro_rules! castagoli {
($fixhd:expr) => {
u32::from_le_bytes([$fixhd[28], $fixhd[29], $fixhd[30], $fixhd[31]])
};
}
macro_rules! data_public_version {
($fixhd:expr) => {
$fixhd[32]
};
}
macro_rules! sid_length {
($fixhd:expr) => {
$fixhd[33]
};
}
macro_rules! extra_headers_length {
($fixhd:expr) => {
u16::from_le_bytes([$fixhd[34], $fixhd[35]])
};
}
macro_rules! data_payload_length {
($fixhd:expr) => {
u32::from_le_bytes([$fixhd[36], $fixhd[37], $fixhd[38], $fixhd[39]])
};
}
pub struct MS3Data {
pub(crate) raw: Vec<u8>,
pub(crate) decoded: Cell<DecodedData>,
}
impl fmt::Debug for MS3Data {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let temp = self.decoded.take();
let _ = match temp {
DecodedData::None => write!(f, "DecodedData::None"),
DecodedData::Text(ref s) => write!(f, "DecodedData::Text({})", s),
DecodedData::F32(ref v) => write!(f, "DecodedData::F32({:?})", v),
DecodedData::F64(ref v) => write!(f, "DecodedData::F64({:?})", v),
DecodedData::I16(ref v) => write!(f, "DecodedData::I16({:?})", v),
DecodedData::I32(ref v) => write!(f, "DecodedData::I32({:?})", v),
DecodedData::Opaque(ref v) => write!(f, "DecodedData::Opaque({:?})", v),
};
self.decoded.set(temp);
Ok(())
}
}
impl Default for MS3Data {
fn default() -> Self {
Self {
raw: Vec::new(),
decoded: Cell::new(DecodedData::None),
}
}
}
impl MS3Data {
pub fn raw(&self) -> &[u8] {
&self.raw
}
pub fn raw_mut(&mut self) -> &mut Vec<u8> {
&mut self.raw
}
}
#[derive(Debug, Clone)]
pub enum DecodedData {
None,
Text(String),
F32(Vec<f32>),
F64(Vec<f64>),
I16(Vec<i16>),
I32(Vec<i32>),
Opaque(Vec<u8>),
}
impl default::Default for DecodedData {
fn default() -> Self {
Self::None
}
}