Decoding binary protocols in python
Decoding binary protocols like the MySQL Client/Server Protocol or MySQL's new X Protocol involves taking a sequence of bytes and turning them into integers.
In python the usually workhorse for this task is struct.unpack()
It takes a sequence of bytes and a format-string and returns a tuple of decoded values.
In the case of the MySQL Client/Server protocol the integers are (mostly) little-endian, unsigned and we can use:
format | description |
---|