Packet

Struct Packet 

Source
pub struct Packet<T: AsRef<[u8]>> { /* private fields */ }

Implementations§

Source§

impl<T: AsRef<[u8]>> Packet<T>

Source

pub const HEADER_SIZE: usize = 3usize

Source

pub const CHECKSUM_SIZE: usize = 2usize

Source

pub const OFFSET_SIZE: usize = 2usize

Source

pub const MAX_PAYLOAD_SIZE: usize = 1_024usize

Source

pub const MAX_MSG_ID_SIZE: usize = 15usize

Source

pub const BASE_PACKET_SIZE: usize = 5usize

Source

pub const MAX_PACKET_SIZE: usize = 1_044usize

Source

pub const CRC16_CCITT_FALSE: Algorithm<u16>

Source

pub fn new_unchecked(buffer: T) -> Packet<T>

Source

pub fn new(buffer: T) -> Result<Packet<T>, Error>

Source

pub fn check_len(&self) -> Result<(), Error>

Source

pub fn check_payload_length(&self) -> Result<(), Error>

Checks that the buffer contains enough bytes to read both the message ID and the payload bytes

Source

pub fn check_checksum(&self) -> Result<(), Error>

Source

pub fn wire_size(&self) -> Result<usize, Error>

Source

pub fn into_inner(self) -> T

Source

pub fn buffer_len(n_msg_id_bytes: usize, n_payload_bytes: usize) -> usize

Return the length of a buffer required to hold a message with a payload length of n_msg_id_bytes + n_payload_bytes.

Source

pub fn data_length(&self) -> u16

Source

pub fn typ_raw(&self) -> u8

Source

pub fn typ(&self) -> MessageType

Source

pub fn internal(&self) -> bool

Source

pub fn offset(&self) -> bool

Source

pub fn id_length_raw(&self) -> u8

Source

pub fn id_length(&self) -> Result<usize, Error>

Source

pub fn response(&self) -> bool

Source

pub fn acknum(&self) -> u8

Source

pub fn checksum(&self) -> Result<u16, Error>

Source

pub fn compute_checksum(&self) -> Result<u16, Error>

Source§

impl<T: AsRef<[u8]>> Packet<T>

Source

pub fn msg_id_raw(&self) -> Result<&[u8], Error>

Source

pub fn msg_id(&self) -> Result<MessageId<'_>, Error>

Source

pub fn payload(&self) -> Result<&[u8], Error>

Source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> Packet<T>

Source

pub fn set_data_length(&mut self, value: u16) -> Result<(), Error>

Source

pub fn set_typ(&mut self, value: MessageType)

Source

pub fn set_internal(&mut self, value: bool)

Source

pub fn set_offset(&mut self, value: bool)

Source

pub fn set_id_length(&mut self, value: u8) -> Result<(), Error>

Source

pub fn set_response(&mut self, value: bool)

Source

pub fn set_acknum(&mut self, value: u8)

Source

pub fn msg_id_mut(&mut self) -> Result<&mut [u8], Error>

Source

pub fn payload_mut(&mut self) -> Result<&mut [u8], Error>

Source

pub fn set_checksum(&mut self, value: u16) -> Result<(), Error>

Trait Implementations§

Source§

impl<T: AsRef<[u8]>> AsRef<[u8]> for Packet<T>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone + AsRef<[u8]>> Clone for Packet<T>

Source§

fn clone(&self) -> Packet<T>

Returns a duplicate 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<T: Debug + AsRef<[u8]>> Debug for Packet<T>

Source§

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

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

impl<T: AsRef<[u8]>> Display for Packet<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Packet<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Packet<T>
where T: RefUnwindSafe,

§

impl<T> Send for Packet<T>
where T: Send,

§

impl<T> Sync for Packet<T>
where T: Sync,

§

impl<T> Unpin for Packet<T>
where T: Unpin,

§

impl<T> UnwindSafe for Packet<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.