MySQL 8.4.2
Source Code Documentation
Gcs_packet Class Reference

This class is an abstraction for the packet concept. More...

#include <gcs_internal_message.h>

Public Types

using buffer_ptr = std::unique_ptr< unsigned char, Gcs_packet_buffer_deleter >
 

Public Member Functions

 Gcs_packet () noexcept
 
 Gcs_packet (Gcs_packet &&packet) noexcept
 These constructors are to be used when move semantics may be needed. More...
 
Gcs_packetoperator= (Gcs_packet &&packet) noexcept
 
 Gcs_packet (const Gcs_packet &packet)=delete
 
Gcs_packetoperator= (const Gcs_packet &packet)=delete
 
Gcs_internal_message_header const & get_fixed_header () const
 Retrieve this packet's header. More...
 
std::vector< Gcs_dynamic_header > const & get_dynamic_headers () const
 Retrieve this packet's dynamic headers. More...
 
std::vector< std::unique_ptr< Gcs_stage_metadata > > const & get_stage_metadata () const
 Retrieve this packet's stage metadata. More...
 
std::size_t const & get_next_stage_index () const
 
void prepare_for_next_outgoing_stage ()
 
void prepare_for_next_incoming_stage ()
 
Gcs_dynamic_headerget_current_dynamic_header ()
 
Gcs_stage_metadataget_current_stage_header ()
 
unsigned char * get_payload_pointer ()
 
void set_payload_length (unsigned long long const &new_length)
 
Gcs_protocol_version get_maximum_version () const
 Return the value of the maximum supported version. More...
 
Gcs_protocol_version get_used_version () const
 Return the value of the version in use. More...
 
Cargo_type get_cargo_type () const
 Return the cargo type. More...
 
unsigned long long get_total_length () const
 Return the total length. More...
 
unsigned long long const & get_payload_length () const
 Return the payload length. More...
 
std::pair< buffer_ptr, unsigned long long > serialize ()
 Encode the packet content into its serialization buffer, and release ownership of the serialization buffer. More...
 
void dump (std::ostringstream &output) const
 Create a string representation of the packet to be logged. More...
 
Gcs_xcom_synode const & get_delivery_synode () const
 
Gcs_xcom_synode const & get_origin_synode () const
 

Static Public Member Functions

static std::pair< bool, Gcs_packetmake_outgoing_packet (Cargo_type const &cargo, Gcs_protocol_version const &current_version, std::vector< Gcs_dynamic_header > &&dynamic_headers, std::vector< std::unique_ptr< Gcs_stage_metadata > > &&stage_metadata, unsigned long long const &payload_size)
 This factory method is to be used when sending a packet. More...
 
static std::pair< bool, Gcs_packetmake_from_existing_packet (Gcs_packet const &original_packet, unsigned long long const &new_payload_size)
 This factory method is to be used when modifying a packet. More...
 
static Gcs_packet make_incoming_packet (buffer_ptr &&buffer, unsigned long long buffer_size, synode_no const &delivery_synode, synode_no const &origin_synode, Gcs_message_pipeline const &pipeline)
 This factory method is to be used when receiving a packet from the network. More...
 

Private Member Functions

 Gcs_packet (Cargo_type const &cargo, Gcs_protocol_version const &current_version, std::vector< Gcs_dynamic_header > &&dynamic_headers, std::vector< std::unique_ptr< Gcs_stage_metadata > > &&stage_metadata, unsigned long long const &payload_size)
 Constructor called by make_to_send. More...
 
 Gcs_packet (Gcs_packet const &original_packet, unsigned long long const &new_payload_size)
 Constructor called by make_from_existing_packet. More...
 
 Gcs_packet (synode_no const &delivery_synode, synode_no const &origin_synode)
 Constructor called by make_from_serialized_buffer. More...
 
bool allocate_serialization_buffer ()
 Allocates the underlying buffer where the packet will be serialized to using serialize. More...
 
