[][src]Struct bitstream_io::read::ByteReader

pub struct ByteReader<R: Read, E: Endianness> { /* fields omitted */ }

For reading aligned bytes from a stream of bytes in a given endianness.

This only reads aligned values and maintains no internal state.

Implementations

impl<R: Read, E: Endianness> ByteReader<R, E>[src]

pub fn new(reader: R) -> ByteReader<R, E>[src]

Wraps a ByteReader around something that implements Read

pub fn endian(reader: R, _endian: E) -> ByteReader<R, E>[src]

Wraps a ByteReader around something that implements Read with the given endianness.

pub fn into_reader(self) -> R[src]

Unwraps internal reader and disposes of ByteReader.

pub fn reader(&mut self) -> &mut R[src]

Provides mutable reference to internal reader

pub fn into_bitreader(self) -> BitReader<R, E>[src]

Converts ByteReader to BitReader in the same endianness.

pub fn bitreader(&mut self) -> BitReader<&mut R, E>[src]

Provides temporary BitReader in the same endianness.

Warning

Any unread bits left over when BitReader is dropped are lost.

pub fn read<N>(&mut self) -> Result<N, Error> where
    N: Numeric
[src]

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};
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};
let data = [0b00000000, 0b11111111];
let mut reader = ByteReader::endian(Cursor::new(&data), LittleEndian);
assert_eq!(reader.read::<u16>().unwrap(), 0b1111111100000000);

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

Completely fills the given buffer with whole bytes.

Errors

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

Auto Trait Implementations

impl<R, E> RefUnwindSafe for ByteReader<R, E> where
    E: RefUnwindSafe,
    R: RefUnwindSafe

impl<R, E> Send for ByteReader<R, E> where
    E: Send,
    R: Send

impl<R, E> Sync for ByteReader<R, E> where
    E: Sync,
    R: Sync

impl<R, E> Unpin for ByteReader<R, E> where
    E: Unpin,
    R: Unpin

impl<R, E> UnwindSafe for ByteReader<R, E> where
    E: UnwindSafe,
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.