pub struct ProtocolMessage {
pub payload_length: u16,
pub message_id: u16,
pub src_device_id: u8,
pub dst_device_id: u8,
pub payload: Vec<u8>,
pub checksum: u16,
}Fields§
§payload_length: u16§message_id: u16§src_device_id: u8§dst_device_id: u8§payload: Vec<u8>§checksum: u16Implementations§
Source§impl ProtocolMessage
impl ProtocolMessage
Sourcepub fn new() -> Self
pub fn new() -> Self
Message Format
Each message consists of a header, optional payload, and checksum. The binary format is specified as follows:
| Byte | Type | Name | Description |
|---|---|---|---|
| 0 | u8 | start1 | Start frame identifier, ASCII ‘B’ |
| 1 | u8 | start2 | Start frame identifier, ASCII ‘R’ |
| 2-3 | u16 | payload_length | Number of bytes in payload. |
| 4-5 | u16 | message_id | The message id. |
| 6 | u8 | src_device_id | The device ID of the device sending the message. |
| 7 | u8 | dst_device_id | The device ID of the intended recipient of the message. |
| 8-n | u8[] | payload | The message payload. |
| (n+1)-(n+2) | u16 | checksum | The message checksum. The checksum is calculated as the sum of all the non-checksum bytes in the message. |
pub fn set_message(&mut self, message: &impl PingMessage)
pub fn set_src_device_id(&mut self, src_device_id: u8)
pub fn dst_device_id(&self) -> u8
pub fn set_dst_device_id(&mut self, dst_device_id: u8)
pub fn payload(&self) -> &[u8] ⓘ
pub fn checksum(&self) -> u16
pub fn update_checksum(&mut self)
pub fn calculate_crc(&self) -> u16
pub fn has_valid_crc(&self) -> bool
pub fn length(&self) -> usize
pub fn write(&self, writer: &mut dyn Write) -> Result<usize>
pub fn serialized(&self) -> Vec<u8> ⓘ
Trait Implementations§
Source§impl Clone for ProtocolMessage
impl Clone for ProtocolMessage
Source§fn clone(&self) -> ProtocolMessage
fn clone(&self) -> ProtocolMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ProtocolMessage
impl Debug for ProtocolMessage
Source§impl Default for ProtocolMessage
impl Default for ProtocolMessage
Source§fn default() -> ProtocolMessage
fn default() -> ProtocolMessage
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for ProtocolMessage
impl<'de> Deserialize<'de> for ProtocolMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Encoder<ProtocolMessage> for PingCodec
impl Encoder<ProtocolMessage> for PingCodec
Source§impl PartialEq for ProtocolMessage
impl PartialEq for ProtocolMessage
Source§impl Serialize for ProtocolMessage
impl Serialize for ProtocolMessage
Source§impl TryFrom<&ProtocolMessage> for Messages
impl TryFrom<&ProtocolMessage> for Messages
impl StructuralPartialEq for ProtocolMessage
Auto Trait Implementations§
impl Freeze for ProtocolMessage
impl RefUnwindSafe for ProtocolMessage
impl Send for ProtocolMessage
impl Sync for ProtocolMessage
impl Unpin for ProtocolMessage
impl UnwindSafe for ProtocolMessage
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