pub struct BinaryReader<R, O = BigEndian> { /* private fields */ }Expand description
Reader wrapper for fixed-width binary values.
The byte order is selected by the O type parameter. Use
BinaryReader<R, BigEndian> for big-endian data and
BinaryReader<R, LittleEndian> for little-endian data.
§Type Parameters
R: Underlying byte input.O: Compile-time byte-order specification.
§Examples
use qubit_codec::BigEndian;
use qubit_io_binary::BinaryReader;
use std::io::Cursor;
let mut reader = BinaryReader::<_, BigEndian>::new(Cursor::new([0x12, 0x34]));
assert_eq!(reader.read_u16()?, 0x1234);Implementations§
Source§impl<R, O> BinaryReader<R, O>
impl<R, O> BinaryReader<R, O>
Sourcepub fn is_buffered(&self) -> bool
pub fn is_buffered(&self) -> bool
Returns whether this reader buffers input.
§Returns
Returns true when reads may prefetch bytes into an internal buffer.
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.
§Parameters
output: Destination byte buffer.index: Start of the writable range.count: Maximum number of bytes to read.
§Returns
Returns the number of bytes read; zero indicates end-of-input.
§Errors
Returns the underlying input error.
§Safety
index..index + count must be a valid range within output.
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.
§Parameters
output: Destination byte buffer.index: Start of the writable range.count: Maximum number of bytes to read.
§Returns
Returns the number of bytes read before the range is full or EOF.
§Errors
Returns the underlying input error.
§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>
Source§impl<R, O> BinaryReader<R, O>
impl<R, O> BinaryReader<R, O>
Source§impl<R, O> BinaryReader<R, O>where
O: ByteOrderSpec,
impl<R, O> BinaryReader<R, O>where
O: ByteOrderSpec,
Sourcepub const fn byte_order(&self) -> ByteOrder
pub const fn byte_order(&self) -> ByteOrder
Returns the byte order selected by this reader.
§Returns
Returns the compile-time byte order as a runtime value.
Sourcepub fn inner_mut(&mut self) -> &mut R
pub fn inner_mut(&mut self) -> &mut R
Returns an exclusive reference to the underlying reader.
§Returns
Returns mutable access to the wrapped reader.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Source§impl<R> BinaryReader<R, BigEndian>
impl<R> BinaryReader<R, BigEndian>
Sourcepub fn read_string_with_u16_len(&mut self, max_len: usize) -> Result<String>
pub fn read_string_with_u16_len(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by a 16-bit byte length.
§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
std::io::ErrorKind::InvalidData when the encoded length
exceeds max_len or the payload is not valid UTF-8.
Sourcepub fn read_string_with_u32_len(&mut self, max_len: usize) -> Result<String>
pub fn read_string_with_u32_len(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by a 32-bit byte length.
§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
std::io::ErrorKind::InvalidData when the encoded length
exceeds max_len or the payload is not valid UTF-8.
Source§impl<R> BinaryReader<R, LittleEndian>
impl<R> BinaryReader<R, LittleEndian>
Sourcepub fn read_string_with_u16_len(&mut self, max_len: usize) -> Result<String>
pub fn read_string_with_u16_len(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by a 16-bit byte length.
§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
std::io::ErrorKind::InvalidData when the encoded length
exceeds max_len or the payload is not valid UTF-8.
Sourcepub fn read_string_with_u32_len(&mut self, max_len: usize) -> Result<String>
pub fn read_string_with_u32_len(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by a 32-bit byte length.
§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
std::io::ErrorKind::InvalidData when the encoded length
exceeds max_len or the payload is not valid UTF-8.
Source§impl<R> BinaryReader<R, NativeEndian>
impl<R> BinaryReader<R, NativeEndian>
Sourcepub fn read_string_with_u16_len(&mut self, max_len: usize) -> Result<String>
pub fn read_string_with_u16_len(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by a 16-bit byte length.
§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
std::io::ErrorKind::InvalidData when the encoded length
exceeds max_len or the payload is not valid UTF-8.
Sourcepub fn read_string_with_u32_len(&mut self, max_len: usize) -> Result<String>
pub fn read_string_with_u32_len(&mut self, max_len: usize) -> Result<String>
Reads a UTF-8 string prefixed by a 32-bit byte length.
§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
std::io::ErrorKind::InvalidData when the encoded length
exceeds max_len or the payload is not valid UTF-8.
Trait Implementations§
Source§impl<R, O> Input for BinaryReader<R, O>
impl<R, O> Input for BinaryReader<R, O>
Source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Reports whether the wrapped input is buffered.
§Returns
Returns the wrapped input’s buffering state.
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 by the wrapped 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, O> Freeze for BinaryReader<R, O>
impl<R, O> RefUnwindSafe for BinaryReader<R, O>
impl<R, O> Send for BinaryReader<R, O>
impl<R, O> Sync for BinaryReader<R, O>
impl<R, O> Unpin for BinaryReader<R, O>
impl<R, O> UnsafeUnpin for BinaryReader<R, O>
impl<R, O> UnwindSafe for BinaryReader<R, O>
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 moreimpl<T> SeekableInput for T
Source§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