X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=rust%2Fsrc%2Fendian.rs;h=bb63ec518dd832bdc10b069065bb7ce95f33a040;hb=20e2af4ec687ccbdfe47fe30275dd0121ec3ec16;hp=dd562e60eff7c9cf8500879f1064c41618ba5ae7;hpb=b8f1dedca099b32b4b4b4dda5f265cc1e8db9587;p=pspp diff --git a/rust/src/endian.rs b/rust/src/endian.rs index dd562e60ef..bb63ec518d 100644 --- a/rust/src/endian.rs +++ b/rust/src/endian.rs @@ -37,6 +37,43 @@ impl Endian { pub trait ToBytes { fn to_bytes(self, value: T) -> [u8; N]; } +impl ToBytes 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 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 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 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 for Endian { + fn to_bytes(self, value: u8) -> [u8; 1] { + [value] + } +} impl ToBytes for Endian { fn to_bytes(self, value: f64) -> [u8; 8] { match self {