Decode a packet from a payload.Non-streaming packet decoder. Accepts a byte array containing a single packet, and attempts to parse the packet and return the payload. @param packet byte array containing the input packet @return payload of the packet
(packet)
| 22 | |
| 23 | |
| 24 | def decode_packet(packet): |
| 25 | """ |
| 26 | Decode a packet from a payload.Non-streaming packet decoder. |
| 27 | Accepts a byte array containing a single packet, and attempts |
| 28 | to parse the packet and return the payload. |
| 29 | @param packet byte array containing the input packet |
| 30 | @return payload of the packet |
| 31 | """ |
| 32 | assert type(packet) is bytearray |
| 33 | |
| 34 | if len(packet) < 4: |
| 35 | raise makerbot_driver.errors.PacketLengthError(len(packet), 4) |
| 36 | |
| 37 | if packet[0] != makerbot_driver.constants.header: |
| 38 | raise makerbot_driver.errors.PacketHeaderError(packet[0], makerbot_driver.constants.header) |
| 39 | |
| 40 | if packet[1] != len(packet) - 3: |
| 41 | raise makerbot_driver.errors.PacketLengthFieldError(packet[1], len(packet) - 3) |
| 42 | |
| 43 | if packet[len(packet) - 1] != makerbot_driver.Encoder.CalculateCRC(packet[2:(len(packet) - 1)]): |
| 44 | raise makerbot_driver.errors.PacketCRCError(packet[len(packet) - 1], makerbot_driver.Encoder.CalculateCRC(packet[2:(len(packet) - 1)])) |
| 45 | |
| 46 | return packet[2:(len(packet) - 1)] |
| 47 | |
| 48 | |
| 49 | def check_response_code(response_code): |
nothing calls this directly
no outgoing calls
no test coverage detected