pub struct BufferedLeb128Reader<R, P>{ /* private fields */ }Expand description
Buffered reader for LEB128 integers.
Values are decoded directly from the internal input buffer while the codec scans for the LEB128 terminating byte.
§Buffered state
This reader may prefetch bytes from the wrapped reader. As a result,
Self::inner can observe an underlying stream position ahead of the
logical position exposed by this wrapper.
§Target-width integers
usize and isize methods use the current Rust target’s pointer width.
Prefer fixed-width integer methods such as read_u64 or read_i64 for
persistent files and cross-platform protocols.
§Type Parameters
R: Underlying byte input.P: LEB128 canonicality policy.
Implementations§
Source§impl<R, P> BufferedLeb128Reader<R, P>
impl<R, P> BufferedLeb128Reader<R, P>
Sourcepub fn with_capacity(inner: R, capacity: usize) -> Self
pub fn with_capacity(inner: R, capacity: usize) -> Self
Sourcepub fn try_with_capacity(
inner: R,
capacity: usize,
) -> Result<Self, TryReserveError>
pub fn try_with_capacity( inner: R, capacity: usize, ) -> Result<Self, TryReserveError>
Tries to create a buffered LEB128 reader with at least capacity bytes.
§Errors
Returns an allocation error when the requested buffer cannot be allocated.
Sourcepub const fn is_strict(&self) -> bool
pub const fn is_strict(&self) -> bool
Returns whether this reader rejects non-canonical encodings.
§Returns
Returns true when policy P requires canonical encodings.
Sourcepub const fn inner(&self) -> &R
pub const fn inner(&self) -> &R
Returns a shared reference to the underlying reader.
The underlying reader may already be positioned past unread bytes held in this wrapper’s internal buffer.
§Returns
Returns the wrapped reader.
Sourcepub fn into_parts(self) -> (R, Buffer<u8>)
pub fn into_parts(self) -> (R, Buffer<u8>)
Consumes this wrapper and preserves its unread buffered bytes.
§Returns
Returns the wrapped reader and the buffer whose Buffer::readable
slice contains every prefetched byte not yet consumed logically. To
continue the same logical stream, consume that slice before reading
from the returned reader.
Source§impl<R> BufferedLeb128Reader<R, NonStrict>
impl<R> BufferedLeb128Reader<R, NonStrict>
Sourcepub fn read_u8_non_strict(&mut self) -> Result<u8>
pub fn read_u8_non_strict(&mut self) -> Result<u8>
Sourcepub fn read_u16_non_strict(&mut self) -> Result<u16>
pub fn read_u16_non_strict(&mut self) -> Result<u16>
Sourcepub fn read_u32_non_strict(&mut self) -> Result<u32>
pub fn read_u32_non_strict(&mut self) -> Result<u32>
Sourcepub fn read_u64_non_strict(&mut self) -> Result<u64>
pub fn read_u64_non_strict(&mut self) -> Result<u64>
Sourcepub fn read_u128_non_strict(&mut self) -> Result<u128>
pub fn read_u128_non_strict(&mut self) -> Result<u128>
Sourcepub fn read_usize_non_strict(&mut self) -> Result<usize>
pub fn read_usize_non_strict(&mut self) -> Result<usize>
Sourcepub fn read_i8_non_strict(&mut self) -> Result<i8>
pub fn read_i8_non_strict(&mut self) -> Result<i8>
Sourcepub fn read_i16_non_strict(&mut self) -> Result<i16>
pub fn read_i16_non_strict(&mut self) -> Result<i16>
Sourcepub fn read_i32_non_strict(&mut self) -> Result<i32>
pub fn read_i32_non_strict(&mut self) -> Result<i32>
Sourcepub fn read_i64_non_strict(&mut self) -> Result<i64>
pub fn read_i64_non_strict(&mut self) -> Result<i64>
Sourcepub fn read_i128_non_strict(&mut self) -> Result<i128>
pub fn read_i128_non_strict(&mut self) -> Result<i128>
Sourcepub fn read_isize_non_strict(&mut self) -> Result<isize>
pub fn read_isize_non_strict(&mut self) -> Result<isize>
Sourcepub fn read_utf8_string_usize_non_strict(
&mut self,
max_len: usize,
) -> Result<String>
pub fn read_utf8_string_usize_non_strict( &mut self, max_len: usize, ) -> Result<String>
Reads a UTF-8 string prefixed by an unsigned LEB128 byte length.
The length prefix is decoded as usize, so this format is target-width dependent. Prefer a fixed-width length prefix for persistent files and cross-platform protocols.
§Parameters
- max_len: Maximum accepted UTF-8 payload length in bytes.
§Returns
Returns the decoded UTF-8 string.
§Errors
Returns an input or allocation error, or an invalid-data error for a malformed or excessive length or invalid UTF-8.
Sourcepub fn read_utf8_string_u64_non_strict(
&mut self,
max_len: usize,
) -> Result<String>
pub fn read_utf8_string_u64_non_strict( &mut self, max_len: usize, ) -> Result<String>
Reads a UTF-8 string prefixed by an unsigned LEB128 u64 byte length.
Prefer this method over the usize variant for persistent files and cross-platform protocols because the length field is independent of the current Rust target’s pointer width.
§Parameters
- max_len: Maximum accepted UTF-8 payload length in bytes.
§Returns
Returns the decoded UTF-8 string.
§Errors
Returns an input, conversion, or allocation error, or an invalid-data error for a malformed or excessive length or invalid UTF-8.
Source§impl<R> BufferedLeb128Reader<R, Strict>
impl<R> BufferedLeb128Reader<R, Strict>
Sourcepub fn read_usize(&mut self) -> Result<usize>
pub fn read_usize(&mut self) -> Result<usize>
Sourcepub fn read_isize(&mut self) -> Result<isize>
pub fn read_isize(&mut self) -> Result<isize>
Sourcepub fn read_utf8_string_usize(&mut self, max_len: usize) -> Result<String>
pub fn read_utf8_string_usize(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by an unsigned LEB128 byte length.
The length prefix is decoded as usize, so this format is target-width dependent. Prefer a fixed-width length prefix for persistent files and cross-platform protocols.
§Parameters
- max_len: Maximum accepted UTF-8 payload length in bytes.
§Returns
Returns the decoded UTF-8 string.
§Errors
Returns an input or allocation error, or an invalid-data error for a malformed or excessive length or invalid UTF-8.
Sourcepub fn read_utf8_string_u64(&mut self, max_len: usize) -> Result<String>
pub fn read_utf8_string_u64(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by an unsigned LEB128 u64 byte length.
Prefer this method over the usize variant for persistent files and cross-platform protocols because the length field is independent of the current Rust target’s pointer width.
§Parameters
- max_len: Maximum accepted UTF-8 payload length in bytes.
§Returns
Returns the decoded UTF-8 string.
§Errors
Returns an input, conversion, or allocation error, or an invalid-data error for a malformed or excessive length or invalid UTF-8.
Source§impl<R, P> BufferedLeb128Reader<R, P>
impl<R, P> BufferedLeb128Reader<R, P>
Sourcepub fn is_buffered(&self) -> bool
pub fn is_buffered(&self) -> bool
Returns whether this reader buffers input.
Sourcepub unsafe fn read_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize>
pub unsafe fn read_unchecked( &mut self, output: &mut [u8], index: usize, count: usize, ) -> Result<usize>
Reads up to count bytes into an indexed output range.
§Safety
index..index + count must be a valid range within output.
Sourcepub fn read(&mut self, output: &mut [u8]) -> Result<usize>
pub fn read(&mut self, output: &mut [u8]) -> Result<usize>
Reads bytes into the full output slice.
Sourcepub unsafe fn read_fully_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize>
pub unsafe fn read_fully_unchecked( &mut self, output: &mut [u8], index: usize, count: usize, ) -> Result<usize>
Reads bytes into an indexed range until it is full or EOF.
§Safety
index..index + count must be a valid range within output.
Sourcepub fn read_fully(&mut self, output: &mut [u8]) -> Result<usize>
pub fn read_fully(&mut self, output: &mut [u8]) -> Result<usize>
Reads bytes into the full output slice until it is full or EOF.
Sourcepub fn read_exactly(&mut self, output: &mut [u8]) -> Result<()>
pub fn read_exactly(&mut self, output: &mut [u8]) -> Result<()>
Reads bytes until the full output slice is filled.
Trait Implementations§
Source§impl<R, P> Input for BufferedLeb128Reader<R, P>
impl<R, P> Input for BufferedLeb128Reader<R, P>
Source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Source§unsafe fn read_unchecked(
&mut self,
output: &mut [u8],
index: usize,
count: usize,
) -> Result<usize>
unsafe fn read_unchecked( &mut self, output: &mut [u8], index: usize, count: usize, ) -> Result<usize>
Reads up to count bytes into an indexed output range.
§Parameters
output: Destination slice.index: First destination index.count: Maximum number of bytes to read.
§Returns
Returns the number of bytes read.
§Errors
Returns an error reported while reading the buffered input.
§Safety
index..index + count must be a valid range within output.
Source§fn read(&mut self, output: &mut [Self::Item]) -> Result<usize, Error>
fn read(&mut self, output: &mut [Self::Item]) -> Result<usize, Error>
Source§unsafe fn read_fully_unchecked(
&mut self,
output: &mut [Self::Item],
index: usize,
count: usize,
) -> Result<usize, Error>
unsafe fn read_fully_unchecked( &mut self, output: &mut [Self::Item], index: usize, count: usize, ) -> Result<usize, Error>
Auto Trait Implementations§
impl<R, P> Freeze for BufferedLeb128Reader<R, P>where
R: Freeze,
impl<R, P> RefUnwindSafe for BufferedLeb128Reader<R, P>where
R: RefUnwindSafe,
impl<R, P> Send for BufferedLeb128Reader<R, P>where
R: Send,
impl<R, P> Sync for BufferedLeb128Reader<R, P>where
R: Sync,
impl<R, P> Unpin for BufferedLeb128Reader<R, P>where
R: Unpin,
impl<R, P> UnsafeUnpin for BufferedLeb128Reader<R, P>where
R: UnsafeUnpin,
impl<R, P> UnwindSafe for BufferedLeb128Reader<R, P>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<R> BinaryReadExt for R
impl<R> BinaryReadExt for R
Source§fn read_u16(&mut self, byte_order: ByteOrder) -> Result<u16>
fn read_u16(&mut self, byte_order: ByteOrder) -> Result<u16>
Source§fn read_u16_be(&mut self) -> Result<u16>
fn read_u16_be(&mut self) -> Result<u16>
Source§fn read_u16_le(&mut self) -> Result<u16>
fn read_u16_le(&mut self) -> Result<u16>
Source§fn read_u32(&mut self, byte_order: ByteOrder) -> Result<u32>
fn read_u32(&mut self, byte_order: ByteOrder) -> Result<u32>
Source§fn read_u32_be(&mut self) -> Result<u32>
fn read_u32_be(&mut self) -> Result<u32>
Source§fn read_u32_le(&mut self) -> Result<u32>
fn read_u32_le(&mut self) -> Result<u32>
Source§fn read_u64(&mut self, byte_order: ByteOrder) -> Result<u64>
fn read_u64(&mut self, byte_order: ByteOrder) -> Result<u64>
Source§fn read_u64_be(&mut self) -> Result<u64>
fn read_u64_be(&mut self) -> Result<u64>
Source§fn read_u64_le(&mut self) -> Result<u64>
fn read_u64_le(&mut self) -> Result<u64>
Source§fn read_u128(&mut self, byte_order: ByteOrder) -> Result<u128>
fn read_u128(&mut self, byte_order: ByteOrder) -> Result<u128>
Source§fn read_u128_be(&mut self) -> Result<u128>
fn read_u128_be(&mut self) -> Result<u128>
Source§fn read_u128_le(&mut self) -> Result<u128>
fn read_u128_le(&mut self) -> Result<u128>
Source§fn read_i16(&mut self, byte_order: ByteOrder) -> Result<i16>
fn read_i16(&mut self, byte_order: ByteOrder) -> Result<i16>
Source§fn read_i16_le(&mut self) -> Result<i16>
fn read_i16_le(&mut self) -> Result<i16>
Source§fn read_i32(&mut self, byte_order: ByteOrder) -> Result<i32>
fn read_i32(&mut self, byte_order: ByteOrder) -> Result<i32>
Source§fn read_i32_le(&mut self) -> Result<i32>
fn read_i32_le(&mut self) -> Result<i32>
Source§fn read_i64(&mut self, byte_order: ByteOrder) -> Result<i64>
fn read_i64(&mut self, byte_order: ByteOrder) -> Result<i64>
Source§fn read_i64_le(&mut self) -> Result<i64>
fn read_i64_le(&mut self) -> Result<i64>
Source§fn read_i128(&mut self, byte_order: ByteOrder) -> Result<i128>
fn read_i128(&mut self, byte_order: ByteOrder) -> Result<i128>
Source§fn read_i128_be(&mut self) -> Result<i128>
fn read_i128_be(&mut self) -> Result<i128>
Source§fn read_i128_le(&mut self) -> Result<i128>
fn read_i128_le(&mut self) -> Result<i128>
Source§fn read_f32(&mut self, byte_order: ByteOrder) -> Result<f32>
fn read_f32(&mut self, byte_order: ByteOrder) -> Result<f32>
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
Source§impl<R> Leb128ReadExt for R
impl<R> Leb128ReadExt for R
Source§fn read_uleb_u8_non_strict(&mut self) -> Result<u8>
fn read_uleb_u8_non_strict(&mut self) -> Result<u8>
u8. Read moreSource§fn read_uleb_u16_non_strict(&mut self) -> Result<u16>
fn read_uleb_u16_non_strict(&mut self) -> Result<u16>
u16. Read moreSource§fn read_uleb_u16_strict(&mut self) -> Result<u16>
fn read_uleb_u16_strict(&mut self) -> Result<u16>
u16. Read moreSource§fn read_uleb_u32_non_strict(&mut self) -> Result<u32>
fn read_uleb_u32_non_strict(&mut self) -> Result<u32>
u32. Read moreSource§fn read_uleb_u32_strict(&mut self) -> Result<u32>
fn read_uleb_u32_strict(&mut self) -> Result<u32>
u32. Read moreSource§fn read_uleb_u64_non_strict(&mut self) -> Result<u64>
fn read_uleb_u64_non_strict(&mut self) -> Result<u64>
u64. Read moreSource§fn read_uleb_u64_strict(&mut self) -> Result<u64>
fn read_uleb_u64_strict(&mut self) -> Result<u64>
u64. Read moreSource§fn read_uleb_u128_non_strict(&mut self) -> Result<u128>
fn read_uleb_u128_non_strict(&mut self) -> Result<u128>
u128. Read moreSource§fn read_uleb_u128_strict(&mut self) -> Result<u128>
fn read_uleb_u128_strict(&mut self) -> Result<u128>
u128. Read moreSource§fn read_uleb_usize_non_strict(&mut self) -> Result<usize>
fn read_uleb_usize_non_strict(&mut self) -> Result<usize>
usize. Read moreSource§fn read_uleb_usize_strict(&mut self) -> Result<usize>
fn read_uleb_usize_strict(&mut self) -> Result<usize>
usize. Read moreSource§fn read_sleb_i8_non_strict(&mut self) -> Result<i8>
fn read_sleb_i8_non_strict(&mut self) -> Result<i8>
i8. Read moreSource§fn read_sleb_i16_non_strict(&mut self) -> Result<i16>
fn read_sleb_i16_non_strict(&mut self) -> Result<i16>
i16. Read moreSource§fn read_sleb_i32_non_strict(&mut self) -> Result<i32>
fn read_sleb_i32_non_strict(&mut self) -> Result<i32>
i32. Read moreSource§fn read_sleb_i64_non_strict(&mut self) -> Result<i64>
fn read_sleb_i64_non_strict(&mut self) -> Result<i64>
i64. Read moreSource§fn read_sleb_i128_non_strict(&mut self) -> Result<i128>
fn read_sleb_i128_non_strict(&mut self) -> Result<i128>
i128. Read moreSource§fn read_sleb_i128_strict(&mut self) -> Result<i128>
fn read_sleb_i128_strict(&mut self) -> Result<i128>
i128. Read moreSource§impl<T> StringReadExt for T
impl<T> StringReadExt for T
Source§fn read_utf8_payload_into(
&mut self,
bytes: &mut Vec<u8>,
len: usize,
max_len: usize,
) -> Result<(), Error>
fn read_utf8_payload_into( &mut self, bytes: &mut Vec<u8>, len: usize, max_len: usize, ) -> Result<(), Error>
Source§fn read_utf8_payload(
&mut self,
len: usize,
max_len: usize,
) -> Result<String, Error>
fn read_utf8_payload( &mut self, len: usize, max_len: usize, ) -> Result<String, Error>
Source§fn read_utf8_string_uleb_usize(
&mut self,
max_len: usize,
) -> Result<String, Error>
fn read_utf8_string_uleb_usize( &mut self, max_len: usize, ) -> Result<String, Error>
Source§fn read_utf8_string_uleb_usize_strict(
&mut self,
max_len: usize,
) -> Result<String, Error>
fn read_utf8_string_uleb_usize_strict( &mut self, max_len: usize, ) -> Result<String, Error>
Source§fn read_utf8_string_uleb_u64(&mut self, max_len: usize) -> Result<String, Error>
fn read_utf8_string_uleb_u64(&mut self, max_len: usize) -> Result<String, Error>
u64 byte-length prefix. Read moreSource§fn read_utf8_string_uleb_u64_strict(
&mut self,
max_len: usize,
) -> Result<String, Error>
fn read_utf8_string_uleb_u64_strict( &mut self, max_len: usize, ) -> Result<String, Error>
u64 byte-length
prefix. Read moreSource§fn read_string_with_u16_len(
&mut self,
byte_order: ByteOrder,
max_len: usize,
) -> Result<String, Error>
fn read_string_with_u16_len( &mut self, byte_order: ByteOrder, max_len: usize, ) -> Result<String, Error>
u16 byte-length prefix. Read moreSource§fn read_string_with_u16_len_be(
&mut self,
max_len: usize,
) -> Result<String, Error>
fn read_string_with_u16_len_be( &mut self, max_len: usize, ) -> Result<String, Error>
u16 byte-length prefix. Read moreSource§fn read_string_with_u16_len_le(
&mut self,
max_len: usize,
) -> Result<String, Error>
fn read_string_with_u16_len_le( &mut self, max_len: usize, ) -> Result<String, Error>
u16 byte-length prefix. Read moreSource§fn read_string_with_u32_len(
&mut self,
byte_order: ByteOrder,
max_len: usize,
) -> Result<String, Error>
fn read_string_with_u32_len( &mut self, byte_order: ByteOrder, max_len: usize, ) -> Result<String, Error>
u32 byte-length prefix. Read moreSource§impl<R> ZigZagReadExt for R
impl<R> ZigZagReadExt for R
Source§fn read_zig_zag_i8_non_strict(&mut self) -> Result<i8>
fn read_zig_zag_i8_non_strict(&mut self) -> Result<i8>
i8. Read moreSource§fn read_zig_zag_i16_non_strict(&mut self) -> Result<i16>
fn read_zig_zag_i16_non_strict(&mut self) -> Result<i16>
i16. Read moreSource§fn read_zig_zag_i32_non_strict(&mut self) -> Result<i32>
fn read_zig_zag_i32_non_strict(&mut self) -> Result<i32>
i32. Read moreSource§fn read_zig_zag_i64_non_strict(&mut self) -> Result<i64>
fn read_zig_zag_i64_non_strict(&mut self) -> Result<i64>
i64. Read moreSource§fn read_zig_zag_i128_non_strict(&mut self) -> Result<i128>
fn read_zig_zag_i128_non_strict(&mut self) -> Result<i128>
i128. Read more