Struct Reader
pub struct Reader {
rest: Bytes,
}Expand description
Reads values from the start of a shared buffer.
Decode implementations read their fields from a reader. Bytes and
strings that a value keeps share the buffer instead of copying it.
§Example
use bytes::Bytes;
use ql_qmi::codec::{Reader, ValueError};
let mut reader = Reader::new(Bytes::from_static(&[0x34, 0x12, 1, b'o', b'k']));
assert_eq!(reader.read::<u16>()?, 0x1234);
assert!(reader.read::<bool>()?);
assert_eq!(reader.read_bytes(1)?, b"o"[..]);
assert_eq!(reader.read_rest(), b"k"[..]);
assert!(reader.is_empty());Fields§
§rest: BytesImplementations§
§impl Reader
impl Reader
pub fn read<T: Decode>(&mut self) -> Result<T, ValueError>
pub fn read<T: Decode>(&mut self) -> Result<T, ValueError>
pub fn read_bytes(&mut self, len: usize) -> Result<Bytes, ValueError>
pub fn read_bytes(&mut self, len: usize) -> Result<Bytes, ValueError>
Reads the next len bytes without copying them.
§Errors
Returns ValueError::Truncated if fewer bytes are left.
pub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], ValueError>
pub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], ValueError>
Trait Implementations§
impl Eq for Reader
impl StructuralPartialEq for Reader
Auto Trait Implementations§
impl !Freeze for Reader
impl RefUnwindSafe for Reader
impl Send for Reader
impl Sync for Reader
impl Unpin for Reader
impl UnsafeUnpin for Reader
impl UnwindSafe for Reader
Blanket Implementations§
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
Mutably borrows from an owned value. Read more