MySQL 8.0.40
Source Code Documentation
|
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_packet & | operator= (Gcs_packet &&packet) noexcept |
Gcs_packet (const Gcs_packet &packet)=delete | |
Gcs_packet & | operator= (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_header & | get_current_dynamic_header () |
Gcs_stage_metadata & | get_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_packet > | make_outgoing_packet (Cargo_type const &cargo, Gcs_protocol_version const ¤t_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_packet > | make_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 ¤t_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_header > | m_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... | |
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 | +-----------—+--------------—+-------------—+--------—+
using Gcs_packet::buffer_ptr = std::unique_ptr<unsigned char, Gcs_packet_buffer_deleter> |
|
noexcept |
|
noexcept |
These constructors are to be used when move semantics may be needed.
|
delete |
|
explicitprivate |
Constructor called by make_to_send
.
cargo | The message type |
current_version | The pipeline version |
dynamic_headers | The dynamic headers of the stages the packet will go through |
stage_metadata | The stage metadata of the stages the packet will go through |
payload_size | The payload size |
|
explicitprivate |
Constructor called by make_from_existing_packet
.
original_packet | The packet to "clone" |
new_payload_size | The payload size of this packet |
|
explicitprivate |
Constructor called by make_from_serialized_buffer
.
delivery_synode | The XCom synode where the packet was decided on |
origin_synode | The XCom synode that identifieis the origin of this packet |
|
private |
Allocates the underlying buffer where the packet will be serialized to using serialize
.
|
private |
Decode the packet content from the given buffer containing a serialized packet.
buffer | Buffer containing a serialized packet |
buffer_size | Size of the buffer |
pipeline | The message pipeline |
void Gcs_packet::dump | ( | std::ostringstream & | output | ) | const |
Create a string representation of the packet to be logged.
output | Reference to the output stream where the string will be created. |
Cargo_type Gcs_packet::get_cargo_type | ( | ) | const |
Return the cargo type.
Gcs_dynamic_header & Gcs_packet::get_current_dynamic_header | ( | ) |
Gcs_stage_metadata & Gcs_packet::get_current_stage_header | ( | ) |
Gcs_xcom_synode const & Gcs_packet::get_delivery_synode | ( | ) | const |
std::vector< Gcs_dynamic_header > const & Gcs_packet::get_dynamic_headers | ( | ) | const |
Retrieve this packet's dynamic headers.
Gcs_internal_message_header const & Gcs_packet::get_fixed_header | ( | ) | const |
Retrieve this packet's header.
Gcs_protocol_version Gcs_packet::get_maximum_version | ( | ) | const |
Return the value of the maximum supported version.
std::size_t const & Gcs_packet::get_next_stage_index | ( | ) | const |
Gcs_xcom_synode const & Gcs_packet::get_origin_synode | ( | ) | const |
unsigned long long const & Gcs_packet::get_payload_length | ( | ) | const |
Return the payload length.
unsigned char * Gcs_packet::get_payload_pointer | ( | ) |
std::vector< std::unique_ptr< Gcs_stage_metadata > > const & Gcs_packet::get_stage_metadata | ( | ) | const |
Retrieve this packet's stage metadata.
unsigned long long Gcs_packet::get_total_length | ( | ) | const |
Return the total length.
Gcs_protocol_version Gcs_packet::get_used_version | ( | ) | const |
Return the value of the version in use.
|
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:
original_packet | The packet to "clone" |
new_payload_size | The payload size of this packet |
{true,Gcs_packet} | If packet is created successfully |
{false,_} | If memory could not be allocated |
|
static |
This factory method is to be used when receiving a packet from the network.
buffer | Buffer with a serialized packet |
buffer_size | Size of the buffer |
delivery_synode | The XCom synode where the packet was decided on |
origin_synode | The XCom synode that identifies the origin of the packet |
pipeline | The message pipeline |
|
static |
This factory method is to be used when sending a packet.
cargo | The message type |
current_version | The pipeline version |
dynamic_headers | The dynamic headers of the stages the packet will go through |
stage_metadata | The stage metadata of the stages the packet will go through |
payload_size | The payload size |
{true,Gcs_packet} | If packet is created successfully |
{false,_} | If memory could not be allocated |
|
delete |
|
noexcept |
void Gcs_packet::prepare_for_next_incoming_stage | ( | ) |
void Gcs_packet::prepare_for_next_outgoing_stage | ( | ) |
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.
{buffer,buffer_size} | The buffer with the serialized packet, and its size |
void Gcs_packet::set_payload_length | ( | unsigned long long const & | new_length | ) |
|
private |
The XCom synode in which this packet was delivered.
|
private |
List of dynamic headers created by the stages by which the packet has passed through and changed it.
|
private |
Fixed header which is common regardless whether the packet has been changed by a stage or not.
|
private |
Index of the next stage to apply/revert in both m_dynamic_headers and m_stage_metadata.
|
private |
The XCom synode in which this packet was delivered.
|
private |
The buffer containing all serialized data for this packet.
|
private |
The capacity of the serialization buffer.
|
private |
The offset in m_serialized_packet where the application payload starts.
|
private |
The size of the serialized application payload in m_serialized_packet.
|
private |
The size of the serialized m_stage_metadata in m_serialized_packet.
|
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.