#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum Endian {
#[default]
Little,
Big,
}
impl Endian {
pub fn u16(self, bytes: [u8; 2]) -> u16 {
match self {
Self::Little => u16::from_le_bytes(bytes),
Self::Big => u16::from_be_bytes(bytes),
}
}
pub fn i16(self, bytes: [u8; 2]) -> i16 {
match self {
Self::Little => i16::from_le_bytes(bytes),
Self::Big => i16::from_be_bytes(bytes),
}
}
pub fn u32(self, bytes: [u8; 4]) -> u32 {
match self {
Self::Little => u32::from_le_bytes(bytes),
Self::Big => u32::from_be_bytes(bytes),
}
}
pub fn i32(self, bytes: [u8; 4]) -> i32 {
match self {
Self::Little => i32::from_le_bytes(bytes),
Self::Big => i32::from_be_bytes(bytes),
}
}
pub fn u64(self, bytes: [u8; 8]) -> u64 {
match self {
Self::Little => u64::from_le_bytes(bytes),
Self::Big => u64::from_be_bytes(bytes),
}
}
pub fn i64(self, bytes: [u8; 8]) -> i64 {
match self {
Self::Little => i64::from_le_bytes(bytes),
Self::Big => i64::from_be_bytes(bytes),
}
}
pub fn f32(self, bytes: [u8; 4]) -> f32 {
f32::from_bits(self.u32(bytes))
}
pub fn f64(self, bytes: [u8; 8]) -> f64 {
f64::from_bits(self.u64(bytes))
}
}