use core::mem::size_of;
#[inline]
#[must_use]
pub(crate) const fn usize_from_u32(val: u32) -> usize {
assert!(size_of::<usize>() >= size_of::<u32>());
#[expect(clippy::as_conversions)]
{
val as usize
}
}
#[inline]
#[must_use]
pub(crate) fn u64_from_hilo(hi: u32, lo: u32) -> u64 {
(u64::from(hi) << 32) | u64::from(lo)
}
#[inline]
#[must_use]
pub(crate) fn u32_from_hilo(hi: u16, lo: u16) -> u32 {
(u32::from(hi) << 16) | u32::from(lo)
}
#[inline]
#[must_use]
#[track_caller]
pub(crate) fn read_u16le(bytes: &[u8], offset: usize) -> u16 {
let end = offset.checked_add(size_of::<u16>()).unwrap();
let bytes = bytes.get(offset..end).unwrap();
u16::from_le_bytes(bytes.try_into().unwrap())
}
#[inline]
#[must_use]
#[track_caller]
pub(crate) fn read_u32le(bytes: &[u8], offset: usize) -> u32 {
let end = offset.checked_add(size_of::<u32>()).unwrap();
let bytes = bytes.get(offset..end).unwrap();
u32::from_le_bytes(bytes.try_into().unwrap())
}
#[inline]
#[must_use]
#[track_caller]
pub(crate) fn read_u32be(bytes: &[u8], offset: usize) -> u32 {
let end = offset.checked_add(size_of::<u32>()).unwrap();
let bytes = bytes.get(offset..end).unwrap();
u32::from_be_bytes(bytes.try_into().unwrap())
}