pub fn deserilize(mut rsp_data: &[u8]) -> MyResult<Message> {
        let mut msg_body = vec![];
        let (msg_type_raw, msg_id, h_data) = ProtocolHeader::read_from(&mut rsp_data)?;

        if msg_id == 0 {
            return Err(BlynkError::InvalidMessageId);
        }

        let msg_type =
            MessageType::try_from(msg_type_raw).map_err(|_e| BlynkError::InvalidMessageHeader)?;
        let mut size = None;
        let mut status = None;

        match msg_type {
            MessageType::Rsp | MessageType::Ping => {
                status = Some(ProtocolStatus::try_from(h_data).expect("Incorrect response status"));
            }
            MessageType::Hw
            | MessageType::Bridge
            | MessageType::Internal
            | MessageType::Redirect => {
                size = Some(h_data);
                let msg_body_raw = match String::from_utf8(rsp_data[..h_data.into()].to_vec()) {
                    Ok(msg_body_raw) => msg_body_raw,
                    Err(_) => return Err(BlynkError::InvalidMessageBody),
                };
                msg_body = msg_body_raw.split('\0').map(String::from).collect();
            }
            _ => panic!("Unknown message type {:?}", msg_type),
        }

        Ok(Message::new(
            msg_type,
            msg_id,
            size,
            status,
            msg_body.iter().map(|s| s as &str).collect(),
        ))
    }
/// Converts byte array into Message object or returns error
/// if it's not possible
Converts byte array into Message object or returns error
if it's not possible
Converts byte array into Message object or returns error if it ' s not possible
pub fn deserilize(mut rsp_data: &[u8]) -> MyResult<Message> {
        let mut msg_body = vec![];
        let (msg_type_raw, msg_id, h_data) = ProtocolHeader::read_from(&mut rsp_data)?;
        if msg_id == 0 {
            return Err(BlynkError::InvalidMessageId);
        }
        let msg_type =
            MessageType::try_from(msg_type_raw).map_err(|_e| BlynkError::InvalidMessageHeader)?;
        let mut size = None;
        let mut status = None;
        match msg_type {
            MessageType::Rsp | MessageType::Ping => {
                status = Some(ProtocolStatus::try_from(h_data).expect("Incorrect response status"));
            }
            MessageType::Hw
            | MessageType::Bridge
            | MessageType::Internal
            | MessageType::Redirect => {
                size = Some(h_data);
                let msg_body_raw = match String::from_utf8(rsp_data[..h_data.into()].to_vec()) {
                    Ok(msg_body_raw) => msg_body_raw,
                    Err(_) => return Err(BlynkError::InvalidMessageBody),
                };
                msg_body = msg_body_raw.split('\0').map(String::from).collect();
            }
            _ => panic!("Unknown message type {:?}", msg_type),
        }
        Ok(Message::new(
            msg_type,
            msg_id,
            size,
            status,
            msg_body.iter().map(|s| s as &str).collect(),
        ))
    }
pub fn deserilize ( mut rsp_data : & [ u8 ] ) -> MyResult < Message > { let mut msg_body = vec ! [ ] ; let ( msg_type_raw , msg_id , h_data ) = ProtocolHeader :: read_from ( & mut rsp_data ) ? ; if msg_id == 0 { return Err ( BlynkError :: InvalidMessageId ) ; } let msg_type = MessageType :: try_from ( msg_type_raw ) . map_err ( | _e | BlynkError :: InvalidMessageHeader ) ? ; let mut size = None ; let mut status = None ; match msg_type { MessageType :: Rsp | MessageType :: Ping => { status = Some ( ProtocolStatus :: try_from ( h_data ) . expect ( " " ) ) ; } MessageType :: Hw | MessageType :: Bridge | MessageType :: Internal | MessageType :: Redirect => { size = Some ( h_data ) ; let msg_body_raw = match String :: from_utf8 ( rsp_data [ .. h_data . into ( ) ] . to_vec ( ) ) { Ok ( msg_body_raw ) => msg_body_raw , Err ( _ ) => return Err ( BlynkError :: InvalidMessageBody ) , } ; msg_body = msg_body_raw . split ( '\0' ) . map ( String :: from ) . collect ( ) ; } _ => panic ! ( " " msg_type ) , } Ok ( Message :: new ( msg_type , msg_id , size , status , msg_body . iter ( ) . map ( | s | s as & str ) . collect ( ) , ) ) }
Converts byte array into Message object or returns error
if it's not possible
Converts byte array into Message object or returns error if it ' s not possible
rsp_data
&[u8]
rsp_data
&[u8]