void deserialize (buffer_ptr &&buffer, unsigned long long buffer_size, Gcs_message_pipeline const &pipeline)
 Decode the packet content from the given buffer containing a serialized packet. More...
 

Private Attributes

Gcs_internal_message_header m_fixed_header
 Fixed header which is common regardless whether the packet has been changed by a stage or not. More...
 
std::vector< Gcs_dynamic_headerm_dynamic_headers
 List of dynamic headers created by the stages by which the packet has passed through and changed it. More...
 
std::vector< std::unique_ptr< Gcs_stage_metadata > > m_stage_metadata
 List of stage metadata created by the stages by which the packet has passed through. More...
 
std::size_t m_next_stage_index {0}
 Index of the next stage to apply/revert in both m_dynamic_headers and m_stage_metadata. More...
 
buffer_ptr m_serialized_packet
 The buffer containing all serialized data for this packet. More...
 
unsigned long long m_serialized_packet_size {0}
 The capacity of the serialization buffer. More...
 
std::size_t m_serialized_payload_offset {0}
 The offset in m_serialized_packet where the application payload starts. More...
 
unsigned long long m_serialized_payload_size {0}
 The size of the serialized application payload in m_serialized_packet. More...
 
unsigned long long m_serialized_stage_metadata_size {0}
 The size of the serialized m_stage_metadata in m_serialized_packet. More...
 
Gcs_xcom_synode m_delivery_synode
 The XCom synode in which this packet was delivered. More...
 
Gcs_xcom_synode m_origin_synode
 The XCom synode in which this packet was delivered. More...
 

Detailed Description

This class is an abstraction for the packet concept.

It is used to manipulate the contents of a buffer that is to be sent to the network in an optimal way.

The on-the-wire layout looks like this:

+-----------—+--------------—+-------------—+--------—+ | fixed header | dynamic headers | stage metadata | payload | +-----------—+--------------—+-------------—+--------—+

Member Typedef Documentation

◆ buffer_ptr

using Gcs_packet::buffer_ptr = std::unique_ptr<unsigned char, Gcs_packet_buffer_deleter>

Constructor & Destructor Documentation

◆ Gcs_packet() [1/6]

Gcs_packet::Gcs_packet ( )
noexcept

◆ Gcs_packet() [2/6]

Gcs_packet::Gcs_packet ( Gcs_packet &&  packet)
noexcept

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

◆ Gcs_packet() [3/6]

Gcs_packet::Gcs_packet ( const Gcs_packet packet)
delete

◆ Gcs_packet() [4/6]

Gcs_packet::Gcs_packet ( Cargo_type const &  cargo,
Gcs_protocol_version const &  current_version,
std::vector< Gcs_dynamic_header > &&  dynamic_headers,
std::vector< std::unique_ptr< Gcs_stage_metadata > > &&  stage_metadata,
unsigned long long const &  payload_size 
)
explicitprivate

Constructor called by make_to_send.

Parameters
cargoThe message type
current_versionThe pipeline version
dynamic_headersThe dynamic headers of the stages the packet will go through
stage_metadataThe stage metadata of the stages the packet will go through
payload_sizeThe payload size

◆ Gcs_packet() [5/6]

Gcs_packet::Gcs_packet ( Gcs_packet const &  original_packet,
unsigned long long const &  new_payload_size 
)
explicitprivate

Constructor called by make_from_existing_packet.

Parameters
original_packetThe packet to "clone"
new_payload_sizeThe payload size of this packet

◆ Gcs_packet() [6/6]

Gcs_packet::Gcs_packet ( synode_no const &  delivery_synode,
synode_no const &  origin_synode 
)
explicitprivate

Constructor called by make_from_serialized_buffer.

Parameters
delivery_synodeThe XCom synode where the packet was decided on
origin_synodeThe XCom synode that identifieis the origin of this packet

Member Function Documentation

