pub trait ByteRead {
    fn read<N: Numeric>(&mut self) -> Result<N, Error>;
    fn skip(&mut self, bytes: u32) -> Result<()>;

    fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()> { ... }
    fn read_to_bytes<const SIZE: usize>(&mut self) -> Result<[u8; SIZE]> { ... }
    fn read_to_vec(&mut self, bytes: usize) -> Result<Vec<u8>> { ... }
}
Expand description

A trait for anything that can read aligned values from an input stream

Required Methods

Reads whole numeric value from stream

Errors

Passes along any I/O error from the underlying stream.

Examples
use std::io::{Read, Cursor};
use bitstream_io::{BigEndian, ByteReader, ByteRead};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), BigEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b0000000011111111);
use std::io::{Read, Cursor};
use bitstream_io::{LittleEndian, ByteReader, ByteRead};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), LittleEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b1111111100000000);

Skips the given number of bytes in the stream.

Errors

Passes along any I/O error from the underlying stream.

Provided Methods

Completely fills the given buffer with whole bytes.

Errors

Passes along any I/O error from the underlying stream.

Completely fills a whole buffer with bytes and returns it.

Errors

Passes along any I/O error from the underlying stream.

Completely fills a vector of bytes and returns it.

Errors

Passes along any I/O error from the underlying stream.

Implementors