@staticmethod<EOL><INDENT>def parse_msg(buf):<DEDENT>
<EOL>if <NUM_LIT> not in buf:<EOL><INDENT>return PARSE_RESULT.INCOMPLETE, [], None<EOL><DEDENT>buf = [ord(x) if not isinstance(x, int) else x for x in buf[list(buf).index(<NUM_LIT>):]]<EOL>try:<EOL><INDENT>data_len = (buf[<NUM_LIT:1>] << <NUM_LIT:8>) | buf[<NUM_LIT:2>]<EOL>opt_len = buf[<NUM_LIT:3>]<EOL><DEDENT>except IndexError:<EOL><INDENT>return PARSE_RESULT.INCOMPLETE, buf, None<EOL><DEDENT>msg_len = <NUM_LIT:6> + data_len + opt_len + <NUM_LIT:1><EOL>if len(buf) < msg_len:<EOL><INDENT>return PARSE_RESULT.INCOMPLETE, buf, None<EOL><DEDENT>msg = buf[<NUM_LIT:0>:msg_len]<EOL>buf = buf[msg_len:]<EOL>packet_type = msg[<NUM_LIT:4>]<EOL>data = msg[<NUM_LIT:6>:<NUM_LIT:6> + data_len]<EOL>opt_data = msg[<NUM_LIT:6> + data_len:<NUM_LIT:6> + data_len + opt_len]<EOL>if msg[<NUM_LIT:5>] != crc8.calc(msg[<NUM_LIT:1>:<NUM_LIT:5>]):<EOL><INDENT>Packet.logger.error('<STR_LIT>')<EOL>return PARSE_RESULT.CRC_MISMATCH, buf, None<EOL><DEDENT>if msg[<NUM_LIT:6> + data_len + opt_len] != crc8.calc(msg[<NUM_LIT:6>:<NUM_LIT:6> + data_len + opt_len]):<EOL><INDENT>Packet.logger.error('<STR_LIT>')<EOL>return PARSE_RESULT.CRC_MISMATCH, buf, None<EOL><DEDENT>if packet_type == PACKET.RADIO_ERP1:<EOL><INDENT>if data[<NUM_LIT:0>] == RORG.UTE:<EOL><INDENT>packet = UTETeachInPacket(packet_type, data, opt_data)<EOL><DEDENT>else:<EOL><INDENT>packet = RadioPacket(packet_type, data, opt_data)<EOL><DEDENT><DEDENT>elif packet_type == PACKET.RESPONSE:<EOL><INDENT>packet = ResponsePacket(packet_type, data, opt_data)<EOL><DEDENT>elif packet_type == PACKET.EVENT:<EOL><INDENT>packet = EventPacket(packet_type, data, opt_data)<EOL><DEDENT>else:<EOL><INDENT>packet = Packet(packet_type, data, opt_data)<EOL><DEDENT>return PARSE_RESULT.OK, buf, packet<EOL>
Parses message from buffer.
returns:
    - PARSE_RESULT
    - remaining buffer
    - Packet -object (if message was valid, else None)