Skip to main content

BinaryWriter

Struct BinaryWriter 

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

Binary writer that matches TypeScript SDK encoding exactly

Implementations§

Source§

impl BinaryWriter

Source

pub fn new() -> Self

Create a new binary writer

Source

pub fn with_capacity(capacity: usize) -> Self

Create a binary writer with pre-allocated capacity

Source

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

Get the accumulated bytes

Source

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

Get a reference to the accumulated bytes

Source

pub fn clear(&mut self)

Clear the buffer

Source

pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), EncodingError>

Write raw bytes to the buffer

Source

pub fn write_field( &mut self, field: u32, value: &[u8], ) -> Result<(), EncodingError>

Encode a field with its number and value Matches TS: fieldMarshalBinary(field: number, val: Uint8Array)

Source

pub fn write_uvarint(&mut self, value: u64) -> Result<(), EncodingError>

Encode an unsigned varint using Go’s canonical encoding/binary algorithm Matches Go: binary.PutUvarint(buf, x)

Source

pub fn write_uvarint_field( &mut self, value: u64, field: u32, ) -> Result<(), EncodingError>

Encode an unsigned varint with field number

Source

pub fn write_varint(&mut self, value: i64) -> Result<(), EncodingError>

Encode a signed varint using Go’s canonical zigzag encoding Matches Go: binary.PutVarint(buf, x)

Source

pub fn write_varint_field( &mut self, value: i64, field: u32, ) -> Result<(), EncodingError>

Encode a signed varint with field number

Source

pub fn write_big_number(&mut self, value: &BigUint) -> Result<(), EncodingError>

Encode a big number (unsigned big integer) Matches TS: bigNumberMarshalBinary(bn: bigint, field?: number)

Source

pub fn write_big_number_field( &mut self, value: &BigUint, field: u32, ) -> Result<(), EncodingError>

Encode a big number with field number

Source

pub fn write_bool(&mut self, value: bool) -> Result<(), EncodingError>

Encode a boolean value Matches TS: booleanMarshalBinary(b: boolean, field?: number)

Source

pub fn write_bool_field( &mut self, value: bool, field: u32, ) -> Result<(), EncodingError>

Encode a boolean with field number

Source

pub fn write_string(&mut self, value: &str) -> Result<(), EncodingError>

Encode a string as UTF-8 bytes with length prefix Matches TS: stringMarshalBinary(val: string, field?: number)

Source

pub fn write_string_field( &mut self, value: &str, field: u32, ) -> Result<(), EncodingError>

Encode a string with field number

Source

pub fn write_bytes_with_length( &mut self, bytes: &[u8], ) -> Result<(), EncodingError>

Encode bytes with length prefix Matches TS: bytesMarshalBinary(val: Uint8Array, field?: number)

Source

pub fn write_bytes_field( &mut self, bytes: &[u8], field: u32, ) -> Result<(), EncodingError>

Encode bytes with length prefix and field number

Source

pub fn write_hash(&mut self, hash: &[u8; 32]) -> Result<(), EncodingError>

Encode a 32-byte hash without length prefix Matches TS: hashMarshalBinary(val: Uint8Array, field?: number)

Source

pub fn write_hash_field( &mut self, hash: &[u8; 32], field: u32, ) -> Result<(), EncodingError>

Encode a hash with field number

Source

pub fn write_hash_bytes(&mut self, hash: &[u8]) -> Result<(), EncodingError>

Encode a variable-length hash with validation

Source

pub fn write_hash_bytes_field( &mut self, hash: &[u8], field: u32, ) -> Result<(), EncodingError>

Encode a variable-length hash with field number

Source

pub fn write_optional<T, F>( &mut self, value: Option<&T>, _field: u32, writer_fn: F, ) -> Result<(), EncodingError>
where T: Clone, F: FnOnce(&mut Self, &T) -> Result<(), EncodingError>,

Write an optional value (None = skip, Some = encode)

Source

pub fn write_array<T, F>( &mut self, items: &[T], _field: u32, writer_fn: F, ) -> Result<(), EncodingError>
where F: Fn(&mut Self, &T) -> Result<(), EncodingError>,

Write an array/slice with element encoding

Source§

impl BinaryWriter

Helper functions that match TypeScript SDK exactly

Source

pub fn with_field_number( data: &[u8], field: Option<u32>, ) -> Result<Vec<u8>, EncodingError>

Create field-encoded data (helper matching TS withFieldNumber)

Source

pub fn encode_uvarint(value: u64) -> Vec<u8>

Encode uvarint as standalone function

Source

pub fn encode_varint(value: i64) -> Vec<u8>

Encode varint as standalone function

Source

pub fn encode_string(value: &str) -> Vec<u8>

Encode string as standalone function

Source

pub fn encode_bytes(bytes: &[u8]) -> Vec<u8>

Encode bytes with length as standalone function

Source

pub fn encode_bool(value: bool) -> Vec<u8>

Encode boolean as standalone function

Source

pub fn encode_hash(hash: &[u8; 32]) -> Vec<u8>

Encode hash as standalone function

Trait Implementations§

Source§

impl Clone for BinaryWriter

Source§

fn clone(&self) -> BinaryWriter

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 Debug for BinaryWriter

Source§

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

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

impl Default for BinaryWriter

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