use crate::DecodingError;
use std::io::{self, Write};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Header {
ChtV1,
}
impl Header {
pub const fn cht_v1() -> Self {
Self::ChtV1
}
pub fn write<W: Write>(self, writer: &mut W) -> Result<(), io::Error> {
match self {
Self::ChtV1 => writer.write_all(&[1]),
}
}
pub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodingError> {
if bytes.first() == Some(&1) {
return Ok(Self::cht_v1());
}
Err(DecodingError::bad_header("cannot decode"))
}
pub const fn len(self) -> usize {
match self {
Self::ChtV1 => 1,
}
}
}