Skip to main content

BufferedLeb128Writer

Struct BufferedLeb128Writer 

Source
pub struct BufferedLeb128Writer<W> { /* private fields */ }
Expand description

Buffered writer for canonical LEB128 integers.

Values are encoded directly into the internal output buffer and flushed to the wrapped writer in larger chunks.

§Flush contract

Pending buffered bytes are not flushed from Drop. Call Write::flush or Self::into_inner to guarantee that all bytes reach the wrapped writer. Self::get_ref and Self::get_mut can observe the wrapped writer before pending bytes have been flushed.

§Target-width integers

usize and isize methods use the current Rust target’s pointer width. Prefer fixed-width integer methods such as write_u64 or write_i64 for persistent files and cross-platform protocols.

Implementations§

Source§

impl<W> BufferedLeb128Writer<W>

Source

pub fn new(inner: W) -> Self

Creates a buffered LEB128 writer with the default buffer capacity.

Source

pub fn with_capacity(inner: W, capacity: usize) -> Self

Creates a buffered LEB128 writer with at least capacity bytes.

Source

pub const fn get_ref(&self) -> &W

Returns a shared reference to the underlying writer.

Pending bytes may still be held in this wrapper’s internal buffer.

Source

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

Returns an exclusive reference to the underlying writer.

Pending bytes may still be held in this wrapper’s internal buffer. Flush first if the underlying writer must observe all previous writes.

Source§

impl<W> BufferedLeb128Writer<W>
where W: Write,

Source

pub fn into_inner(self) -> Result<W>

Flushes pending bytes and returns the underlying writer.

Source

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

Writes a UTF-8 string prefixed by an unsigned LEB128 byte length.

The length prefix is encoded as usize, so this format is target-width dependent. Prefer a fixed-width length prefix for persistent files and cross-platform protocols.

Source§

impl<W> BufferedLeb128Writer<W>
where W: Write,

Source

pub fn write_u8(&mut self, value: u8) -> Result<()>

Writes an unsigned LEB128 u8.

Source

pub fn write_u16(&mut self, value: u16) -> Result<()>

Writes an unsigned LEB128 u16.

Source

pub fn write_u32(&mut self, value: u32) -> Result<()>

Writes an unsigned LEB128 u32.

Source

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

Writes an unsigned LEB128 u64.

Source

pub fn write_u128(&mut self, value: u128) -> Result<()>

Writes an unsigned LEB128 u128.

Source

pub fn write_usize(&mut self, value: usize) -> Result<()>

Writes an unsigned LEB128 usize.

Source

pub fn write_i8(&mut self, value: i8) -> Result<()>

Writes a signed LEB128 i8.

Source

pub fn write_i16(&mut self, value: i16) -> Result<()>

Writes a signed LEB128 i16.

Source

pub fn write_i32(&mut self, value: i32) -> Result<()>

Writes a signed LEB128 i32.

Source

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

Writes a signed LEB128 i64.

Source

pub fn write_i128(&mut self, value: i128) -> Result<()>

Writes a signed LEB128 i128.

Source

pub fn write_isize(&mut self, value: isize) -> Result<()>

Writes a signed LEB128 isize.

Trait Implementations§

Source§

impl<W> Seek for BufferedLeb128Writer<W>
where W: Write + Seek,

Source§

fn seek(&mut self, position: SeekFrom) -> Result<u64>

Flushes pending bytes before seeking the wrapped writer.

1.55.0 · Source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
Source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · Source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · Source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more
Source§

impl<W> Write for BufferedLeb128Writer<W>
where W: Write,

Source§

fn write(&mut self, buffer: &[u8]) -> Result<usize>

Writes bytes through the internal buffer.

Source§

fn write_all(&mut self, buffer: &[u8]) -> Result<()>

Writes all bytes through the internal buffer.

Source§

fn flush(&mut self) -> Result<()>

Flushes the internal buffer and then the wrapped writer.

1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<W> Freeze for BufferedLeb128Writer<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for BufferedLeb128Writer<W>
where W: RefUnwindSafe,

§

impl<W> Send for BufferedLeb128Writer<W>
where W: Send,

§

impl<W> Sync for BufferedLeb128Writer<W>
where W: Sync,

§

impl<W> Unpin for BufferedLeb128Writer<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for BufferedLeb128Writer<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for BufferedLeb128Writer<W>
where W: 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<W> BinaryWriteExt for W
where W: Write + ?Sized,

Source§

fn write_u8(&mut self, value: u8) -> Result<()>

Writes an unsigned 8-bit integer.
Source§

fn write_i8(&mut self, value: i8) -> Result<()>

