tycho_util/
io.rs

1// TODO: Extend with required methods.
2pub trait ByteOrderRead {
3    fn read_be_uint(&mut self, bytes: usize) -> std::io::Result<u64>;
4    fn read_byte(&mut self) -> std::io::Result<u8>;
5    fn read_le_u32(&mut self) -> std::io::Result<u32>;
6}
7
8impl<T: std::io::Read> ByteOrderRead for T {
9    #[inline]
10    fn read_be_uint(&mut self, bytes: usize) -> std::io::Result<u64> {
11        let mut buf = [0; 8];
12        self.read_exact(&mut buf[8 - bytes..])?;
13        Ok(u64::from_be_bytes(buf))
14    }
15
16    #[inline]
17    fn read_byte(&mut self) -> std::io::Result<u8> {
18        let mut buf = [0; 1];
19        self.read_exact(&mut buf)?;
20        Ok(buf[0])
21    }
22
23    #[inline]
24    fn read_le_u32(&mut self) -> std::io::Result<u32> {
25        let mut buf = [0; 4];
26        self.read_exact(&mut buf)?;
27        Ok(u32::from_le_bytes(buf))
28    }
29}