pub struct ZigZagReader<R> { /* private fields */ }Expand description
Reader wrapper for ZigZag encoded signed integers.
This wrapper defaults to non-strict decoding of the underlying unsigned
LEB128 value. Use ZigZagReader::with_strict or
ZigZagReader::set_strict to reject non-canonical underlying encodings.
§Examples
use std::io::Cursor;
use qubit_io::{
ZigZagReader,
ZigZagWriter,
};
let mut output = ZigZagWriter::new(Vec::new());
output.write_i32(-123)?;
let mut input = ZigZagReader::with_strict(Cursor::new(output.into_inner()), true);
assert_eq!(-123, input.read_i32()?);Implementations§
Source§impl<R> ZigZagReader<R>
impl<R> ZigZagReader<R>
Sourcepub fn with_strict(inner: R, strict: bool) -> Self
pub fn with_strict(inner: R, strict: bool) -> Self
Sourcepub fn is_strict(&self) -> bool
pub fn is_strict(&self) -> bool
Reports whether strict underlying LEB128 decoding is enabled.
§Returns
true when non-canonical underlying LEB128 encodings are rejected.
Sourcepub fn set_strict(&mut self, strict: bool)
pub fn set_strict(&mut self, strict: bool)
Changes the underlying LEB128 policy used by subsequent reads.
§Parameters
strict: Whether to reject non-canonical underlying LEB128 encodings.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Source§impl<R> ZigZagReader<R>where
R: Read,
impl<R> ZigZagReader<R>where
R: Read,
Sourcepub fn read_i8(&mut self) -> Result<i8>
pub fn read_i8(&mut self) -> Result<i8>
Reads a ZigZag encoded i8.
§Errors
Returns an I/O error from the wrapped reader, or InvalidData for
malformed or overflowing underlying unsigned LEB128 input. In strict
mode, also returns InvalidData for non-canonical underlying LEB128
input.
Sourcepub fn read_i16(&mut self) -> Result<i16>
pub fn read_i16(&mut self) -> Result<i16>
Reads a ZigZag encoded i16.
§Errors
Returns an I/O error from the wrapped reader, or InvalidData for
malformed or overflowing underlying unsigned LEB128 input. In strict
mode, also returns InvalidData for non-canonical underlying LEB128
input.
Sourcepub fn read_i32(&mut self) -> Result<i32>
pub fn read_i32(&mut self) -> Result<i32>
Reads a ZigZag encoded i32.
§Errors
Returns an I/O error from the wrapped reader, or InvalidData for
malformed or overflowing underlying unsigned LEB128 input. In strict
mode, also returns InvalidData for non-canonical underlying LEB128
input.
Sourcepub fn read_i64(&mut self) -> Result<i64>
pub fn read_i64(&mut self) -> Result<i64>
Reads a ZigZag encoded i64.
§Errors
Returns an I/O error from the wrapped reader, or InvalidData for
malformed or overflowing underlying unsigned LEB128 input. In strict
mode, also returns InvalidData for non-canonical underlying LEB128
input.
Sourcepub fn read_i128(&mut self) -> Result<i128>
pub fn read_i128(&mut self) -> Result<i128>
Reads a ZigZag encoded i128.
§Errors
Returns an I/O error from the wrapped reader, or InvalidData for
malformed or overflowing underlying unsigned LEB128 input. In strict
mode, also returns InvalidData for non-canonical underlying LEB128
input.
Sourcepub fn read_isize(&mut self) -> Result<isize>
pub fn read_isize(&mut self) -> Result<isize>
Reads a ZigZag encoded isize.
§Errors
Returns an I/O error from the wrapped reader, or InvalidData for
malformed or overflowing underlying unsigned LEB128 input. In strict
mode, also returns InvalidData for non-canonical underlying LEB128
input.
Trait Implementations§
Source§impl<R> BufRead for ZigZagReader<R>where
R: BufRead,
impl<R> BufRead for ZigZagReader<R>where
R: BufRead,
Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Read methods, if empty. Read moreSource§fn consume(&mut self, amount: usize)
fn consume(&mut self, amount: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl<R> Read for ZigZagReader<R>where
R: Read,
impl<R> Read for ZigZagReader<R>where
R: Read,
Source§fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<R> Seek for ZigZagReader<R>where
R: Seek,
impl<R> Seek for ZigZagReader<R>where
R: Seek,
Source§fn seek(&mut self, position: SeekFrom) -> Result<u64>
fn seek(&mut self, position: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Auto Trait Implementations§
impl<R> Freeze for ZigZagReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for ZigZagReader<R>where
R: RefUnwindSafe,
impl<R> Send for ZigZagReader<R>where
R: Send,
impl<R> Sync for ZigZagReader<R>where
R: Sync,
impl<R> Unpin for ZigZagReader<R>where
R: Unpin,
impl<R> UnsafeUnpin for ZigZagReader<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for ZigZagReader<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BinaryReadExt for T
impl<T> BinaryReadExt for T
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<T> BufReadExt for T
impl<T> BufReadExt for T
Source§fn read_until_limited_into(
&mut self,
delimiter: u8,
output: &mut Vec<u8>,
max_len: usize,
) -> Result<usize, Error>
fn read_until_limited_into( &mut self, delimiter: u8, output: &mut Vec<u8>, max_len: usize, ) -> Result<usize, Error>
Source§fn read_line_limited(&mut self, max_len: usize) -> Result<String, Error>
fn read_line_limited(&mut self, max_len: usize) -> Result<String, Error>
max_len. Read moreSource§impl<T> Leb128ReadExt for T
impl<T> Leb128ReadExt for T
Source§fn read_uleb_u8_strict(&mut self) -> Result<u8, Error>
fn read_uleb_u8_strict(&mut self) -> Result<u8, Error>
u8. Read moreSource§fn read_uleb_u16_strict(&mut self) -> Result<u16, Error>
fn read_uleb_u16_strict(&mut self) -> Result<u16, Error>
u16. Read moreSource§fn read_uleb_u32_strict(&mut self) -> Result<u32, Error>
fn read_uleb_u32_strict(&mut self) -> Result<u32, Error>
u32. Read moreSource§fn read_uleb_u64_strict(&mut self) -> Result<u64, Error>
fn read_uleb_u64_strict(&mut self) -> Result<u64, Error>
u64. Read moreSource§fn read_uleb_u128_strict(&mut self) -> Result<u128, Error>
fn read_uleb_u128_strict(&mut self) -> Result<u128, Error>
u128. Read moreSource§fn read_uleb_usize(&mut self) -> Result<usize, Error>
fn read_uleb_usize(&mut self) -> Result<usize, Error>
usize. Read moreSource§fn read_uleb_usize_strict(&mut self) -> Result<usize, Error>
fn read_uleb_usize_strict(&mut self) -> Result<usize, Error>
usize. Read moreSource§fn read_sleb_i8_strict(&mut self) -> Result<i8, Error>
fn read_sleb_i8_strict(&mut self) -> Result<i8, Error>
i8. Read moreSource§fn read_sleb_i16_strict(&mut self) -> Result<i16, Error>
fn read_sleb_i16_strict(&mut self) -> Result<i16, Error>
i16. Read moreSource§fn read_sleb_i32_strict(&mut self) -> Result<i32, Error>
fn read_sleb_i32_strict(&mut self) -> Result<i32, Error>
i32. Read moreSource§fn read_sleb_i64_strict(&mut self) -> Result<i64, Error>
fn read_sleb_i64_strict(&mut self) -> Result<i64, Error>
i64. Read moreSource§impl<T> ReadExt for T
impl<T> ReadExt for T
Source§fn read_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
fn read_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
buffer is full or EOF is reached. Read moreSource§fn read_exact_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
fn read_exact_array<const N: usize>(&mut self) -> Result<[u8; N], Error>
N bytes into a stack-allocated array. Read moreSource§fn read_exact_vec_limited(
&mut self,
len: usize,
max_len: usize,
) -> Result<Vec<u8>, Error>
fn read_exact_vec_limited( &mut self, len: usize, max_len: usize, ) -> Result<Vec<u8>, Error>
len bytes into a new vector after checking a limit. Read moreSource§fn read_exact_vec_limited_into(
&mut self,
output: &mut Vec<u8>,
len: usize,
max_len: usize,
) -> Result<(), Error>
fn read_exact_vec_limited_into( &mut self, output: &mut Vec<u8>, len: usize, max_len: usize, ) -> Result<(), Error>
Source§fn discard_exact_or_eof(&mut self, bytes: u64) -> Result<u64, Error>
fn discard_exact_or_eof(&mut self, bytes: u64) -> Result<u64, Error>
bytes bytes from this reader. Read moreSource§fn copy_to(&mut self, writer: &mut dyn Write) -> Result<u64, Error>
fn copy_to(&mut self, writer: &mut dyn Write) -> Result<u64, Error>
writer. Read moreSource§fn copy_to_at_most(
&mut self,
writer: &mut dyn Write,
max_bytes: u64,
) -> Result<u64, Error>
fn copy_to_at_most( &mut self, writer: &mut dyn Write, max_bytes: u64, ) -> Result<u64, Error>
Source§fn copy_to_end_limited(
&mut self,
writer: &mut dyn Write,
max_bytes: u64,
) -> Result<u64, Error>
fn copy_to_end_limited( &mut self, writer: &mut dyn Write, max_bytes: u64, ) -> Result<u64, Error>
max_bytes. Read moreSource§fn read_to_end_limited(&mut self, max_len: usize) -> Result<Vec<u8>, Error>
fn read_to_end_limited(&mut self, max_len: usize) -> Result<Vec<u8>, Error>
Source§fn read_to_end_limited_into(
&mut self,
output: &mut Vec<u8>,
max_len: usize,
) -> Result<usize, Error>
fn read_to_end_limited_into( &mut self, output: &mut Vec<u8>, max_len: usize, ) -> Result<usize, Error>
output with a maximum accepted length. Read moreSource§impl<T> ReadSeekExt for T
impl<T> ReadSeekExt for T
Source§impl<T> StringReadExt for T
impl<T> StringReadExt for T
Source§fn read_utf8_string_uleb(&mut self, max_len: usize) -> Result<String, Error>
fn read_utf8_string_uleb(&mut self, max_len: usize) -> Result<String, Error>
Source§fn read_utf8_string_uleb_strict(
&mut self,
max_len: usize,
) -> Result<String, Error>
fn read_utf8_string_uleb_strict( &mut self, max_len: usize, ) -> Result<String, Error>
Source§fn read_utf8_string_u16_be(&mut self, max_len: usize) -> Result<String, Error>
fn read_utf8_string_u16_be(&mut self, max_len: usize) -> Result<String, Error>
u16 byte-length prefix. Read moreSource§fn read_utf8_string_u16_le(&mut self, max_len: usize) -> Result<String, Error>
fn read_utf8_string_u16_le(&mut self, max_len: usize) -> Result<String, Error>
u16 byte-length prefix. Read moreSource§impl<T> ZigZagReadExt for T
impl<T> ZigZagReadExt for T
Source§fn read_zigzag_i8_strict(&mut self) -> Result<i8, Error>
fn read_zigzag_i8_strict(&mut self) -> Result<i8, Error>
i8. Read moreSource§fn read_zigzag_i16_strict(&mut self) -> Result<i16, Error>
fn read_zigzag_i16_strict(&mut self) -> Result<i16, Error>
i16. Read moreSource§fn read_zigzag_i32_strict(&mut self) -> Result<i32, Error>
fn read_zigzag_i32_strict(&mut self) -> Result<i32, Error>
i32. Read moreSource§fn read_zigzag_i64_strict(&mut self) -> Result<i64, Error>
fn read_zigzag_i64_strict(&mut self) -> Result<i64, Error>
i64. Read moreSource§fn read_zigzag_i128_strict(&mut self) -> Result<i128, Error>
fn read_zigzag_i128_strict(&mut self) -> Result<i128, Error>
i128. Read more