/// Extract the PDU length out of the ADU request buffer.
Extract the PDU length out of the ADU request buffer.
Extract the PDU length out of the ADU request buffer .
pub fn request_pdu_len(adu_buf: &[u8]) -> Result<Option<usize>> {
    if adu_buf.len() < 2 {
        return Ok(None);
    }
    let fn_code = adu_buf[1];
    let len = match fn_code {
        0x01..=0x06 => Some(5),
        0x07 | 0x0B | 0x0C | 0x11 => Some(1),
        0x0F | 0x10 => {
            if adu_buf.len() > 4 {
                Some(6 + adu_buf[4] as usize)
            } else {
                // incomplete frame
                None
            }
        }
        0x16 => Some(7),
        0x18 => Some(3),
        0x17 => {
            if adu_buf.len() > 10 {
                Some(10 + adu_buf[10] as usize)
            } else {
                // incomplete frame
                None
            }
        }
        _ => {
            return Err(Error::FnCode(fn_code));
        }
    };
    Ok(len)
}
pub fn request_pdu_len ( adu_buf : & [ u8 ] ) -> Result < Option < usize > > { if adu_buf . len ( ) < 2 { return Ok ( None ) ; } let fn_code = adu_buf [ 1 ] ; let len = match fn_code { 0x01 ..= 0x06 => Some ( 5 ) , 0x07 | 0x0B | 0x0C | 0x11 => Some ( 1 ) , 0x0F | 0x10 => { if adu_buf . len ( ) > 4 { Some ( 6 + adu_buf [ 4 ] as usize ) } else { // incomplete frame None } } 0x16 => Some ( 7 ) , 0x18 => Some ( 3 ) , 0x17 => { if adu_buf . len ( ) > 10 { Some ( 10 + adu_buf [ 10 ] as usize ) } else { // incomplete frame None } } _ => { return Err ( Error :: FnCode ( fn_code ) ) ; } } ; Ok ( len ) }
Extract the PDU length out of the ADU request buffer.
Extract the PDU length out of the ADU request buffer .
adu_buf
&[u8]