Reputation: 14974
I'm trying to send/receive data with an embedded device using a custom protocol. struct.pack() and unpack() seem like they'd do the job, but the fmt argument doesn't seem to be flexible enough to handle variable length arrays of data.
Example: device sends [event report] [number of events] ([event type] [event value], [event type] [event value], ...)
Where:
What would be the best way to decode this data into Python? Also, how would I encode similar data structures to send to the device?
Upvotes: 2
Views: 949
Reputation: 223
Consider using python-bitstring to implement binary protocols. It's quite flexible and easy to use.
Upvotes: 3