Struct canadensis_encoding::ReadCursor
source · [−]pub struct ReadCursor<'b> { /* private fields */ }
Expand description
A cursor over a byte slice for easy deserializing of UAVCAN data types
Functions that read values will return zero when reading beyond the end of the bytes, in accordance with the implicit zero extension rule (specification section 3.7.1.5)
Implementations
sourceimpl<'b> ReadCursor<'b>
impl<'b> ReadCursor<'b>
sourcepub fn new(bytes: &'b [u8]) -> Self
pub fn new(bytes: &'b [u8]) -> Self
Creates a cursor that will read starting at the beginning of the provided slice
sourcepub fn as_bytes(&self) -> Option<&'b [u8]>
pub fn as_bytes(&self) -> Option<&'b [u8]>
If this cursor is aligned to a byte boundary, this function returns the slice of bytes that remain to be read.
Caution: This function bypasses the normal mechanism for keeping track of which bytes
have already been read. If you consume any of the returned bytes, you must call
advance_bytes()
so that they will not be read again alter.
sourcepub fn read_aligned_u8(&mut self) -> u8
pub fn read_aligned_u8(&mut self) -> u8
Reads an 8-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn read_aligned_u16(&mut self) -> u16
pub fn read_aligned_u16(&mut self) -> u16
Reads a 16-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn read_aligned_u32(&mut self) -> u32
pub fn read_aligned_u32(&mut self) -> u32
Reads a 32-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn read_aligned_u64(&mut self) -> u64
pub fn read_aligned_u64(&mut self) -> u64
Reads a 64-bit integer
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn advance_bytes(&mut self, byte_increment: usize)
pub fn advance_bytes(&mut self, byte_increment: usize)
Marks some bytes has having already been read
This function should only be used with as_bytes()
when manually
handling bytes.
sourcepub fn align_to_8_bits(&mut self)
pub fn align_to_8_bits(&mut self)
Skips up to 7 bits so that this cursor is aligned to 8 bits (one byte)
sourcepub fn is_aligned_to_8_bits(&self) -> bool
pub fn is_aligned_to_8_bits(&self) -> bool
Returns true if this cursor is aligned to a multiple of 8 bits
sourcepub fn read_aligned_f16(&mut self) -> f16
pub fn read_aligned_f16(&mut self) -> f16
Reads a 16-bit floating-point value
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn read_aligned_f32(&mut self) -> f32
pub fn read_aligned_f32(&mut self) -> f32
Reads a 32-bit floating-point value
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn read_aligned_f64(&mut self) -> f64
pub fn read_aligned_f64(&mut self) -> f64
Reads a 64-bit floating-point value
Panics
This function panics if the cursor is not aligned to a multiple of 8 bits.
sourcepub fn read_bytes(&mut self, bytes: &mut [u8])
pub fn read_bytes(&mut self, bytes: &mut [u8])
Reads a byte array
sourcepub fn read_composite<T>(&mut self) -> Result<T, DeserializeError> where
T: Deserialize,
pub fn read_composite<T>(&mut self) -> Result<T, DeserializeError> where
T: Deserialize,
Reads a composite object
This function returns an error if T is delimited and the delimiter header has an invalid length.
It also return an error if T’s deserialize implementation encounters an error.
sourceimpl ReadCursor<'_>
impl ReadCursor<'_>
sourceimpl ReadCursor<'_>
impl ReadCursor<'_>
Trait Implementations
Auto Trait Implementations
impl<'b> RefUnwindSafe for ReadCursor<'b>
impl<'b> Send for ReadCursor<'b>
impl<'b> Sync for ReadCursor<'b>
impl<'b> Unpin for ReadCursor<'b>
impl<'b> UnwindSafe for ReadCursor<'b>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more