pub struct Packet {
pub start_byte: u8,
pub length: u8,
pub payload: Vec<u8>,
pub checksum: u8,
pub end_byte: u8,
}Expand description
Represents a packet with start, length, payload, checksum, and end bytes
Fields§
§start_byte: u8Start byte (START_BYTE)
length: u8Length of payload
payload: Vec<u8>Payload
checksum: u8Checksum
end_byte: u8End byte (END_BYTE)
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn new(payload: Vec<u8>) -> Self
pub fn new(payload: Vec<u8>) -> Self
Creates a new packet with the given payload.
The payload will be escaped and the checksum will be calculated.
Sourcepub fn calculate_checksum(payload: &[u8]) -> u8
pub fn calculate_checksum(payload: &[u8]) -> u8
Calculates the checksum of the given payload.
Sourcepub fn escape_payload(payload: &[u8]) -> Vec<u8> ⓘ
pub fn escape_payload(payload: &[u8]) -> Vec<u8> ⓘ
Escapes the given payload by replacing START_BYTE, END_BYTE, and ESCAPE_BYTE with their escaped versions.
Sourcepub fn unescape_payload(payload: &[u8]) -> Vec<u8> ⓘ
pub fn unescape_payload(payload: &[u8]) -> Vec<u8> ⓘ
Unescapes the given payload by replacing ESCAPE_BYTE with its unescaped version.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, &'static str>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, &'static str>
Creates a packet from its byte representation.
Trait Implementations§
impl StructuralPartialEq for Packet
Auto Trait Implementations§
impl Freeze for Packet
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
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