MySQL 8.0.40
Source Code Documentation
|
The MySQL Protocol has a set of possible encodings for integers.
A fixed-length unsigned integer stores its value in a series of bytes with the least significant byte first.
The MySQL uses the following fixed-length unsigned integer variants:
See int3store() for an example.
An integer that consumes 1, 3, 4, or 9 bytes, depending on its numeric value
To convert a number value into a length-encoded integer:
Greater or equal | Lower than | Stored as |
---|---|---|
0 | 251 | 1-byte integer |
251 | 216 | 0xFC + 2-byte integer |
216 | 224 | 0xFD + 3-byte integer |
224 | 264 | 0xFE + 8-byte integer |
Similarly, to convert a length-encoded integer into its numeric value check the first byte.
0xFE
, you must check the length of the packet to verify that it has enough space for a 8-byte integer. If not, it may be an EOF_Packet instead.