pub struct BinaryEncoder<W: Write> { /* private fields */ }Expand description
Binary encoder with versioning support
Implementations§
Source§impl<W: Write> BinaryEncoder<W>
impl<W: Write> BinaryEncoder<W>
Sourcepub fn with_version(writer: W, version: u8) -> Self
pub fn with_version(writer: W, version: u8) -> Self
Create an encoder with a specific protocol version
Sourcepub fn write_header(&mut self) -> ChieResult<()>
pub fn write_header(&mut self) -> ChieResult<()>
Sourcepub fn write_u8(&mut self, value: u8) -> ChieResult<()>
pub fn write_u8(&mut self, value: u8) -> ChieResult<()>
Sourcepub fn write_u32(&mut self, value: u32) -> ChieResult<()>
pub fn write_u32(&mut self, value: u32) -> ChieResult<()>
Sourcepub fn write_u64(&mut self, value: u64) -> ChieResult<()>
pub fn write_u64(&mut self, value: u64) -> ChieResult<()>
Sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> ChieResult<()>
pub fn write_bytes(&mut self, bytes: &[u8]) -> ChieResult<()>
Sourcepub fn write_string(&mut self, s: &str) -> ChieResult<()>
pub fn write_string(&mut self, s: &str) -> ChieResult<()>
Sourcepub fn write_bool(&mut self, value: bool) -> ChieResult<()>
pub fn write_bool(&mut self, value: bool) -> ChieResult<()>
Sourcepub fn write_checksum(&mut self, data: &[u8]) -> ChieResult<()>
pub fn write_checksum(&mut self, data: &[u8]) -> ChieResult<()>
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Consume the encoder and return the underlying writer
Sourcepub fn write_bytes_chunked<R: Read>(
&mut self,
reader: &mut R,
total_size: u64,
chunk_size: usize,
) -> ChieResult<()>
pub fn write_bytes_chunked<R: Read>( &mut self, reader: &mut R, total_size: u64, chunk_size: usize, ) -> ChieResult<()>
Write large byte array in chunks to avoid excessive memory allocation
§Examples
use chie_shared::encoding::BinaryEncoder;
let data = vec![1u8; 10_000]; // 10KB of data
let mut reader = &data[..];
let mut buf = Vec::new();
let mut encoder = BinaryEncoder::new(&mut buf);
// Write in 1KB chunks
encoder.write_bytes_chunked(&mut reader, 10_000, 1024).unwrap();§Errors
Returns error if writing fails
Sourcepub fn copy_from_reader<R: Read>(&mut self, reader: &mut R) -> ChieResult<u64>
pub fn copy_from_reader<R: Read>(&mut self, reader: &mut R) -> ChieResult<u64>
Stream data directly from a reader without buffering entire payload
§Errors
Returns error if copying fails
Auto Trait Implementations§
impl<W> Freeze for BinaryEncoder<W>where
W: Freeze,
impl<W> RefUnwindSafe for BinaryEncoder<W>where
W: RefUnwindSafe,
impl<W> Send for BinaryEncoder<W>where
W: Send,
impl<W> Sync for BinaryEncoder<W>where
W: Sync,
impl<W> Unpin for BinaryEncoder<W>where
W: Unpin,
impl<W> UnwindSafe for BinaryEncoder<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more