The MySQL Protocol has a set of possible encodings for integers:
fixed length intergers
length encoded integers
A integer than consumes 1, 3, 4 or 9 bytes depending on its numeric valuer
To convert a number value into a length-encoded integer:
If the value is < 251, it is stored as a 1-byte integer.
If the value is ≥ 251 and < (2^16), it is
If the value is ≥ (2^16) and < (2^24), it is
If the value is ≥ (2^24) and < (2^64) it is
Up to MySQL 3.22,
0xfe was followed
by a 4-byte integer.
To convert a length-encoded integer into its numeric value, check the first byte:
If it is < 0xfb, treat it as a 1-byte integer.
If it is 0xfc, it is followed by a 2-byte integer.
If it is 0xfd, it is followed by a 3-byte integer.
If it is 0xfe, it is followed by a 8-byte integer.
If the first byte of a packet is a length-encoded
integer and its byte value is
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 a
Depending on the context, the first byte may also have other meanings:
0xff as 1st byte of length-encoded integers is undefined.
fa -- 250 fc fb 00 -- 251