BinaryDecoder

Struct BinaryDecoder 

Source
pub struct BinaryDecoder<R: Read> { /* private fields */ }
Expand description

Binary decoder with versioning support

Implementations§

Source§

impl<R: Read> BinaryDecoder<R>

Source

pub fn new(reader: R) -> Self

Create a new decoder

Source

pub fn read_header(&mut self) -> ChieResult<u8>

Read and verify the message header (magic bytes + version)

§Errors

Returns error if header is invalid or unsupported

Source

pub fn read_u8(&mut self) -> ChieResult<u8>

Read a u8 value

§Errors

Returns error if reading fails

Source

pub fn read_u32(&mut self) -> ChieResult<u32>

Read a u32 value (little-endian)

§Errors

Returns error if reading fails

Source

pub fn read_u64(&mut self) -> ChieResult<u64>

Read a u64 value (little-endian)

§Errors

Returns error if reading fails

Source

pub fn read_bytes(&mut self) -> ChieResult<Vec<u8>>

Read a variable-length byte array (length prefix + data)

§Errors

Returns error if reading fails or length is invalid

Source

pub fn read_string(&mut self) -> ChieResult<String>

Read a string (UTF-8 encoded with length prefix)

§Errors

Returns error if reading fails or string is invalid UTF-8

Source

pub fn read_bool(&mut self) -> ChieResult<bool>

Read a boolean from a single byte

§Errors

Returns error if reading fails

Source

pub fn verify_checksum(&mut self, data: &[u8]) -> ChieResult<()>

Read and verify CRC32 checksum for the given data

§Errors

Returns error if checksum doesn’t match or reading fails

Source

pub fn version(&self) -> u8

Get the protocol version from the header

Source

pub fn get_mut(&mut self) -> &mut R

Get a mutable reference to the underlying reader

Source

pub fn into_inner(self) -> R

Consume the decoder and return the underlying reader

Source

pub fn read_bytes_chunked<F>( &mut self, chunk_size: usize, callback: F, ) -> ChieResult<u64>
where F: FnMut(&[u8]) -> ChieResult<()>,

Read large byte array in chunks with a callback to process each chunk

§Errors

Returns error if reading fails or callback returns error

Source

pub fn copy_to_writer<W: Write>( &mut self, writer: &mut W, size: u64, ) -> ChieResult<u64>

Stream data directly to a writer without buffering entire payload

§Errors

Returns error if copying fails

Auto Trait Implementations§

§

impl<R> Freeze for BinaryDecoder<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for BinaryDecoder<R>
where R: RefUnwindSafe,

§

impl<R> Send for BinaryDecoder<R>
where R: Send,

§

impl<R> Sync for BinaryDecoder<R>
where R: Sync,

§

impl<R> Unpin for BinaryDecoder<R>
where R: Unpin,

§

impl<R> UnwindSafe for BinaryDecoder<R>
where R: UnwindSafe,

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