Skip to main content

BinaryReader

Struct BinaryReader 

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

Binary reader that matches TypeScript SDK decoding exactly

Implementations§

Source§

impl<'a> BinaryReader<'a>

Source

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

Create a new binary reader from byte data

Source

pub fn position(&self) -> usize

Get the current position in the data

Source

pub fn remaining(&self) -> usize

Get the remaining bytes count

Source

pub fn has_remaining(&self) -> bool

Check if there are more bytes to read

Source

pub fn peek_byte(&self) -> Result<u8, DecodingError>

Peek at the next byte without advancing position

Source

pub fn read_byte(&mut self) -> Result<u8, DecodingError>

Read a single byte

Source

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

Read exact number of bytes

Source

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

Read exact number of bytes into a buffer

Source

pub fn read_uvarint(&mut self) -> Result<u64, DecodingError>

Decode an unsigned varint using Go’s canonical encoding/binary algorithm Matches Go: binary.ReadUvarint(r)

Source

pub fn read_varint(&mut self) -> Result<i64, DecodingError>

Decode a signed varint using Go’s canonical zigzag decoding Matches Go: binary.ReadVarint(r)

Source

pub fn read_big_number(&mut self) -> Result<BigUint, DecodingError>

Decode a big number (unsigned big integer) Matches TS: bigNumberUnmarshalBinary(data: Uint8Array, offset?: number)

Source

pub fn read_bool(&mut self) -> Result<bool, DecodingError>

Decode a boolean value Matches TS: booleanUnmarshalBinary(data: Uint8Array, offset?: number)

Source

pub fn read_string(&mut self) -> Result<String, DecodingError>

Decode a string as UTF-8 bytes with length prefix Matches TS: stringUnmarshalBinary(data: Uint8Array, offset?: number)

Source

pub fn read_bytes_with_length(&mut self) -> Result<&'a [u8], DecodingError>

Decode bytes with length prefix Matches TS: bytesUnmarshalBinary(data: Uint8Array, offset?: number)

Source

pub fn read_hash(&mut self) -> Result<[u8; 32], DecodingError>

Decode a 32-byte hash without length prefix Matches TS: hashUnmarshalBinary(data: Uint8Array, offset?: number)

Source

pub fn read_hash_bytes(&mut self) -> Result<Vec<u8>, DecodingError>

Decode a variable-length hash with validation

Source

pub fn read_remaining(&mut self) -> &'a [u8]

Read the remaining bytes

Source

pub fn reset(&mut self)

Reset position to beginning

Source

pub fn seek(&mut self, position: usize) -> Result<(), DecodingError>

Seek to a specific position

Source§

impl<'a> BinaryReader<'a>

Helper functions that match TypeScript SDK exactly

Source

pub fn decode_uvarint(data: &[u8]) -> Result<(u64, usize), DecodingError>

Decode uvarint as standalone function

Source

pub fn decode_varint(data: &[u8]) -> Result<(i64, usize), DecodingError>

Decode varint as standalone function

Source

pub fn decode_string(data: &[u8]) -> Result<(String, usize), DecodingError>

Decode string as standalone function

Source

pub fn decode_bytes(data: &[u8]) -> Result<(Vec<u8>, usize), DecodingError>

Decode bytes as standalone function

Source

pub fn decode_bool(data: &[u8]) -> Result<(bool, usize), DecodingError>

Decode boolean as standalone function

Source

pub fn decode_hash(data: &[u8]) -> Result<([u8; 32], usize), DecodingError>

Decode hash as standalone function

Trait Implementations§

Source§

impl<'a> Clone for BinaryReader<'a>

Source§

fn clone(&self) -> BinaryReader<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for BinaryReader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BinaryReader<'a>

§

impl<'a> RefUnwindSafe for BinaryReader<'a>

§

impl<'a> Send for BinaryReader<'a>

§

impl<'a> Sync for BinaryReader<'a>

§

impl<'a> Unpin for BinaryReader<'a>

§

impl<'a> UnsafeUnpin for BinaryReader<'a>

§

impl<'a> UnwindSafe for BinaryReader<'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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

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

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,