forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust381.2 MiBe18142dTahinli4 hours ago4543 commits

bytes.rs17 lines, 497 bytesHistoryRawDownload
1pub(crate) fn u16_at(data: &[u8], at: usize, big_endian: bool) -> Option<u16> {
2 let b: [u8; 2] = data.get(at..at + 2)?.try_into().ok()?;
3 Some(if big_endian {
4 u16::from_be_bytes(b)
5 } else {
6 u16::from_le_bytes(b)
7 })
8}
9
10pub(crate) fn u32_at(data: &[u8], at: usize, big_endian: bool) -> Option<u32> {
11 let b: [u8; 4] = data.get(at..at + 4)?.try_into().ok()?;
12 Some(if big_endian {
13 u32::from_be_bytes(b)
14 } else {
15 u32::from_le_bytes(b)
16 })
17}