Writes a signed 8-bit integer.
Source§

fn write_u16(&mut self, value: u16, byte_order: ByteOrder) -> Result<()>

Writes an unsigned 16-bit integer using a runtime byte order.
Source§

fn write_u16_be(&mut self, value: u16) -> Result<()>

Writes a big-endian unsigned 16-bit integer.
Source§

fn write_u16_le(&mut self, value: u16) -> Result<()>

Writes a little-endian unsigned 16-bit integer.
Source§

fn write_u32(&mut self, value: u32, byte_order: ByteOrder) -> Result<()>

Writes an unsigned 32-bit integer using a runtime byte order.
Source§

fn write_u32_be(&mut self, value: u32) -> Result<()>

Writes a big-endian unsigned 32-bit integer.
Source§

fn write_u32_le(&mut self, value: u32) -> Result<()>

Writes a little-endian unsigned 32-bit integer.
Source§

fn write_u64(&mut self, value: u64, byte_order: ByteOrder) -> Result<()>

Writes an unsigned 64-bit integer using a runtime byte order.
Source§

fn write_u64_be(&mut self, value: u64) -> Result<()>

Writes a big-endian unsigned 64-bit integer.
Source§

fn write_u64_le(&mut self, value: u64) -> Result<()>

Writes a little-endian unsigned 64-bit integer.
Source§

fn write_u128(&mut self, value: u128, byte_order: ByteOrder) -> Result<()>

Writes an unsigned 128-bit integer using a runtime byte order.
Source§

fn write_u128_be(&mut self, value: u128) -> Result<()>

Writes a big-endian unsigned 128-bit integer.
Source§

fn write_u128_le(&mut self, value: u128) -> Result<()>

Writes a little-endian unsigned 128-bit integer.
Source§

fn write_i16(&mut self, value: i16, byte_order: ByteOrder) -> Result<()>

Writes a signed 16-bit integer using a runtime byte order.
Source§

fn write_i16_be(&mut self, value: i16) -> Result<()>

Writes a big-endian signed 16-bit integer.
Source§

fn write_i16_le(&mut self, value: i16) -> Result<()>

Writes a little-endian signed 16-bit integer.
Source§

fn write_i32(&mut self, value: i32, byte_order: ByteOrder) -> Result<()>

Writes a signed 32-bit integer using a runtime byte order.
Source§

fn write_i32_be(&mut self, value: i32) -> Result<()>

Writes a big-endian signed 32-bit integer.
Source§

fn write_i32_le(&mut self, value: i32) -> Result<()>

Writes a little-endian signed 32-bit integer.
Source§

fn write_i64(&mut self, value: i64, byte_order: ByteOrder) -> Result<()>

Writes a signed 64-bit integer using a runtime byte order.
Source§

fn write_i64_be(&mut self, value: i64) -> Result<()>

Writes a big-endian signed 64-bit integer.
Source§

fn write_i64_le(&mut self, value: i64) -> Result<()>

Writes a little-endian signed 64-bit integer.
Source§

fn write_i128(&mut self, value: i128, byte_order: ByteOrder) -> Result<()>

Writes a signed 128-bit integer using a runtime byte order.
Source§

fn write_i128_be(&mut self, value: i128) -> Result<()>

Writes a big-endian signed 128-bit integer.
Source§

fn write_i128_le(&mut self, value: i128) -> Result<()>

Writes a little-endian signed 128-bit integer.
Source§

fn write_f32(&mut self, value: f32, byte_order: ByteOrder) -> Result<()>

Writes a 32-bit float using a runtime byte order.
Source§

fn write_f32_be(&mut self, value: f32) -> Result<()>

Writes a big-endian 32-bit float.
Source§

fn write_f32_le(&mut self, value: f32) -> Result<()>

Writes a little-endian 32-bit float.
Source§

fn write_f64(&mut self, value: f64, byte_order: ByteOrder) -> Result<()>

Writes a 64-bit float using a runtime byte order.
Source§

fn write_f64_be(&mut self, value: f64) -> Result<()>

Writes a big-endian 64-bit float.
Source§

fn write_f64_le(&mut self, value: f64) -> Result<()>

Writes a little-endian 64-bit float.
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<W> Leb128WriteExt for W
where W: Write + ?Sized,

Source§

fn write_uleb_u8(&mut self, value: u8) -> Result<()>

Writes an unsigned LEB128 u8.
Source§

fn write_uleb_u16(&mut self, value: u16) -> Result<()>

Writes an unsigned LEB128 u16.
Source§

fn write_uleb_u32(&mut self, value: u32) -> Result<()>

