pub struct BinaryWriter { /* private fields */ }Expand description
Binary writer that matches TypeScript SDK encoding exactly
Implementations§
Source§impl BinaryWriter
impl BinaryWriter
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a binary writer with pre-allocated capacity
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Get the accumulated bytes
Sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), EncodingError>
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), EncodingError>
Write raw bytes to the buffer
Sourcepub fn write_field(
&mut self,
field: u32,
value: &[u8],
) -> Result<(), EncodingError>
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)
Sourcepub fn write_uvarint(&mut self, value: u64) -> Result<(), EncodingError>
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)
Sourcepub fn write_uvarint_field(
&mut self,
value: u64,
field: u32,
) -> Result<(), EncodingError>
pub fn write_uvarint_field( &mut self, value: u64, field: u32, ) -> Result<(), EncodingError>
Encode an unsigned varint with field number
Sourcepub fn write_varint(&mut self, value: i64) -> Result<(), EncodingError>
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)
Sourcepub fn write_varint_field(
&mut self,
value: i64,
field: u32,
) -> Result<(), EncodingError>
pub fn write_varint_field( &mut self, value: i64, field: u32, ) -> Result<(), EncodingError>
Encode a signed varint with field number
Sourcepub fn write_big_number(&mut self, value: &BigUint) -> Result<(), EncodingError>
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)
Sourcepub fn write_big_number_field(
&mut self,
value: &BigUint,
field: u32,
) -> Result<(), EncodingError>
pub fn write_big_number_field( &mut self, value: &BigUint, field: u32, ) -> Result<(), EncodingError>
Encode a big number with field number
Sourcepub fn write_bool(&mut self, value: bool) -> Result<(), EncodingError>
pub fn write_bool(&mut self, value: bool) -> Result<(), EncodingError>
Encode a boolean value Matches TS: booleanMarshalBinary(b: boolean, field?: number)
Sourcepub fn write_bool_field(
&mut self,
value: bool,
field: u32,
) -> Result<(), EncodingError>
pub fn write_bool_field( &mut self, value: bool, field: u32, ) -> Result<(), EncodingError>
Encode a boolean with field number
Sourcepub fn write_string(&mut self, value: &str) -> Result<(), EncodingError>
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)
Sourcepub fn write_string_field(
&mut self,
value: &str,
field: u32,
) -> Result<(), EncodingError>
pub fn write_string_field( &mut self, value: &str, field: u32, ) -> Result<(), EncodingError>
Encode a string with field number
Sourcepub fn write_bytes_with_length(
&mut self,
bytes: &[u8],
) -> Result<(), EncodingError>
pub fn write_bytes_with_length( &mut self, bytes: &[u8], ) -> Result<(), EncodingError>
Encode bytes with length prefix Matches TS: bytesMarshalBinary(val: Uint8Array, field?: number)
Sourcepub fn write_bytes_field(
&mut self,
bytes: &[u8],
field: u32,
) -> Result<(), EncodingError>
pub fn write_bytes_field( &mut self, bytes: &[u8], field: u32, ) -> Result<(), EncodingError>
Encode bytes with length prefix and field number
Sourcepub fn write_hash(&mut self, hash: &[u8; 32]) -> Result<(), EncodingError>
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)
Sourcepub fn write_hash_field(
&mut self,
hash: &[u8; 32],
field: u32,
) -> Result<(), EncodingError>
pub fn write_hash_field( &mut self, hash: &[u8; 32], field: u32, ) -> Result<(), EncodingError>
Encode a hash with field number
Sourcepub fn write_hash_bytes(&mut self, hash: &[u8]) -> Result<(), EncodingError>
pub fn write_hash_bytes(&mut self, hash: &[u8]) -> Result<(), EncodingError>
Encode a variable-length hash with validation
Sourcepub fn write_hash_bytes_field(
&mut self,
hash: &[u8],
field: u32,
) -> Result<(), EncodingError>
pub fn write_hash_bytes_field( &mut self, hash: &[u8], field: u32, ) -> Result<(), EncodingError>
Encode a variable-length hash with field number
Sourcepub fn write_optional<T, F>(
&mut self,
value: Option<&T>,
_field: u32,
writer_fn: F,
) -> Result<(), EncodingError>
pub fn write_optional<T, F>( &mut self, value: Option<&T>, _field: u32, writer_fn: F, ) -> Result<(), EncodingError>
Write an optional value (None = skip, Some = encode)
Sourcepub fn write_array<T, F>(
&mut self,
items: &[T],
_field: u32,
writer_fn: F,
) -> Result<(), EncodingError>
pub fn write_array<T, F>( &mut self, items: &[T], _field: u32, writer_fn: F, ) -> Result<(), EncodingError>
Write an array/slice with element encoding
Source§impl BinaryWriter
Helper functions that match TypeScript SDK exactly
impl BinaryWriter
Helper functions that match TypeScript SDK exactly
Sourcepub fn with_field_number(
data: &[u8],
field: Option<u32>,
) -> Result<Vec<u8>, EncodingError>
pub fn with_field_number( data: &[u8], field: Option<u32>, ) -> Result<Vec<u8>, EncodingError>
Create field-encoded data (helper matching TS withFieldNumber)
Trait Implementations§
Source§impl Clone for BinaryWriter
impl Clone for BinaryWriter
Source§fn clone(&self) -> BinaryWriter
fn clone(&self) -> BinaryWriter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more