#[repr(C)]
pub struct HidIoPacketBuffer<const H: usize> { pub ptype: HidIoPacketType, pub id: HidIoCommandId, pub max_len: u32, pub data: Vec<u8, H>, pub done: bool, }
Expand description

HID-IO Packet Buffer Struct

Remarks

Used to store HID-IO data chunks. Will be chunked into individual packets on transmission.

Fields§

§ptype: HidIoPacketType

Type of packet (Continued is automatically set if needed)

§id: HidIoCommandId

Packet Id

§max_len: u32

Packet length for serialization (in bytes)

§data: Vec<u8, H>

Payload data, chunking is done automatically by serializer

§done: bool

Set False if buffer is not complete, True if it is

Implementations§

source§

impl<const H: usize> HidIoPacketBuffer<H>

source

pub fn new() -> HidIoPacketBuffer<H>

Constructor for HidIoPacketBuffer

Remarks

Initialize as blank

source

pub fn clear(&mut self)

Clear Data Sets done to false and resizes payload to 0

source

pub fn set(&mut self, buf: HidIoPacketBuffer<H>)

Set Data

source

pub fn serialized_len(&self) -> u32

Serialized length of buffer Returns the currently computed serialized length of the buffer. Can change based on the struct fields.

source

pub fn append_payload(&mut self, new_data: &[u8]) -> bool

Append payload data

Arguments
  • new_data - Vector of bytes
Remarks

Appends payload to HidIoPacketBuffer.

source

pub fn decode_packet( &mut self, packet_data: &[u8] ) -> Result<u32, HidIoParseError>

Append packet stream Returns the number of bytes used.

Arguments
  • packet_data - Vector of bytes of packet data
Remarks

Does packet decoding on the fly. Will set done parameter if this is the last packet.

source

pub fn serialize_buffer<'a>( &self, data: &'a mut [u8] ) -> Result<&'a [u8], HidIoParseError>

Serialize HidIoPacketBuffer

Remarks

Determine cont, width, upper_len and len fields According to this C-Struct:

struct HidIo_Packet {
   HidIo_Packet_Type type:3;
   uint8_t           cont:1;      // 0 - Only packet, 1 continued packet following
   uint8_t           id_width:1;  // 0 - 16bits, 1 - 32bits
   uint8_t           reserved:1;  // Reserved
   uint8_t           upper_len:2; // Upper 2 bits of length field (generally unused)
   uint8_t           len;         // Lower 8 bits of length field
   uint8_t           data[0];     // Start of data payload (may start with Id)
};

Trait Implementations§

source§

impl<const H: usize> Clone for HidIoPacketBuffer<H>

source§

fn clone(&self) -> HidIoPacketBuffer<H>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const H: usize> Debug for HidIoPacketBuffer<H>

source§

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

Formats the value using the given formatter. Read more
source§

impl<const H: usize> Default for HidIoPacketBuffer<H>

source§

fn default() -> HidIoPacketBuffer<H>

Returns the “default value” for a type. Read more
source§

impl<const H: usize> Display for HidIoPacketBuffer<H>

source§

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

Display formatter for HidIoPacketBuffer

source§

impl<const H: usize> PartialEq<HidIoPacketBuffer<H>> for HidIoPacketBuffer<H>

source§

fn eq(&self, other: &HidIoPacketBuffer<H>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const H: usize> Eq for HidIoPacketBuffer<H>

source§

impl<const H: usize> StructuralEq for HidIoPacketBuffer<H>

source§

impl<const H: usize> StructuralPartialEq for HidIoPacketBuffer<H>

Auto Trait Implementations§

§

impl<const H: usize> RefUnwindSafe for HidIoPacketBuffer<H>

§

impl<const H: usize> Send for HidIoPacketBuffer<H>

§

impl<const H: usize> Sync for HidIoPacketBuffer<H>

§

impl<const H: usize> Unpin for HidIoPacketBuffer<H>

§

impl<const H: usize> UnwindSafe for HidIoPacketBuffer<H>

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.