Skip to main content

BsvReader

Struct BsvReader 

Source
pub struct BsvReader<'a> { /* private fields */ }
Expand description

A cursor-based reader for Bitcoin protocol binary data.

Wraps a byte slice and maintains a read position, providing methods to read fixed-size integers and VarInt values in little-endian order.

Implementations§

Source§

impl<'a> BsvReader<'a>

Source

pub fn new(data: &'a [u8]) -> Self

Create a new reader over the given byte slice.

§Arguments
  • data - The byte slice to read from.
§Returns

A BsvReader positioned at the start of the data.

Source

pub fn read_bytes(&mut self, n: usize) -> Result<&'a [u8], PrimitivesError>

Read n bytes and advance the position.

§Arguments
  • n - Number of bytes to read.
§Returns

A byte slice of length n, or an error if insufficient data remains.

Source

pub fn read_u8(&mut self) -> Result<u8, PrimitivesError>

Read a single byte and advance the position.

§Returns

The byte value, or an error if no data remains.

Source

pub fn read_u16_le(&mut self) -> Result<u16, PrimitivesError>

Read a little-endian u16 and advance the position by 2 bytes.

§Returns

The decoded u16, or an error if insufficient data.

Source

pub fn read_u32_le(&mut self) -> Result<u32, PrimitivesError>

Read a little-endian u32 and advance the position by 4 bytes.

§Returns

The decoded u32, or an error if insufficient data.

Source

pub fn read_u64_le(&mut self) -> Result<u64, PrimitivesError>

Read a little-endian u64 and advance the position by 8 bytes.

§Returns

The decoded u64, or an error if insufficient data.

Source

pub fn read_varint(&mut self) -> Result<VarInt, PrimitivesError>

Read a VarInt and advance the position accordingly.

§Returns

The decoded VarInt, or an error if insufficient data.

Source

pub fn remaining(&self) -> usize

Return the number of bytes remaining.

§Returns

The count of unread bytes.

Auto Trait Implementations§

§

impl<'a> Freeze for BsvReader<'a>

§

impl<'a> RefUnwindSafe for BsvReader<'a>

§

impl<'a> Send for BsvReader<'a>

§

impl<'a> Sync for BsvReader<'a>

§

impl<'a> Unpin for BsvReader<'a>

§

impl<'a> UnsafeUnpin for BsvReader<'a>

§

impl<'a> UnwindSafe for BsvReader<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V