pub struct ReadCursor<'b> { /* private fields */ }
Expand description

A cursor over a byte slice for easy deserializing of Cyphal 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§

source§

impl<'b> ReadCursor<'b>

source

pub fn new(bytes: &'b [u8]) -> Self

Creates a cursor that will read starting at the beginning of the provided slice

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn align_to_8_bits(&mut self)

Skips up to 7 bits so that this cursor is aligned to 8 bits (one byte)

source

pub fn is_aligned_to_8_bits(&self) -> bool

Returns true if this cursor is aligned to a multiple of 8 bits

source

pub fn read_f16(&mut self) -> f16

Reads a 16-bit floating-point value

source

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.

source

pub fn read_f32(&mut self) -> f32

Reads a 32-bit floating-point value

source

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.

source

pub fn read_f64(&mut self) -> f64

Reads a 64-bit floating-point value

source

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.

source

pub fn read_bytes(&mut self, bytes: &mut [u8])

Reads a byte array

source

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.

source

pub fn read_bool(&mut self) -> bool

Reads a boolean value (1 bit)

source§

impl ReadCursor<'_>

source

pub fn read_u1(&mut self) -> u8

Reads a 1-bit unsigned integer

source

pub fn read_u2(&mut self) -> u8

Reads a 2-bit unsigned integer

source

pub fn read_u3(&mut self) -> u8

Reads a 3-bit unsigned integer

source

pub fn read_u4(&mut self) -> u8

Reads a 4-bit unsigned integer

source

pub fn read_u5(&mut self) -> u8

Reads a 5-bit unsigned integer

source

pub fn read_u6(&mut self) -> u8

Reads a 6-bit unsigned integer

source

pub fn read_u7(&mut self) -> u8

Reads a 7-bit unsigned integer

source

pub fn read_u8(&mut self) -> u8

Reads a 8-bit unsigned integer

source

pub fn read_u9(&mut self) -> u16

Reads a 9-bit unsigned integer

source

pub fn read_u10(&mut self) -> u16

Reads a 10-bit unsigned integer

source

pub fn read_u11(&mut self) -> u16

Reads a 11-bit unsigned integer

source

pub fn read_u12(&mut self) -> u16

Reads a 12-bit unsigned integer

source

pub fn read_u13(&mut self) -> u16

Reads a 13-bit unsigned integer

source

pub fn read_u14(&mut self) -> u16

Reads a 14-bit unsigned integer

source

pub fn read_u15(&mut self) -> u16

Reads a 15-bit unsigned integer

source

pub fn read_u16(&mut self) -> u16

Reads a 16-bit unsigned integer

source

pub fn read_u17(&mut self) -> u32

Reads a 17-bit unsigned integer

source

pub fn read_u18(&mut self) -> u32

Reads a 18-bit unsigned integer

source

pub fn read_u19(&mut self) -> u32

Reads a 19-bit unsigned integer

source

pub fn read_u20(&mut self) -> u32

Reads a 20-bit unsigned integer

source

pub fn read_u21(&mut self) -> u32

Reads a 21-bit unsigned integer

source

pub fn read_u22(&mut self) -> u32

Reads a 22-bit unsigned integer

source

pub fn read_u23(&mut self) -> u32

Reads a 23-bit unsigned integer

source

pub fn read_u24(&mut self) -> u32

Reads a 24-bit unsigned integer

source

pub fn read_u25(&mut self) -> u32

Reads a 25-bit unsigned integer

source

pub fn read_u26(&mut self) -> u32

Reads a 26-bit unsigned integer

source

pub fn read_u27(&mut self) -> u32

Reads a 27-bit unsigned integer

source

pub fn read_u28(&mut self) -> u32

Reads a 28-bit unsigned integer

source

pub fn read_u29(&mut self) -> u32

Reads a 29-bit unsigned integer

source

pub fn read_u30(&mut self) -> u32

Reads a 30-bit unsigned integer

source

pub fn read_u31(&mut self) -> u32

Reads a 31-bit unsigned integer

source

pub fn read_u32(&mut self) -> u32

Reads a 32-bit unsigned integer

source

pub fn read_u33(&mut self) -> u64

Reads a 33-bit unsigned integer

source

pub fn read_u34(&mut self) -> u64

Reads a 34-bit unsigned integer

source

pub fn read_u35(&mut self) -> u64

Reads a 35-bit unsigned integer

source

pub fn read_u36(&mut self) -> u64

Reads a 36-bit unsigned integer

source

pub fn read_u37(&mut self) -> u64

Reads a 37-bit unsigned integer

source

pub fn read_u38(&mut self) -> u64

Reads a 38-bit unsigned integer

source

pub fn read_u39(&mut self) -> u64

Reads a 39-bit unsigned integer

source

pub fn read_u40(&mut self) -> u64

Reads a 40-bit unsigned integer

source

pub fn read_u41(&mut self) -> u64

Reads a 41-bit unsigned integer

source

pub fn read_u42(&mut self) -> u64

Reads a 42-bit unsigned integer

source

pub fn read_u43(&mut self) -> u64

Reads a 43-bit unsigned integer

source

pub fn read_u44(&mut self) -> u64

Reads a 44-bit unsigned integer

source

pub fn read_u45(&mut self) -> u64

Reads a 45-bit unsigned integer

source

pub fn read_u46(&mut self) -> u64

Reads a 46-bit unsigned integer

source

pub fn read_u47(&mut self) -> u64

Reads a 47-bit unsigned integer

source

pub fn read_u48(&mut self) -> u64

Reads a 48-bit unsigned integer

source

pub fn read_u49(&mut self) -> u64

Reads a 49-bit unsigned integer

source

pub fn read_u50(&mut self) -> u64

Reads a 50-bit unsigned integer

source

pub fn read_u51(&mut self) -> u64

Reads a 51-bit unsigned integer

source

pub fn read_u52(&mut self) -> u64

Reads a 52-bit unsigned integer

source

pub fn read_u53(&mut self) -> u64

Reads a 53-bit unsigned integer

source

pub fn read_u54(&mut self) -> u64

Reads a 54-bit unsigned integer

source

pub fn read_u55(&mut self) -> u64

Reads a 55-bit unsigned integer

source

pub fn read_u56(&mut self) -> u64

Reads a 56-bit unsigned integer

source

pub fn read_u57(&mut self) -> u64

Reads a 57-bit unsigned integer

source

pub fn read_u58(&mut self) -> u64

Reads a 58-bit unsigned integer

source

pub fn read_u59(&mut self) -> u64

Reads a 59-bit unsigned integer

source

pub fn read_u60(&mut self) -> u64

Reads a 60-bit unsigned integer

source

pub fn read_u61(&mut self) -> u64

Reads a 61-bit unsigned integer

source

pub fn read_u62(&mut self) -> u64

Reads a 62-bit unsigned integer

source

pub fn read_u63(&mut self) -> u64

Reads a 63-bit unsigned integer

source

pub fn read_u64(&mut self) -> u64

Reads a 64-bit unsigned integer

source§

impl ReadCursor<'_>

source

pub fn skip_1(&mut self)

Advances the cursor to skip 1 bit

source

pub fn skip_2(&mut self)

Advances the cursor to skip 2 bits

source

pub fn skip_3(&mut self)

Advances the cursor to skip 3 bits

source

pub fn skip_4(&mut self)

Advances the cursor to skip 4 bits

source

pub fn skip_5(&mut self)

Advances the cursor to skip 5 bits

source

pub fn skip_6(&mut self)

Advances the cursor to skip 6 bits

source

pub fn skip_7(&mut self)

Advances the cursor to skip 7 bits

source

pub fn skip_8(&mut self)

Advances the cursor to skip 8 bits

source

pub fn skip_9(&mut self)

Advances the cursor to skip 9 bits

source

pub fn skip_10(&mut self)

Advances the cursor to skip 10 bits

source

pub fn skip_11(&mut self)

Advances the cursor to skip 11 bits

source

pub fn skip_12(&mut self)

Advances the cursor to skip 12 bits

source

pub fn skip_13(&mut self)

Advances the cursor to skip 13 bits

source

pub fn skip_14(&mut self)

Advances the cursor to skip 14 bits

source

pub fn skip_15(&mut self)

Advances the cursor to skip 15 bits

source

pub fn skip_16(&mut self)

Advances the cursor to skip 16 bits

source

pub fn skip_17(&mut self)

Advances the cursor to skip 17 bits

source

pub fn skip_18(&mut self)

Advances the cursor to skip 18 bits

source

pub fn skip_19(&mut self)

Advances the cursor to skip 19 bits

source

pub fn skip_20(&mut self)

Advances the cursor to skip 20 bits

source

pub fn skip_21(&mut self)

Advances the cursor to skip 21 bits

source

pub fn skip_22(&mut self)

Advances the cursor to skip 22 bits

source

pub fn skip_23(&mut self)

Advances the cursor to skip 23 bits

source

pub fn skip_24(&mut self)

Advances the cursor to skip 24 bits

source

pub fn skip_25(&mut self)

Advances the cursor to skip 25 bits

source

pub fn skip_26(&mut self)

Advances the cursor to skip 26 bits

source

pub fn skip_27(&mut self)

Advances the cursor to skip 27 bits

source

pub fn skip_28(&mut self)

Advances the cursor to skip 28 bits

source

pub fn skip_29(&mut self)

Advances the cursor to skip 29 bits

source

pub fn skip_30(&mut self)

Advances the cursor to skip 30 bits

source

pub fn skip_31(&mut self)

Advances the cursor to skip 31 bits

source

pub fn skip_32(&mut self)

Advances the cursor to skip 32 bits

source

pub fn skip_33(&mut self)

Advances the cursor to skip 33 bits

source

pub fn skip_34(&mut self)

Advances the cursor to skip 34 bits

source

pub fn skip_35(&mut self)

Advances the cursor to skip 35 bits

source

pub fn skip_36(&mut self)

Advances the cursor to skip 36 bits

source

pub fn skip_37(&mut self)

Advances the cursor to skip 37 bits

source

pub fn skip_38(&mut self)

Advances the cursor to skip 38 bits

source

pub fn skip_39(&mut self)

Advances the cursor to skip 39 bits

source

pub fn skip_40(&mut self)

Advances the cursor to skip 40 bits

source

pub fn skip_41(&mut self)

Advances the cursor to skip 41 bits

source

pub fn skip_42(&mut self)

Advances the cursor to skip 42 bits

source

pub fn skip_43(&mut self)

Advances the cursor to skip 43 bits

source

pub fn skip_44(&mut self)

Advances the cursor to skip 44 bits

source

pub fn skip_45(&mut self)

Advances the cursor to skip 45 bits

source

pub fn skip_46(&mut self)

Advances the cursor to skip 46 bits

source

pub fn skip_47(&mut self)

Advances the cursor to skip 47 bits

source

pub fn skip_48(&mut self)

Advances the cursor to skip 48 bits

source

pub fn skip_49(&mut self)

Advances the cursor to skip 49 bits

source

pub fn skip_50(&mut self)

Advances the cursor to skip 50 bits

source

pub fn skip_51(&mut self)

Advances the cursor to skip 51 bits

source

pub fn skip_52(&mut self)

Advances the cursor to skip 52 bits

source

pub fn skip_53(&mut self)

Advances the cursor to skip 53 bits

source

pub fn skip_54(&mut self)

Advances the cursor to skip 54 bits

source

pub fn skip_55(&mut self)

Advances the cursor to skip 55 bits

source

pub fn skip_56(&mut self)

Advances the cursor to skip 56 bits

source

pub fn skip_57(&mut self)

Advances the cursor to skip 57 bits

source

pub fn skip_58(&mut self)

Advances the cursor to skip 58 bits

source

pub fn skip_59(&mut self)

Advances the cursor to skip 59 bits

source

pub fn skip_60(&mut self)

Advances the cursor to skip 60 bits

source

pub fn skip_61(&mut self)

Advances the cursor to skip 61 bits

source

pub fn skip_62(&mut self)

Advances the cursor to skip 62 bits

source

pub fn skip_63(&mut self)

Advances the cursor to skip 63 bits

source

pub fn skip_64(&mut self)

Advances the cursor to skip 64 bits

Trait Implementations§

source§

impl<'b> Debug for ReadCursor<'b>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.