Function at4_protocol::messaging::parse_message[][src]

pub fn parse_message(bytes: &[u8]) -> Result<ReceivableMessage, &'static str>
Expand description

Parses a byte array into the relevant message.

Arguments

  • bytes - The byte array containing the TCP packet from your AT4.

Example usage

fn main() {
    use at4_protocol::messaging;
    use messaging::ReceivableMessage;

    let bytes = [
        0x55, 0x55, 0xb0, 0x80, 0x01, 0x2d, 0x00, 0x10, 0x40, 0x42, 0x1a, 0x00, 0x61, 0x80, 0x00,
        0x00, 0x01, 0x00, 0x1a, 0x00, 0x61, 0x80, 0xff, 0xfe, 0xca, 0xcb,
    ];

    let m = messaging::parse_message(&bytes);

    match m {
        Ok(m) => match m {
            ReceivableMessage::GroupStatuses(m) => {
                // Do whatever
            }
            ReceivableMessage::ACStatuses(m) => {
                // Some other function
            }
        },
        Err(e) => panic!("{}", e),
    }
}