Skip to main content

BsvWriter

Struct BsvWriter 

Source
pub struct BsvWriter { /* private fields */ }
Expand description

A buffer-based writer for Bitcoin protocol binary data.

Wraps a Vec<u8> and provides methods to append fixed-size integers and VarInt values in little-endian order.

Implementations§

Source§

impl BsvWriter

Source

pub fn new() -> Self

Create a new empty writer.

§Returns

A BsvWriter with an empty internal buffer.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new writer with a pre-allocated capacity.

§Arguments
  • capacity - Initial byte capacity of the internal buffer.
§Returns

A BsvWriter with the given capacity.

Source

pub fn write_bytes(&mut self, bytes: &[u8])

Append raw bytes to the buffer.

§Arguments
  • bytes - The bytes to append.
Source

pub fn write_u8(&mut self, val: u8)

Append a single byte to the buffer.

§Arguments
  • val - The byte value.
Source

pub fn write_u16_le(&mut self, val: u16)

Append a little-endian u16 (2 bytes) to the buffer.

§Arguments
  • val - The u16 value.
Source

pub fn write_u32_le(&mut self, val: u32)

Append a little-endian u32 (4 bytes) to the buffer.

§Arguments
  • val - The u32 value.
Source

pub fn write_u64_le(&mut self, val: u64)

Append a little-endian u64 (8 bytes) to the buffer.

§Arguments
  • val - The u64 value.
Source

pub fn write_varint(&mut self, varint: VarInt)

Append a VarInt to the buffer.

§Arguments
  • varint - The VarInt value to encode and append.
Source

pub fn into_bytes(self) -> Vec<u8>

Consume the writer and return the accumulated bytes.

§Returns

The internal byte buffer.

Source

pub fn as_bytes(&self) -> &[u8]

Return a reference to the current buffer contents.

§Returns

A byte slice of the written data.

Source

pub fn len(&self) -> usize

Return the current length of the buffer.

§Returns

The number of bytes written so far.

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty.

§Returns

true if no bytes have been written.

Trait Implementations§

Source§

impl Default for BsvWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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