use crate::volume::util::get_datetime;
use chrono::{DateTime, Duration, Utc};
use std::fmt::Debug;
use zerocopy::{big_endian, FromBytes, Immutable, KnownLayout};
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, FromBytes, Immutable, KnownLayout)]
pub struct Header {
tape_filename: [u8; 9],
extension_number: [u8; 3],
date: big_endian::U32,
time: big_endian::U32,
icao_of_radar: [u8; 4],
}
impl Header {
pub fn tape_filename(&self) -> Option<String> {
String::from_utf8(self.tape_filename.to_vec()).ok()
}
pub fn extension_number(&self) -> Option<String> {
String::from_utf8(self.extension_number.to_vec()).ok()
}
pub fn date_time(&self) -> Option<DateTime<Utc>> {
get_datetime(
self.date.get() as u16,
Duration::milliseconds(self.time.get() as i64),
)
}
pub fn icao_of_radar(&self) -> Option<String> {
String::from_utf8(self.icao_of_radar.to_vec()).ok()
}
}