pub struct PacketCodec { /* private fields */ }Expand description
Frames and parses ECR17 packets for a given LrcMode.
Implementations§
Source§impl PacketCodec
impl PacketCodec
Sourcepub fn encode_application(&self, payload: &[u8]) -> Vec<u8> ⓘ
pub fn encode_application(&self, payload: &[u8]) -> Vec<u8> ⓘ
Encodes an application frame: STX + payload + ETX + LRC.
Sourcepub fn encode_control(&self, ctrl: u8) -> Vec<u8> ⓘ
pub fn encode_control(&self, ctrl: u8) -> Vec<u8> ⓘ
Encodes a control frame: ctrl + ETX + LRC, where the LRC is computed over the
single-byte payload [ctrl] under the configured LrcMode (so it folds
STX/ETX exactly as an application-frame LRC would).
Sourcepub fn decode(&self, data: &[u8]) -> DecodedPacket
pub fn decode(&self, data: &[u8]) -> DecodedPacket
Decodes exactly one frame from data.
ACK/NAK are recognized by their lead byte only: on the wire a control
frame is ctrl + ETX + LRC (what encode_control
produces and what the session frames), so [ACK, ETX, LRC] decodes to
PacketType::Ack. This leniency is required — the session hands decode the
full 3-byte control frame, and requiring a bare 1-byte ACK would make every
transaction’s ACK handshake fail. See docs/LESSON.md.
For STX/SOH frames the buffer must be exactly one frame: more than one frame,
trailing bytes after the LRC, a missing LRC, or a progress frame not terminated by
EOT all decode to PacketType::Unknown.
Trait Implementations§
Source§impl Clone for PacketCodec
impl Clone for PacketCodec
Source§fn clone(&self) -> PacketCodec
fn clone(&self) -> PacketCodec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more