pub fn response_pdu_len(adu_buf: &[u8]) -> Result<Option<usize>> {
    if adu_buf.len() < 8 {
        return Ok(None);
    }
    let fn_code = adu_buf[7];
    let len = match fn_code {
        0x01..=0x04 | 0x0C | 0x17 => {
            if adu_buf.len() > 8 {
                Some(2 + adu_buf[8] as usize)
            } else {
                // incomplete frame
                None
            }
        }
        0x05 | 0x06 | 0x0B | 0x0F | 0x10 => Some(5),
        0x07 => Some(2),
        0x16 => Some(7),
        0x18 => {
            if adu_buf.len() > 9 {
                Some(3 + BigEndian::read_u16(&adu_buf[8..=9]) as usize)
            } else {
                // incomplete frame
                None
            }
        }
        0x81..=0xAB => Some(2),
        _ => return Err(Error::FnCode(fn_code)),
    };
    Ok(len)
}
/// Extract the PDU length out of the ADU response buffer.
Extract the PDU length out of the ADU response buffer.
Extract the PDU length out of the ADU response buffer .
pub fn response_pdu_len(adu_buf: &[u8]) -> Result<Option<usize>> {
    if adu_buf.len() < 8 {
        return Ok(None);
    }
    let fn_code = adu_buf[7];
    let len = match fn_code {
        0x01..=0x04 | 0x0C | 0x17 => {
            if adu_buf.len() > 8 {
                Some(2 + adu_buf[8] as usize)
            } else {
                // incomplete frame
                None
            }
        }
        0x05 | 0x06 | 0x0B | 0x0F | 0x10 => Some(5),
        0x07 => Some(2),
        0x16 => Some(7),
        0x18 => {
            if adu_buf.len() > 9 {
                Some(3 + BigEndian::read_u16(&adu_buf[8..=9]) as usize)
            } else {
                // incomplete frame
                None
            }
        }
        0x81..=0xAB => Some(2),
        _ => return Err(Error::FnCode(fn_code)),
    };
    Ok(len)
}
pub fn response_pdu_len ( adu_buf : & [ u8 ] ) -> Result < Option < usize > > { if adu_buf . len ( ) < 8 { return Ok ( None ) ; } let fn_code = adu_buf [ 7 ] ; let len = match fn_code { 0x01 ..= 0x04 | 0x0C | 0x17 => { if adu_buf . len ( ) > 8 { Some ( 2 + adu_buf [ 8 ] as usize ) } else { // incomplete frame None } } 0x05 | 0x06 | 0x0B | 0x0F | 0x10 => Some ( 5 ) , 0x07 => Some ( 2 ) , 0x16 => Some ( 7 ) , 0x18 => { if adu_buf . len ( ) > 9 { Some ( 3 + BigEndian :: read_u16 ( & adu_buf [ 8 ..= 9 ] ) as usize ) } else { // incomplete frame None } } 0x81 ..= 0xAB => Some ( 2 ) , _ => return Err ( Error :: FnCode ( fn_code ) ) , } ; Ok ( len ) }
Extract the PDU length out of the ADU response buffer.
Extract the PDU length out of the ADU response buffer .
adu_buf
&[u8]
adu_buf
&[u8]