Skip to main content

BytesReader

Struct BytesReader 

Source
pub struct BytesReader { /* private fields */ }
Available on crate feature bytes only.
Expand description

A SeekSource that owns a bytes::Bytes frame (no borrow), decoding bits from it. Constructing it from a Bytes is a refcount bump (zero copy).

Implementations§

Source§

impl BytesReader

Source

pub fn new(data: Bytes) -> Self

Owns data, positioned at bit 0, MSB-first big-endian.

Source

pub fn with_layout(data: Bytes, layout: Layout) -> Self

Owns data with the given Layout.

Trait Implementations§

Source§

impl Clone for BytesReader

Source§

fn clone(&self) -> BytesReader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BytesReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl SeekSource for BytesReader

Source§

impl Source for BytesReader

Source§

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 more
Source§

fn bit_pos(&self) -> usize

The current absolute bit offset (for position-aware errors).
Source§

fn byte_order(&self) -> ByteOrder

The byte order applied to a byte-multiple value (default big-endian).
Source§

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>

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 more
Source§

fn read<T: Bits>(&mut self) -> Result<T, BitError>

Reads one Bits value of its declared width, applying the byte order. Read more
Source§

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 more
Source§

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 more
Source§

fn as_read(&mut self) -> SourceReader<'_, Self>
where Self: Sized,

Available on crate feature std only.
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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more