MySQL 8.4.2
Source Code Documentation
Gcs_internal_message_header Class Reference

This header is internal to the MySQL GCS library and contains metadata information about the message content. More...

#include <gcs_internal_message_headers.h>

Public Member Functions

 Gcs_internal_message_header () noexcept=default
 Default constructor which is the only one provided. More...
 
 Gcs_internal_message_header (Gcs_internal_message_header &&) noexcept=default
 These constructors are to be used when move semantics may be needed. More...
 
Gcs_internal_message_headeroperator= (Gcs_internal_message_header &&) noexcept=default
 
 Gcs_internal_message_header (const Gcs_internal_message_header &) noexcept=default
 These constructors are to be used when copy semantics may be needed. More...
 
Gcs_internal_message_headeroperator= (const Gcs_internal_message_header &) noexcept=default
 
Gcs_protocol_version get_maximum_version () const
 
Gcs_protocol_version get_used_version () const
 
void set_maximum_version (Gcs_protocol_version version)
 Set the maximum protocol version. More...
 
void set_used_version (Gcs_protocol_version version)
 Set the current protocol version. More...
 
constexpr unsigned short get_fixed_header_length () const
 
Cargo_type get_cargo_type () const
 
void set_cargo_type (Cargo_type type)
 Set the cargo type field value. More...
 
unsigned int get_dynamic_headers_length () const
 
void set_dynamic_headers_length (unsigned int length)
 Set the dynamic headers length field value. More...
 
void set_payload_length (unsigned long long length)
 Set the message length attribute value according to the payload length and the header length. More...
 
unsigned long long get_total_length () const
 
unsigned long long decode (const unsigned char *buffer)
 Decode the contents of the buffer and sets the field values according to the values decoded. More...
 
unsigned long long encode (unsigned char *buffer) const
 Encode the contents of this instance into the buffer. More...
 
void dump (std::ostringstream &output) const
 Create a string representation of the fixed header to be logged. More...
 

Static Public Member Functions

static constexpr unsigned short calculate_length ()
 

Static Public Attributes

static constexpr unsigned short WIRE_USED_VERSION_SIZE = 2
 The used protocol version number length field. More...
 
static constexpr unsigned short WIRE_MAX_VERSION_SIZE = 2
 The maximum protocol version number length field. More...
 
static constexpr unsigned short WIRE_VERSION_SIZE = 4
 The length of the combined version fields. More...
 
static constexpr unsigned short WIRE_HD_LEN_SIZE = 2
 On-the-wire size of the fixed header length field. More...
 
static constexpr unsigned short WIRE_TOTAL_LEN_SIZE = 8
 On-the-wire size of the message size field. More...
 
static constexpr unsigned short WIRE_CARGO_TYPE_SIZE = 2
 On-the-wire size of the cargo type field. More...
 
static constexpr unsigned short WIRE_DYNAMIC_HDRS_LEN_SIZE = 4
 On-the-wire size of the dynamic headers length field. More...
 
static constexpr unsigned short WIRE_DYNAMIC_HDRS_LEN_OFFSET
 On-the-wire offset of the dynamic headers length field. More...
 
static constexpr unsigned short WIRE_MSG_LEN_OFFSET
 On-the-wire offset of the message length field. More...
 
static constexpr unsigned short WIRE_TOTAL_FIXED_HEADER_SIZE
 On-the-wire size of the fixed header. More...
 

Private Attributes

Gcs_protocol_version m_used_version {Gcs_protocol_version::UNKNOWN}
 The header instance used protocol version. More...
 
Gcs_protocol_version m_max_version {Gcs_protocol_version::UNKNOWN}
 The header instance maximum protocol version. More...
 
unsigned short m_fixed_header_len {WIRE_TOTAL_FIXED_HEADER_SIZE}
 The header instance length. More...
 
unsigned long long m_payload_len {0}
 The payload length field. More...
 
unsigned int m_dynamic_headers_len {0}
 The length of the dynamic headers. More...
 
Cargo_type m_cargo_type {Cargo_type::CT_UNKNOWN}
 The cargo type code. More...
 

Detailed Description

This header is internal to the MySQL GCS library and contains metadata information about the message content.

The on-the-wire representation of the fixed header is:

