use std::io;
use speedy::{Readable, Writable};
use byteorder::ReadBytesExt;
#[derive(Debug, PartialEq, Eq, Clone, Copy, Readable, Writable)]
pub struct RepresentationIdentifier {
pub(crate) bytes: [u8; 2], }
impl RepresentationIdentifier {
pub const CDR_BE: Self = Self {
bytes: [0x00, 0x00],
};
pub const CDR_LE: Self = Self {
bytes: [0x00, 0x01],
};
pub const PL_CDR_BE: Self = Self {
bytes: [0x00, 0x02],
};
pub const PL_CDR_LE: Self = Self {
bytes: [0x00, 0x03],
};
pub const CDR2_BE: Self = Self {
bytes: [0x00, 0x10],
};
pub const CDR2_LE: Self = Self {
bytes: [0x00, 0x11],
};
pub const PL_CDR2_BE: Self = Self {
bytes: [0x00, 0x12],
};
pub const PL_CDR2_LE: Self = Self {
bytes: [0x00, 0x13],
};
pub const D_CDR_BE: Self = Self {
bytes: [0x00, 0x14],
};
pub const D_CDR_LE: Self = Self {
bytes: [0x00, 0x15],
};
pub const XML: Self = Self {
bytes: [0x00, 0x04],
};
pub const XCDR2_BE: Self = Self {
bytes: [0x00, 0x06],
};
pub const XCDR2_LE: Self = Self {
bytes: [0x00, 0x07],
};
pub const D_CDR2_BE: Self = Self {
bytes: [0x00, 0x08],
};
pub const D_CDR2_LE: Self = Self {
bytes: [0x00, 0x09],
};
pub const PL_XCDR2_BE: Self = Self {
bytes: [0x00, 0x0a],
};
pub const PL_XCDR2_LE: Self = Self {
bytes: [0x00, 0x0b],
};
pub fn from_bytes(bytes: &[u8]) -> io::Result<Self> {
let mut reader = io::Cursor::new(bytes);
Ok(Self {
bytes: [reader.read_u8()?, reader.read_u8()?],
})
}
pub fn to_bytes(self) -> [u8; 2] {
self.bytes
}
}