pub struct SeekReader<R> { /* private fields */ }Available on crate feature
std only.Expand description
A SeekSource over a seekable reader (Read + Seek, e.g. a File): it seeks
via std::io::Seek to the byte holding the bit cursor, without buffering —
the large-file / container-format case. For a non-seekable stream that still
needs to seek, use BufSource.
§Examples
use bnb::{bin, SeekReader};
use std::io::Cursor;
#[bin(big)]
#[derive(Debug, PartialEq)]
struct Word { value: u32 }
let mut f = SeekReader::new(Cursor::new(vec![0x12u8, 0x34, 0x56, 0x78]));
assert_eq!(Word::decode(&mut f).unwrap(), Word { value: 0x1234_5678 });Implementations§
Trait Implementations§
Source§impl<R: Clone> Clone for SeekReader<R>
impl<R: Clone> Clone for SeekReader<R>
Source§fn clone(&self) -> SeekReader<R>
fn clone(&self) -> SeekReader<R>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<R: Debug> Debug for SeekReader<R>
impl<R: Debug> Debug for SeekReader<R>
impl<R: Read + Seek> SeekSource for SeekReader<R>
Source§impl<R: Read + Seek> Source for SeekReader<R>
impl<R: Read + Seek> Source for SeekReader<R>
Source§fn read_bits(&mut self, n: u32) -> Result<u128, BitError>
fn read_bits(&mut self, n: u32) -> Result<u128, BitError>
Reads
n (<= 128) bits into the low bits of a u128, in the source’s
bit order (MSB-first by default). Read moreSource§fn byte_order(&self) -> ByteOrder
fn byte_order(&self) -> ByteOrder
The byte order applied to a byte-multiple value (default big-endian).
Source§fn bit_order(&self) -> BitOrder
fn bit_order(&self) -> BitOrder
The bit order this source reads in (default MSB-first). Paired with
byte_order to decide whether a byte-multiple value needs its
bytes swapped — each bit order has a natural byte layout (big-endian under MSB,
little-endian under LSB), and only the opposite declaration swaps.Source§fn seek_to_bit(&mut self, pos: usize) -> Result<(), BitError>
fn seek_to_bit(&mut self, pos: usize) -> Result<(), BitError>
Moves the cursor to absolute bit
pos. The default — for a forward-only
source — fails with ErrorKind::NotSeekable; seekable sources (the slice
BitReader) override it. A SeekSource guarantees this works. Read moreSource§fn read_bytes(&mut self, n: usize) -> Result<Vec<u8>, BitError>
fn read_bytes(&mut self, n: usize) -> Result<Vec<u8>, BitError>
Reads
n bytes into a fresh Vec (at any bit offset — the bytes need not be
aligned). The bulk form of the per-byte read::<u8>() loop, for blob/payload
reads in custom codecs and container formats. Read moreSource§fn read_into(&mut self, buf: &mut [u8]) -> Result<(), BitError>
fn read_into(&mut self, buf: &mut [u8]) -> Result<(), BitError>
Fills
buf with bytes from the source — the no-alloc dual of
read_bytes, for fixed scratch buffers and tight
no_std paths. Read moreSource§fn as_read(&mut self) -> SourceReader<'_, Self> ⓘwhere
Self: Sized,
fn as_read(&mut self) -> SourceReader<'_, Self> ⓘwhere
Self: Sized,
Borrows this source as a
std::io::Read over its bytes — for handing the
cursor to std::io-based code from a #[br(parse_with = …)] (e.g. a decoder, or
a Read-based parser). Reads 8 bits per byte; see SourceReader. Only with
the std feature.Auto Trait Implementations§
impl<R> Freeze for SeekReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for SeekReader<R>where
R: RefUnwindSafe,
impl<R> Send for SeekReader<R>where
R: Send,
impl<R> Sync for SeekReader<R>where
R: Sync,
impl<R> Unpin for SeekReader<R>where
R: Unpin,
impl<R> UnsafeUnpin for SeekReader<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for SeekReader<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more