◆ allocate_serialization_buffer()

bool Gcs_packet::allocate_serialization_buffer ( )
private

Allocates the underlying buffer where the packet will be serialized to using serialize.

Returns
true if the required buffer could not be allocated, false otherwise

◆ deserialize()

void Gcs_packet::deserialize ( buffer_ptr &&  buffer,
unsigned long long  buffer_size,
Gcs_message_pipeline const &  pipeline 
)
private

Decode the packet content from the given buffer containing a serialized packet.

Parameters
bufferBuffer containing a serialized packet
buffer_sizeSize of the buffer
pipelineThe message pipeline

◆ dump()

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

Create a string representation of the packet to be logged.

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

◆ get_cargo_type()

Cargo_type Gcs_packet::get_cargo_type ( ) const

Return the cargo type.

◆ get_current_dynamic_header()

Gcs_dynamic_header & Gcs_packet::get_current_dynamic_header ( )

◆ get_current_stage_header()

Gcs_stage_metadata & Gcs_packet::get_current_stage_header ( )

◆ get_delivery_synode()

Gcs_xcom_synode const & Gcs_packet::get_delivery_synode ( ) const

◆ get_dynamic_headers()

std::vector< Gcs_dynamic_header > const & Gcs_packet::get_dynamic_headers ( ) const

Retrieve this packet's dynamic headers.

Returns
The packet's dynamic headers

◆ get_fixed_header()

Gcs_internal_message_header const & Gcs_packet::get_fixed_header ( ) const

Retrieve this packet's header.

Returns
The packet's header

◆ get_maximum_version()

Gcs_protocol_version Gcs_packet::get_maximum_version ( ) const

Return the value of the maximum supported version.

◆ get_next_stage_index()

std::size_t const & Gcs_packet::get_next_stage_index ( ) const

◆ get_origin_synode()

Gcs_xcom_synode const & Gcs_packet::get_origin_synode ( ) const

◆ get_payload_length()

unsigned long long const & Gcs_packet::get_payload_length ( ) const

Return the payload length.

◆ get_payload_pointer()

unsigned char * Gcs_packet::get_payload_pointer ( )

◆ get_stage_metadata()

std::vector< std::unique_ptr< Gcs_stage_metadata > > const & Gcs_packet::get_stage_metadata ( ) const

Retrieve this packet's stage metadata.

Returns
The packet's stage metadata

◆ get_total_length()

unsigned long long Gcs_packet::get_total_length ( ) const

Return the total length.

◆ get_used_version()

Gcs_protocol_version Gcs_packet::get_used_version ( ) const

Return the value of the version in use.

◆ make_from_existing_packet()

std::pair< bool, Gcs_packet > Gcs_packet::make_from_existing_packet ( Gcs_packet const &  original_packet,
unsigned long long const &  new_payload_size 
)
static

This factory method is to be used when modifying a packet.

This builds a packet with all the same headers, metadata, and state of original_packet.

It is used, for example, by:

  • The compression stage of the pipeline, to derive the compressed packet from the original, uncompressed packet.
  • The fragmentation stage of the pipeline, to derive the fragments from the original packet.
Parameters
original_packetThe packet to "clone"
new_payload_sizeThe payload size of this packet
Return values
{true,Gcs_packet}If packet is created successfully
{false,_}If memory could not be allocated

◆ make_incoming_packet()

Gcs_packet Gcs_packet::make_incoming_packet ( buffer_ptr &&  buffer,
unsigned long long  buffer_size,
synode_no const &  delivery_synode,
synode_no const &  origin_synode,
Gcs_message_pipeline const &  pipeline 
)
static

This factory method is to be used when receiving a packet from the network.

Parameters
bufferBuffer with a serialized packet
buffer_sizeSize of the buffer
delivery_synodeThe XCom synode where the packet was decided on
origin_synodeThe XCom synode that identifies the origin of the packet
pipelineThe message pipeline
Returns
A packet initialized from the buffer

