Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to LE byte order in all cases #77

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/serde_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ macro_rules! impl_ser_de_bin_for {
($ty:ident) => {
impl SerBin for $ty {
fn ser_bin(&self, s: &mut Vec<u8>) {
let du8 = self.to_ne_bytes();
let du8 = self.to_le_bytes();
s.extend_from_slice(&du8);
}
}
Expand All @@ -108,10 +108,13 @@ macro_rules! impl_ser_de_bin_for {
s: d.len(),
});
}
let mut m = [0 as $ty];
m[0] = <$ty>::from_ne_bytes(d[*o..(*o + l)].try_into().unwrap());

// We just checked that the correct amount of bytes are available,
// and there are no invalid bit patterns for these primitives. This
// unwrap should be impossible to hit.
let ret: $ty = <$ty>::from_le_bytes(d[*o..(*o + l)].try_into().unwrap());
*o += l;
Ok(m[0])
Ok(ret)
}
}
};
Expand All @@ -132,7 +135,7 @@ impl_ser_de_bin_for!(i8);
impl SerBin for usize {
fn ser_bin(&self, s: &mut Vec<u8>) {
let u64usize = *self as u64;
let du8 = u64usize.to_ne_bytes();
let du8 = u64usize.to_le_bytes();
s.extend_from_slice(&du8);
}
}
Expand All @@ -142,7 +145,7 @@ impl DeBin for usize {
let l = core::mem::size_of::<u64>();

let m = match d.get(*o..*o + l) {
Some(data) => u64::from_ne_bytes(data.try_into().unwrap()),
Some(data) => u64::from_le_bytes(data.try_into().unwrap()),
None => {
return Err(DeBinErr {
o: *o,
Expand Down
Loading