Protocol Data Types

This page defines the fundamental data types used in the MariaDB client/server protocol, including integers, strings, and binary representations.

List of Possible Types

Unknown type:

Fixed-length bytes

Length-encoded bytes

End-of-file length bytes

Integer type:

Fixed-length integers

Length-encoded integers

String type:

Fixed-length strings

Null-terminated strings

Length-encoded strings

End-of-file length strings

Fixed-Length Bytes

The notation is byte<n>, where <n> is a positive integer. A fixed-length byte stores the value in a series of n bytes.

Length-Encoded Bytes

The notation is byte<lenenc>. Length-encoded bytes are prefixed by a length-encoded integer which describes the length of the byte value, followed by the bytes value.

End of File Length Bytes

The notation is byte<EOF>. Bytes whose length is calculated by the packet remaining length.

Fixed-Length Integers

Notation is int<n>, where <n> is a positive integer. A fixed-length integer stores the value in a series of n bytes. The least significant byte is always the first byte (little-endian format).

Example

An int<4> with value of 2 is stored as 02 00 00 00 .

Length-Encoded Integers

The notation is int<lenenc>. An integer which depending on its value is represented by n bytes.

The first byte represents the size of the integer, depending on the value of the first byte:

  • < 0xFB - Integer value is this a 1-byte integer

  • 0xFB - NULL value

  • 0xFC - Integer value is encoded in the next 2 bytes (3 bytes total)

  • 0xFD - Integer value is encoded in the next 3 bytes (4 bytes total)

  • 0xFE - Integer value is encoded in the next 8 bytes (9 bytes total)

Fixed-Length Strings

The notation is string<fix>. Fixed-length strings have a known hardcoded length.

Null-Terminated Strings

The notation is string<NUL>. Null-terminated strings have a variable size and are terminated by a 0x00 character.

Length-Encoded Strings

The notation is string<lenenc>. Length-encoded strings are prefixed by a length-encoded integer which describes the length of the string, followed by the string value.

Example

An string of 512 "a" is encoded in 515 bytes:

The NULL value is encoded using null (0xfb) length.

An empty value is encoded with a 0 (0x00) length.

End of File Length Strings

The notation is string<EOF>.

Strings whose length is calculated by the packet remaining length. For an example, see the COM_STMT_PREPARE packet.

This page is licensed: CC BY-SA / Gnu FDL

spinner

Last updated

Was this helpful?