◆ make_outgoing_packet()

std::pair< bool, Gcs_packet > Gcs_packet::make_outgoing_packet ( Cargo_type const &  cargo,
Gcs_protocol_version const &  current_version,
std::vector< Gcs_dynamic_header > &&  dynamic_headers,
std::vector< std::unique_ptr< Gcs_stage_metadata > > &&  stage_metadata,
unsigned long long const &  payload_size 
)
static

This factory method is to be used when sending a packet.

Parameters
cargoThe message type
current_versionThe pipeline version
dynamic_headersThe dynamic headers of the stages the packet will go through
stage_metadataThe stage metadata of the stages the packet will go through
payload_sizeThe payload size
Return values
{true,Gcs_packet}If packet is created successfully
{false,_}If memory could not be allocated

◆ operator=() [1/2]

Gcs_packet & Gcs_packet::operator= ( const Gcs_packet packet)
delete

◆ operator=() [2/2]

Gcs_packet & Gcs_packet::operator= ( Gcs_packet &&  packet)
noexcept

◆ prepare_for_next_incoming_stage()

void Gcs_packet::prepare_for_next_incoming_stage ( )

◆ prepare_for_next_outgoing_stage()

void Gcs_packet::prepare_for_next_outgoing_stage ( )

◆ serialize()

std::pair< Gcs_packet::buffer_ptr, unsigned long long > Gcs_packet::serialize ( )

Encode the packet content into its serialization buffer, and release ownership of the serialization buffer.

This method must only be called on a valid packet, i.e. a packet for which allocate_serialization_buffer was called and returned true.

Return values
{buffer,buffer_size}The buffer with the serialized packet, and its size

◆ set_payload_length()

void Gcs_packet::set_payload_length ( unsigned long long const &  new_length)

Member Data Documentation

◆ m_delivery_synode

Gcs_xcom_synode Gcs_packet::m_delivery_synode
private

The XCom synode in which this packet was delivered.

◆ m_dynamic_headers

std::vector<Gcs_dynamic_header> Gcs_packet::m_dynamic_headers
private

List of dynamic headers created by the stages by which the packet has passed through and changed it.

◆ m_fixed_header

Gcs_internal_message_header Gcs_packet::m_fixed_header
private

Fixed header which is common regardless whether the packet has been changed by a stage or not.

◆ m_next_stage_index

std::size_t Gcs_packet::m_next_stage_index {0}
private

Index of the next stage to apply/revert in both m_dynamic_headers and m_stage_metadata.

◆ m_origin_synode

Gcs_xcom_synode Gcs_packet::m_origin_synode
private

The XCom synode in which this packet was delivered.

◆ m_serialized_packet

buffer_ptr Gcs_packet::m_serialized_packet
private

The buffer containing all serialized data for this packet.

◆ m_serialized_packet_size

unsigned long long Gcs_packet::m_serialized_packet_size {0}
private

The capacity of the serialization buffer.

◆ m_serialized_payload_offset

std::size_t Gcs_packet::m_serialized_payload_offset {0}
private

The offset in m_serialized_packet where the application payload starts.

◆ m_serialized_payload_size

unsigned long long Gcs_packet::m_serialized_payload_size {0}
private

The size of the serialized application payload in m_serialized_packet.

◆ m_serialized_stage_metadata_size

unsigned long long Gcs_packet::m_serialized_stage_metadata_size {0}
private

The size of the serialized m_stage_metadata in m_serialized_packet.

◆ m_stage_metadata

std::vector<std::unique_ptr<Gcs_stage_metadata> > Gcs_packet::m_stage_metadata
private

List of stage metadata created by the stages by which the packet has passed through.

This list always has the same length as m_dynamic_headers, and the following holds:

For every i, m_stage_metadata[i] and m_dynamic_headers[i] correspond to the same stage.


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