Writes an unsigned LEB128 u32.
Source§

fn write_uleb_u64(&mut self, value: u64) -> Result<()>

Writes an unsigned LEB128 u64.
Source§

fn write_uleb_u128(&mut self, value: u128) -> Result<()>

Writes an unsigned LEB128 u128.
Source§

fn write_uleb_usize(&mut self, value: usize) -> Result<()>

Writes an unsigned LEB128 usize.
Source§

fn write_sleb_i8(&mut self, value: i8) -> Result<()>

Writes a signed LEB128 i8.
Source§

fn write_sleb_i16(&mut self, value: i16) -> Result<()>

Writes a signed LEB128 i16.
Source§

fn write_sleb_i32(&mut self, value: i32) -> Result<()>

Writes a signed LEB128 i32.
Source§

fn write_sleb_i64(&mut self, value: i64) -> Result<()>

Writes a signed LEB128 i64.
Source§

fn write_sleb_i128(&mut self, value: i128) -> Result<()>

Writes a signed LEB128 i128.
Source§

fn write_sleb_isize(&mut self, value: isize) -> Result<()>

Writes a signed LEB128 isize.
Source§

impl<T> SeekExt for T
where T: Seek + ?Sized,

Source§

fn stream_size(&mut self) -> Result<u64, Error>

Gets the stream size without changing the final stream position. Read more
Source§

impl<T> StringWriteExt for T
where T: Write + ?Sized,

Source§

fn write_utf8_payload(&mut self, value: &str) -> Result<(), Error>

Writes a UTF-8 payload without a length prefix. Read more
Source§

fn write_utf8_string_uleb(&mut self, value: &str) -> Result<(), Error>

Writes a UTF-8 string with an unsigned LEB128 byte-length prefix. Read more
Source§

fn write_utf8_string_u16( &mut self, value: &str, byte_order: ByteOrder, ) -> Result<(), Error>

Writes a UTF-8 string with a runtime-order u16 byte-length prefix. Read more
Source§

fn write_utf8_string_u16_be(&mut self, value: &str) -> Result<(), Error>

Writes a UTF-8 string with a big-endian u16 byte-length prefix. Read more
Source§

fn write_utf8_string_u16_le(&mut self, value: &str) -> Result<(), Error>

Writes a UTF-8 string with a little-endian u16 byte-length prefix. Read more
Source§

fn write_utf8_string_u32( &mut self, value: &str, byte_order: ByteOrder, ) -> Result<(), Error>

Writes a UTF-8 string with a runtime-order u32 byte-length prefix. Read more
Source§

fn write_utf8_string_u32_be(&mut self, value: &str) -> Result<(), Error>

Writes a UTF-8 string with a big-endian u32 byte-length prefix. Read more
Source§

fn write_utf8_string_u32_le(&mut self, value: &str) -> Result<(), Error>

Writes a UTF-8 string with a little-endian u32 byte-length prefix. 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<T> WriteExt for T
where T: Write + ?Sized,

Source§

unsafe fn write_unchecked( &mut self, buffer: &[u8], start_index: usize, count: usize, ) -> Result<usize>

Writes bytes from a range of buffer without checking the range bounds in release builds. Read more
Source§

unsafe fn write_all_unchecked( &mut self, buffer: &[u8], start_index: usize, count: usize, ) -> Result<()>

Writes exactly count bytes from a range of buffer without checking the range bounds in release builds. Read more
Source§

impl<T> WriteSeekExt for T
where T: Write + Seek + ?Sized,

Source§

fn write_all_at_preserving_position( &mut self, offset: u64, buffer: &[u8], ) -> Result<(), Error>

Writes all bytes at offset and restores the original position. Read more
Source§

impl<W> ZigZagWriteExt for W
where W: Write + ?Sized,

Source§

fn write_zig_zag_i8(&mut self, value: i8) -> Result<()>

Writes a ZigZag i8.
Source§

fn write_zig_zag_i16(&mut self, value: i16) -> Result<()>

Writes a ZigZag i16.
Source§

fn write_zig_zag_i32(&mut self, value: i32) -> Result<()>

Writes a ZigZag i32.
Source§

fn write_zig_zag_i64(&mut self, value: i64) -> Result<()>

Writes a ZigZag i64.
Source§

fn write_zig_zag_i128(&mut self, value: i128) -> Result<()>

Writes a ZigZag i128.
Source§

fn write_zig_zag_isize(&mut self, value: isize) -> Result<()>

Writes a ZigZag isize.
Source§

impl<T> WriteSeek for T
where T: Write + Seek + ?Sized,