pub struct BufferedZigZagWriter<W>where
W: ByteOutput,{ /* private fields */ }Expand description
Buffered writer for canonical ZigZag + unsigned LEB128 integers.
Values are encoded directly into the internal output buffer and flushed to the wrapped writer in larger chunks.
§Flush contract
Dropping this writer delegates to qubit_io::BufferedOutput, which makes a
best-effort attempt to drain pending bytes, ignores drop-time errors, and
does not guarantee that the wrapped writer itself is flushed. Call
Output::flush to guarantee that all bytes reach the wrapped output.
Self::inner can observe the wrapped writer before pending bytes have
been flushed.
§Target-width integers
isize methods use the current Rust target’s pointer width. Prefer
fixed-width integer methods such as write_i64 for persistent files and
cross-platform protocols.
§Type Parameters
W: Underlying byte output.
§Examples
use qubit_io::ByteOutput;
use qubit_io_binary::BufferedZigZagWriter;
let mut writer = BufferedZigZagWriter::new(Vec::new());
writer.write_i32(-123)?;
writer.flush()?;
assert_eq!(writer.inner(), &[0xF5, 0x01]);Implementations§
Source§impl<W> BufferedZigZagWriter<W>where
W: ByteOutput,
impl<W> BufferedZigZagWriter<W>where
W: ByteOutput,
Sourcepub fn is_buffered(&self) -> bool
pub fn is_buffered(&self) -> bool
Returns whether this writer buffers output.
§Returns
Returns true when writes may be retained in an internal buffer.
Sourcepub unsafe fn write_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<usize>
pub unsafe fn write_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> Result<usize>
Writes up to count bytes from an indexed input range.
§Parameters
input: Source byte buffer.index: Start of the readable range.count: Maximum number of bytes to write.
§Returns
Returns the number of bytes written.
§Errors
Returns the underlying output error.
§Safety
index..index + count must be a valid range within input.
Sourcepub unsafe fn write_fully_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<()>
pub unsafe fn write_fully_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> Result<()>
Writes all bytes from an indexed input range.
§Parameters
input: Source byte buffer.index: Start of the readable range.count: Number of bytes to write.
§Errors
Returns the underlying output error if the complete range cannot be written.
§Safety
index..index + count must be a valid range within input.
Sourcepub fn write_fully(&mut self, input: &[u8]) -> Result<()>
pub fn write_fully(&mut self, input: &[u8]) -> Result<()>
Source§impl<W> BufferedZigZagWriter<W>where
W: SeekableByteOutput,
impl<W> BufferedZigZagWriter<W>where
W: SeekableByteOutput,
Sourcepub fn seek_to(&mut self, position: SeekFrom) -> Result<u64>
pub fn seek_to(&mut self, position: SeekFrom) -> Result<u64>
Seeks the wrapped byte stream; see Seekable::seek_to for
the seek contract. Buffered wrappers interpret relative offsets
and report positions relative to their logical stream position.
A position query does not flush buffered output.
§Parameters
position: Relative or absolute target position.
§Returns
Returns the resulting stream position in bytes. For buffered wrappers this is the logical position, including buffered data.
§Errors
Returns the underlying seek error.
Source§impl<W> BufferedZigZagWriter<W>where
W: ByteOutput,
impl<W> BufferedZigZagWriter<W>where
W: ByteOutput,
Sourcepub fn with_capacity(inner: W, capacity: usize) -> Self
pub fn with_capacity(inner: W, capacity: usize) -> Self
Creates a buffered ZigZag writer with at least capacity bytes.
§Parameters
inner: Underlying byte output.capacity: Requested internal buffer capacity in bytes.
§Returns
Returns a buffered writer whose capacity also satisfies the largest supported codec payload.
§Panics
Panics if capacity exceeds the maximum capacity supported by Vec.
Sourcepub fn try_with_capacity(
inner: W,
capacity: usize,
) -> Result<Self, TryReserveError>
pub fn try_with_capacity( inner: W, capacity: usize, ) -> Result<Self, TryReserveError>
Tries to create a buffered ZigZag writer with at least capacity bytes.
§Parameters
inner: Underlying byte output to wrap.capacity: Requested internal buffer capacity in bytes. The request is raised when necessary to fit the largest supported codec payload.
§Returns
Returns a buffered writer on successful allocation. Its capacity satisfies both the request and the minimum required by the supported codecs.
§Errors
Returns a TryReserveError if the buffer capacity overflows or its
allocation fails.
Sourcepub const fn inner(&self) -> &W
pub const fn inner(&self) -> &W
Returns a shared reference to the underlying writer.
Pending bytes may still be held in this wrapper’s internal buffer.
§Returns
Returns the wrapped writer.
Sourcepub fn into_parts(self) -> (W, BufferedOutputRecovery<u8>)
pub fn into_parts(self) -> (W, BufferedOutputRecovery<u8>)
Recovers the wrapped writer and the status of bytes retained by this writer.
This method performs no I/O and does not call Self::flush. Pending
bytes were not reported as written and may be retried. Indeterminate
means an inner write panicked and may have produced an external prefix;
do not replay it automatically. Flush first for normal completion.
§Returns
Returns the wrapped writer and pending or indeterminate bytes in logical write order.
Source§impl<W> BufferedZigZagWriter<W>where
W: ByteOutput,
impl<W> BufferedZigZagWriter<W>where
W: ByteOutput,
Trait Implementations§
Source§impl<W> Output for BufferedZigZagWriter<W>where
W: ByteOutput,
impl<W> Output for BufferedZigZagWriter<W>where
W: ByteOutput,
Source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Source§unsafe fn write_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<usize>
unsafe fn write_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> Result<usize>
Writes up to count bytes from an indexed input range.
§Parameters
input: Source slice.index: First source index.count: Maximum number of bytes to write.
§Returns
Returns the number of bytes accepted.
§Errors
Returns an output error encountered while draining pending bytes.
§Safety
index..index + count must be a valid range within input.
Source§fn into_std_write(self) -> StdWrite<Self> ⓘwhere
Self: Sized + ByteOutput,
fn into_std_write(self) -> StdWrite<Self> ⓘwhere
Self: Sized + ByteOutput,
Source§fn write(&mut self, input: &[Self::Item]) -> Result<usize, Error>
fn write(&mut self, input: &[Self::Item]) -> Result<usize, Error>
Source§unsafe fn write_fully_unchecked(
&mut self,
input: &[Self::Item],
index: usize,
count: usize,
) -> Result<(), Error>
unsafe fn write_fully_unchecked( &mut self, input: &[Self::Item], index: usize, count: usize, ) -> Result<(), Error>
Source§impl<W> Seekable for BufferedZigZagWriter<W>where
W: SeekableByteOutput,
impl<W> Seekable for BufferedZigZagWriter<W>where
W: SeekableByteOutput,
Source§fn seek_to(&mut self, position: SeekFrom) -> Result<u64>
fn seek_to(&mut self, position: SeekFrom) -> Result<u64>
Seeks relative to this writer’s logical position.
For SeekFrom::Current(0), returns the logical position including
pending bytes without draining them. Other requests drain pending bytes
before repositioning the wrapped output, but do not flush that output.
Call Self::flush explicitly when buffered data and the wrapped
output must be flushed.
§Parameters
position: Target seek position.
§Returns
Returns the new logical stream position in bytes.
§Errors
Returns an error encountered while draining pending bytes or seeking.
Auto Trait Implementations§
impl<W> Forget for BufferedZigZagWriter<W>
impl<W> Freeze for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: Freeze,
impl<W> Move for BufferedZigZagWriter<W>
impl<W> RefUnwindSafe for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: RefUnwindSafe,
impl<W> Send for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: Send,
impl<W> Sync for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: Sync,
impl<W> Unpin for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: Unpin,
impl<W> UnsafeUnpin for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: UnsafeUnpin,
impl<W> UnwindSafe for BufferedZigZagWriter<W>where
TranscodeEncodeOutput<W>: UnwindSafe,
Blanket Implementations§
Source§impl<W> BinaryWriteExt for Wwhere
W: ByteOutput + ?Sized,
impl<W> BinaryWriteExt for Wwhere
W: ByteOutput + ?Sized,
Source§fn write_u16(&mut self, value: u16, byte_order: ByteOrder) -> Result<()>
fn write_u16(&mut self, value: u16, byte_order: ByteOrder) -> Result<()>
Source§fn write_u16_be(&mut self, value: u16) -> Result<()>
fn write_u16_be(&mut self, value: u16) -> Result<()>
Source§fn write_u16_le(&mut self, value: u16) -> Result<()>
fn write_u16_le(&mut self, value: u16) -> Result<()>
Source§fn write_u32(&mut self, value: u32, byte_order: ByteOrder) -> Result<()>
fn write_u32(&mut self, value: u32, byte_order: ByteOrder) -> Result<()>
Source§fn write_u32_be(&mut self, value: u32) -> Result<()>
fn write_u32_be(&mut self, value: u32) -> Result<()>
Source§fn write_u32_le(&mut self, value: u32) -> Result<()>
fn write_u32_le(&mut self, value: u32) -> Result<()>
Source§fn write_u64(&mut self, value: u64, byte_order: ByteOrder) -> Result<()>
fn write_u64(&mut self, value: u64, byte_order: ByteOrder) -> Result<()>
Source§fn write_u64_be(&mut self, value: u64) -> Result<()>
fn write_u64_be(&mut self, value: u64) -> Result<()>
Source§fn write_u64_le(&mut self, value: u64) -> Result<()>
fn write_u64_le(&mut self, value: u64) -> Result<()>
Source§fn write_u128(&mut self, value: u128, byte_order: ByteOrder) -> Result<()>
fn write_u128(&mut self, value: u128, byte_order: ByteOrder) -> Result<()>
Source§fn write_u128_be(&mut self, value: u128) -> Result<()>
fn write_u128_be(&mut self, value: u128) -> Result<()>
Source§fn write_u128_le(&mut self, value: u128) -> Result<()>
fn write_u128_le(&mut self, value: u128) -> Result<()>
Source§fn write_i16(&mut self, value: i16, byte_order: ByteOrder) -> Result<()>
fn write_i16(&mut self, value: i16, byte_order: ByteOrder) -> Result<()>
Source§fn write_i16_be(&mut self, value: i16) -> Result<()>
fn write_i16_be(&mut self, value: i16) -> Result<()>
Source§fn write_i16_le(&mut self, value: i16) -> Result<()>
fn write_i16_le(&mut self, value: i16) -> Result<()>
Source§fn write_i32(&mut self, value: i32, byte_order: ByteOrder) -> Result<()>
fn write_i32(&mut self, value: i32, byte_order: ByteOrder) -> Result<()>
Source§fn write_i32_be(&mut self, value: i32) -> Result<()>
fn write_i32_be(&mut self, value: i32) -> Result<()>
Source§fn write_i32_le(&mut self, value: i32) -> Result<()>
fn write_i32_le(&mut self, value: i32) -> Result<()>
Source§fn write_i64(&mut self, value: i64, byte_order: ByteOrder) -> Result<()>
fn write_i64(&mut self, value: i64, byte_order: ByteOrder) -> Result<()>
Source§fn write_i64_be(&mut self, value: i64) -> Result<()>
fn write_i64_be(&mut self, value: i64) -> Result<()>
Source§fn write_i64_le(&mut self, value: i64) -> Result<()>
fn write_i64_le(&mut self, value: i64) -> Result<()>
Source§fn write_i128(&mut self, value: i128, byte_order: ByteOrder) -> Result<()>
fn write_i128(&mut self, value: i128, byte_order: ByteOrder) -> Result<()>
Source§fn write_i128_be(&mut self, value: i128) -> Result<()>
fn write_i128_be(&mut self, value: i128) -> Result<()>
Source§fn write_i128_le(&mut self, value: i128) -> Result<()>
fn write_i128_le(&mut self, value: i128) -> Result<()>
Source§fn write_f32(&mut self, value: f32, byte_order: ByteOrder) -> Result<()>
fn write_f32(&mut self, value: f32, byte_order: ByteOrder) -> Result<()>
Source§fn write_f32_be(&mut self, value: f32) -> Result<()>
fn write_f32_be(&mut self, value: f32) -> Result<()>
Source§fn write_f32_le(&mut self, value: f32) -> Result<()>
fn write_f32_le(&mut self, value: f32) -> Result<()>
Source§fn write_f64(&mut self, value: f64, byte_order: ByteOrder) -> Result<()>
fn write_f64(&mut self, value: f64, byte_order: ByteOrder) -> Result<()>
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
impl<T> ByteOutput for T
Source§impl<W> Leb128WriteExt for Wwhere
W: ByteOutput + ?Sized,
impl<W> Leb128WriteExt for Wwhere
W: ByteOutput + ?Sized,
Source§fn write_uleb_u16(&mut self, value: u16) -> Result<()>
fn write_uleb_u16(&mut self, value: u16) -> Result<()>
u16. Read moreSource§fn write_uleb_u32(&mut self, value: u32) -> Result<()>
fn write_uleb_u32(&mut self, value: u32) -> Result<()>
u32. Read moreSource§fn write_uleb_u64(&mut self, value: u64) -> Result<()>
fn write_uleb_u64(&mut self, value: u64) -> Result<()>
u64. Read moreSource§fn write_uleb_u128(&mut self, value: u128) -> Result<()>
fn write_uleb_u128(&mut self, value: u128) -> Result<()>
u128. Read moreSource§fn write_uleb_usize(&mut self, value: usize) -> Result<()>
fn write_uleb_usize(&mut self, value: usize) -> Result<()>
usize. Read moreimpl<T> SeekableByteOutput for T
impl<T> SeekableOutput for T
Source§impl<T> StringWriteExt for Twhere
T: ByteOutput + ?Sized,
impl<T> StringWriteExt for Twhere
T: ByteOutput + ?Sized,
Source§fn write_utf8_payload(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_payload(&mut self, value: &str) -> Result<(), Error>
Writes the string’s UTF-8 bytes without adding a length prefix.
A write failure may occur after some payload bytes have reached the underlying output.
§Parameters
value: UTF-8 string whose bytes are written to the output.
§Returns
Returns after all UTF-8 payload bytes have been written.
§Errors
Returns an I/O error from the underlying output.
Source§fn write_utf8_string_uleb_usize(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_uleb_usize(&mut self, value: &str) -> Result<(), Error>
Writes the UTF-8 byte length as target-width-dependent unsigned LEB128, followed by the string bytes.
A failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after its target-width-dependent byte length.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns an I/O error from writing the prefix or payload.
Source§fn write_utf8_string_uleb_u64(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_uleb_u64(&mut self, value: &str) -> Result<(), Error>
Writes the UTF-8 byte length as unsigned LEB128 u64, then the string
bytes.
Returns InvalidInput if the byte length does not fit in u64; a
write failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after itsu64byte length.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length does not fit in u64, or an
I/O error while writing.
Source§fn write_string_with_u16_len(
&mut self,
value: &str,
byte_order: ByteOrder,
) -> Result<(), Error>
fn write_string_with_u16_len( &mut self, value: &str, byte_order: ByteOrder, ) -> Result<(), Error>
Writes a u16 UTF-8 byte-length prefix in the requested byte order,
followed by the string bytes.
Returns InvalidInput if the byte length exceeds u16::MAX; a write
failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after itsu16byte length.byte_order: Byte order used to encode the length prefix.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length exceeds u16::MAX, or an
I/O error while writing.
Source§fn write_string_with_u16_len_be(&mut self, value: &str) -> Result<(), Error>
fn write_string_with_u16_len_be(&mut self, value: &str) -> Result<(), Error>
Writes a big-endian u16 UTF-8 byte-length prefix, then the string
bytes.
Returns InvalidInput if the byte length exceeds u16::MAX; a write
failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after its big-endianu16byte length.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length exceeds u16::MAX, or an
I/O error while writing.
Source§fn write_string_with_u16_len_le(&mut self, value: &str) -> Result<(), Error>
fn write_string_with_u16_len_le(&mut self, value: &str) -> Result<(), Error>
Writes a little-endian u16 UTF-8 byte-length prefix, then the string
bytes.
Returns InvalidInput if the byte length exceeds u16::MAX; a write
failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after its little-endianu16byte length.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length exceeds u16::MAX, or an
I/O error while writing.
Source§fn write_string_with_u32_len(
&mut self,
value: &str,
byte_order: ByteOrder,
) -> Result<(), Error>
fn write_string_with_u32_len( &mut self, value: &str, byte_order: ByteOrder, ) -> Result<(), Error>
Writes a u32 UTF-8 byte-length prefix in the requested byte order,
followed by the string bytes.
Returns InvalidInput if the byte length exceeds u32::MAX; a write
failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after itsu32byte length.byte_order: Byte order used to encode the length prefix.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length exceeds u32::MAX, or an
I/O error while writing.
Source§fn write_string_with_u32_len_be(&mut self, value: &str) -> Result<(), Error>
fn write_string_with_u32_len_be(&mut self, value: &str) -> Result<(), Error>
Writes a big-endian u32 UTF-8 byte-length prefix, then the string
bytes.
Returns InvalidInput if the byte length exceeds u32::MAX; a write
failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after its big-endianu32byte length.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length exceeds u32::MAX, or an
I/O error while writing.
Source§fn write_string_with_u32_len_le(&mut self, value: &str) -> Result<(), Error>
fn write_string_with_u32_len_le(&mut self, value: &str) -> Result<(), Error>
Writes a little-endian u32 UTF-8 byte-length prefix, then the string
bytes.
Returns InvalidInput if the byte length exceeds u32::MAX; a write
failure can leave a partial prefix or payload in the output.
§Parameters
value: UTF-8 string to write after its little-endianu32byte length.
§Returns
Returns after the length prefix and payload have been written.
§Errors
Returns InvalidInput if the byte length exceeds u32::MAX, or an
I/O error while writing.