+---------------—+--------—+---------------------------------------—+ | field | wire size | description | +==================+===========+==========================================+ | used_version | 2 bytes | protocol version in use by sender | | max_version | 2 bytes | max protocol version supported by sender | | fixed_hdr_len | 2 bytes | length of the fixed header | | message_len | 8 bytes | length of the message | | dyn_hdr_len | 4 bytes | length of the dynamic headers | | cargo_type | 2 bytes | the cargo type in the payload | +---------------—+--------—+---------------------------------------—+

Be aware that previously there was a single 4-byte version field. Its semantics were the same of the used_version field.

Older nodes will continue to send messages that, from their point of view, contain the single version field. Older nodes only know protocol version 1. Messages sent by older nodes will be encoded as follows:

used_version = 1 and max_version = 0

This is due to two factors:

  1. The combined size of {used,max}_version is 4 bytes, which is the same size of the old version field.
  2. The fixed header is encoded in little endian. Therefore, the used_version (max_version) field will contain the least (most) significant 2 bytes of the old version field.

This class takes care of messages from old nodes by decoding such messages as:

   used_version = 1 and max_version = 1

Constructor & Destructor Documentation

◆ Gcs_internal_message_header() [1/3]

Gcs_internal_message_header::Gcs_internal_message_header ( )
explicitdefaultnoexcept

Default constructor which is the only one provided.

◆ Gcs_internal_message_header() [2/3]

Gcs_internal_message_header::Gcs_internal_message_header ( Gcs_internal_message_header &&  )
defaultnoexcept

These constructors are to be used when move semantics may be needed.

◆ Gcs_internal_message_header() [3/3]

Gcs_internal_message_header::Gcs_internal_message_header ( const Gcs_internal_message_header )
defaultnoexcept

These constructors are to be used when copy semantics may be needed.

Member Function Documentation

◆ calculate_length()

static constexpr unsigned short Gcs_internal_message_header::calculate_length ( )
inlinestaticconstexpr

◆ decode()

unsigned long long Gcs_internal_message_header::decode ( const unsigned char *  buffer)

Decode the contents of the buffer and sets the field values according to the values decoded.

The buffer MUST be encoded in little endian format.

Parameters
bufferThe buffer to decode from.
Returns
Length of decoded information in bytes.

◆ dump()

void Gcs_internal_message_header::dump ( std::ostringstream &  output) const

Create a string representation of the fixed header to be logged.

Parameters
outputReference to the output stream where the string will be created.

◆ encode()

unsigned long long Gcs_internal_message_header::encode ( unsigned char *  buffer) const

Encode the contents of this instance into the buffer.

The encoding SHALL be done in little endian format.

Parameters
bufferThe buffer to encode to.
Returns
Length of encoded information in bytes.

◆ get_cargo_type()

Cargo_type Gcs_internal_message_header::get_cargo_type ( ) const
Returns
the cargo type.

◆ get_dynamic_headers_length()

unsigned int Gcs_internal_message_header::get_dynamic_headers_length ( ) const
Returns
The dynamic headers length field value.

◆ get_fixed_header_length()

constexpr unsigned short Gcs_internal_message_header::get_fixed_header_length ( ) const
inlineconstexpr
Returns
the value of the header length field value.

◆ get_maximum_version()

Gcs_protocol_version Gcs_internal_message_header::get_maximum_version ( ) const
Returns
the value of the maximum protocol version field.

◆ get_total_length()

unsigned long long Gcs_internal_message_header::get_total_length ( ) const
Returns
The message total length field value.

◆ get_used_version()

Gcs_protocol_version Gcs_internal_message_header::get_used_version ( ) const
Returns
the value of the used protocol version field.

◆ operator=() [1/2]

Gcs_internal_message_header & Gcs_internal_message_header::operator= ( const Gcs_internal_message_header )
defaultnoexcept

◆ operator=() [2/2]

Gcs_internal_message_header & Gcs_internal_message_header::operator= ( Gcs_internal_message_header &&  )
defaultnoexcept

◆ set_cargo_type()

void Gcs_internal_message_header::set_cargo_type ( Cargo_type  type)

Set the cargo type field value.

Parameters
typeCargo type to set.

◆ set_dynamic_headers_length()

void Gcs_internal_message_header::set_dynamic_headers_length ( unsigned int  length)

Set the dynamic headers length field value.

Parameters
lengthThe dynamic headers value.

◆ set_maximum_version()

