-#[derive(Copy, Clone, Debug)]
/// The endianness for integer and floating-point numbers in SPSS system files.
///
/// SPSS system files can declare IBM 370 and DEC VAX floating-point
/// representations, but no file that uses either of these has ever been found
/// in the wild, so this code does not handle them.
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Endian {
/// Big-endian: MSB at lowest address.
Big,
pub trait ToBytes<T, const N: usize> {
fn to_bytes(self, value: T) -> [u8; N];
}
+impl ToBytes<i64, 8> for Endian {
+ fn to_bytes(self, value: i64) -> [u8; 8] {
+ match self {
+ Endian::Big => i64::to_be_bytes(value),
+ Endian::Little => i64::to_le_bytes(value),
+ }
+ }
+}
+impl ToBytes<u32, 4> for Endian {
+ fn to_bytes(self, value: u32) -> [u8; 4] {
+ match self {
+ Endian::Big => u32::to_be_bytes(value),
+ Endian::Little => u32::to_le_bytes(value),
+ }
+ }
+}
+impl ToBytes<i32, 4> for Endian {
+ fn to_bytes(self, value: i32) -> [u8; 4] {
+ match self {
+ Endian::Big => i32::to_be_bytes(value),
+ Endian::Little => i32::to_le_bytes(value),
+ }
+ }
+}
+impl ToBytes<u16, 2> for Endian {
+ fn to_bytes(self, value: u16) -> [u8; 2] {
+ match self {
+ Endian::Big => u16::to_be_bytes(value),
+ Endian::Little => u16::to_le_bytes(value),
+ }
+ }
+}
+impl ToBytes<u8, 1> for Endian {
+ fn to_bytes(self, value: u8) -> [u8; 1] {
+ [value]
+ }
+}
impl ToBytes<f64, 8> for Endian {
fn to_bytes(self, value: f64) -> [u8; 8] {
match self {