Skip to main content

encode_adu

Function encode_adu 

Source
pub fn encode_adu(
    transaction_id: u16,
    unit_id: u8,
    pdu: &[u8],
) -> Result<Vec<u8>, EncodeError>
Expand description

Wrap a PDU in an MBAP header addressed back to the requester.

Refuses any PDU try_parse_adu would not accept back. Without the check a 254-byte PDU produced a length field of 255 — outside the 2..=254 the parser enforces — and past 65534 octets the (pdu.len() as u16) + 1 overflowed, which panics in every debug and test build and wrapped silently before [profile.release] overflow-checks was turned on.