use std::io::Read;

#[derive(Debug)]
pub struct NomReader<R: Read> {
    inner: R
}
impl<R: Read> NomReader<R> {
    pub fn new(inner: R) -> NomReader<R> {
        Self {
            inner
        }
    }

    pub fn read_u8(&mut self) -> Result<u8, std::io::Error> {
        let mut buf = [0u8; 1];
        self.inner.read_exact(&mut buf)?;
        Ok(u8::from_be_bytes(buf))
    }
    pub fn read_u16(&mut self) -> Result<u16, std::io::Error> {
        let mut buf = [0u8; 2];
        self.inner.read_exact(&mut buf)?;
        Ok(u16::from_be_bytes(buf))
    }
    pub fn read_u32(&mut self) -> Result<u32, std::io::Error> {
        let mut buf = [0u8; 4];
        self.inner.read_exact(&mut buf)?;
        Ok(u32::from_be_bytes(buf))
    }
    pub fn read_u64(&mut self) -> Result<u64, std::io::Error> {
        let mut buf = [0u8; 8];
        self.inner.read_exact(&mut buf)?;
        Ok(u64::from_be_bytes(buf))
    }
    pub fn read_n(&mut self, n: usize) -> Result<Vec<u8>, std::io::Error> {
        let mut buf = vec![0u8; n];
        self.inner.read_exact(&mut buf)?;
        Ok(buf)
    }
    pub fn read_f32(&mut self) -> Result<f32, std::io::Error> {
        let mut buf = [0u8; 4];
        self.inner.read_exact(&mut buf)?;
        Ok(f32::from_be_bytes(buf))
    }
}