void Gcs_internal_message_header::set_maximum_version ( Gcs_protocol_version  version)

Set the maximum protocol version.

Parameters
versionMaximum protocol version.

◆ set_payload_length()

void Gcs_internal_message_header::set_payload_length ( unsigned long long  length)

Set the message length attribute value according to the payload length and the header length.

Only the payload information is provided because the header length is fixed.

Parameters
lengthPayload length.

◆ set_used_version()

void Gcs_internal_message_header::set_used_version ( Gcs_protocol_version  version)

Set the current protocol version.

Parameters
versionCurrent protocol version.

Member Data Documentation

◆ m_cargo_type

Cargo_type Gcs_internal_message_header::m_cargo_type {Cargo_type::CT_UNKNOWN}
private

The cargo type code.

◆ m_dynamic_headers_len

unsigned int Gcs_internal_message_header::m_dynamic_headers_len {0}
private

The length of the dynamic headers.

◆ m_fixed_header_len

unsigned short Gcs_internal_message_header::m_fixed_header_len {WIRE_TOTAL_FIXED_HEADER_SIZE}
private

The header instance length.

◆ m_max_version

Gcs_protocol_version Gcs_internal_message_header::m_max_version {Gcs_protocol_version::UNKNOWN}
private

The header instance maximum protocol version.

◆ m_payload_len

unsigned long long Gcs_internal_message_header::m_payload_len {0}
private

The payload length field.

Note that we keep track of the total length indirectly and the storage capacity is determined by the payload length which is the dominant factor.

◆ m_used_version

Gcs_protocol_version Gcs_internal_message_header::m_used_version {Gcs_protocol_version::UNKNOWN}
private

The header instance used protocol version.

◆ WIRE_CARGO_TYPE_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_CARGO_TYPE_SIZE = 2
staticconstexpr

On-the-wire size of the cargo type field.

◆ WIRE_DYNAMIC_HDRS_LEN_OFFSET

constexpr unsigned short Gcs_internal_message_header::WIRE_DYNAMIC_HDRS_LEN_OFFSET
staticconstexpr
Initial value:
=
static constexpr unsigned short WIRE_HD_LEN_SIZE
On-the-wire size of the fixed header length field.
Definition: gcs_internal_message_headers.h:202
static constexpr unsigned short WIRE_VERSION_SIZE
The length of the combined version fields.
Definition: gcs_internal_message_headers.h:194
static constexpr unsigned short WIRE_TOTAL_LEN_SIZE
On-the-wire size of the message size field.
Definition: gcs_internal_message_headers.h:207

On-the-wire offset of the dynamic headers length field.

◆ WIRE_DYNAMIC_HDRS_LEN_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_DYNAMIC_HDRS_LEN_SIZE = 4
staticconstexpr

On-the-wire size of the dynamic headers length field.

◆ WIRE_HD_LEN_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_HD_LEN_SIZE = 2
staticconstexpr

On-the-wire size of the fixed header length field.

◆ WIRE_MAX_VERSION_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_MAX_VERSION_SIZE = 2
staticconstexpr

The maximum protocol version number length field.

◆ WIRE_MSG_LEN_OFFSET

constexpr unsigned short Gcs_internal_message_header::WIRE_MSG_LEN_OFFSET
staticconstexpr
Initial value:

On-the-wire offset of the message length field.

◆ WIRE_TOTAL_FIXED_HEADER_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_TOTAL_FIXED_HEADER_SIZE
staticconstexpr
Initial value:
=
static constexpr unsigned short WIRE_DYNAMIC_HDRS_LEN_SIZE
On-the-wire size of the dynamic headers length field.
Definition: gcs_internal_message_headers.h:217
static constexpr unsigned short WIRE_CARGO_TYPE_SIZE
On-the-wire size of the cargo type field.
Definition: gcs_internal_message_headers.h:212

On-the-wire size of the fixed header.

◆ WIRE_TOTAL_LEN_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_TOTAL_LEN_SIZE = 8
staticconstexpr

On-the-wire size of the message size field.

◆ WIRE_USED_VERSION_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_USED_VERSION_SIZE = 2
staticconstexpr

The used protocol version number length field.

◆ WIRE_VERSION_SIZE

constexpr unsigned short Gcs_internal_message_header::WIRE_VERSION_SIZE = 4
staticconstexpr

The length of the combined version fields.


The documentation for this class was generated from the following files: