Trait ByteRead

trait ByteRead

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

Required Methods

fn read<V>(self: &mut Self) -> Result<V, Error>
where
    V: Primitive

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);
fn read_as<F, V>(self: &mut Self) -> Result<V, Error>
where
    F: Endianness,
    V: Primitive

Reads whole numeric value from stream in a potentially different endianness

Errors

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

Examples

use std::io::{Read, Cursor};
use bitstream_io::{BigEndian, ByteReader, ByteRead, LittleEndian};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), BigEndian);
assert_eq!(reader.read_as::<LittleEndian, u16>().unwrap(), 0b1111111100000000);
use std::io::{Read, Cursor};
use bitstream_io::{BigEndian, ByteReader, ByteRead, LittleEndian};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), LittleEndian);
assert_eq!(reader.read_as::<BigEndian, u16>().unwrap(), 0b0000000011111111);
fn skip(self: &mut Self, bytes: u32) -> Result<()>

Skips the given number of bytes in the stream.

Errors

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

fn reader_ref(self: &mut Self) -> &mut dyn Read

Returns mutable reference to underlying reader

Provided Methods

fn read_bytes(self: &mut Self, buf: &mut [u8]) -> Result<()>

Completely fills the given buffer with whole bytes.

Errors

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

fn read_to_bytes<SIZE: usize>(self: &mut Self) -> Result<[u8; SIZE]>

Completely fills a whole buffer with bytes and returns it.

Errors

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

fn read_to_vec(self: &mut Self, bytes: usize) -> Result<Vec<u8>>

Completely fills a vector of bytes and returns it.

Errors

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

fn parse<F: FromByteStream>(self: &mut Self) -> Result<F, <F as >::Error>

Parses and returns complex type

fn parse_with<'a, F: FromByteStreamWith<'a>>(self: &mut Self, context: &<F as >::Context) -> Result<F, <F as >::Error>

Parses and returns complex type with context

Implementors