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

Use u32 and u16 from_xx_bytes #42

Merged
merged 1 commit into from
Nov 29, 2024
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
14 changes: 4 additions & 10 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ pub fn read_u32<R: BufRead + Seek>(reader: &mut R, endianness: &Endian) -> Image
reader.read_exact(&mut buf)?;

match endianness {
Endian::Little => Ok(((buf[3] as u32) << 24)
| ((buf[2] as u32) << 16)
| ((buf[1] as u32) << 8)
| (buf[0] as u32)),
Endian::Big => Ok(((buf[0] as u32) << 24)
| ((buf[1] as u32) << 16)
| ((buf[2] as u32) << 8)
| (buf[3] as u32)),
Endian::Little => Ok(u32::from_le_bytes(buf)),
Endian::Big => Ok(u32::from_be_bytes(buf)),
}
}

Expand All @@ -47,8 +41,8 @@ pub fn read_u16<R: BufRead + Seek>(reader: &mut R, endianness: &Endian) -> Image
reader.read_exact(&mut buf)?;

match endianness {
Endian::Little => Ok(((buf[1] as u16) << 8) | (buf[0] as u16)),
Endian::Big => Ok(((buf[0] as u16) << 8) | (buf[1] as u16)),
Endian::Little => Ok(u16::from_le_bytes(buf)),
Endian::Big => Ok(u16::from_be_bytes(buf)),
}
}

Expand Down
Loading