MySQL 8.4.0
Source Code Documentation
mysql::serialization::Serializer< Serializer_derived_type, Archive_type > Class Template Reference

Interface for serializer. More...

#include <serializer.h>

Public Types

using Serializer_current_type = Serializer< Serializer_derived_type, Archive_type >
 

Public Member Functions

bool is_error () const
 
bool is_good () const
 
const Serialization_errorget_error ()
 
template<typename T >
Serializer_current_typeoperator<< (const T &arg)
 Function for the API user to serialize data. More...
 
template<typename T >
Serializer_current_typeoperator>> (T &arg)
 Function for the API user to serialize data. More...
 
Archive_type & get_archive ()
 Function for the API user to access reference of the archive. More...
 
template<typename T >
Serializer< Serializer_derived_type, Archive_type > & operator<< (const T &arg)
 
template<typename T >
Serializer< Serializer_derived_type, Archive_type > & operator>> (T &arg)
 

Static Public Member Functions

template<typename T >
static std::size_t get_size (const T &arg)
 

Protected Member Functions

Serializer_derived_type * get_derived ()
 Casts this to derived type. More...
 
template<class Field_type , Field_size field_size_defined>
void encode_field (Level_type level, Field_id_type field_id, const Field_definition< Field_type, field_size_defined > &field_definition)
 Function used to encode one field. More...
 
template<class Field_type , Field_size field_size_defined>
void decode_field (Level_type level, Field_id_type field_id, std::size_t serializable_end_pos, Field_definition< Field_type, field_size_defined > &field_definition)
 Function used to decode one field. More...
 
template<class Serializable_type >
void encode_serializable (Level_type level, Field_id_type field_id, const Serializable_type &serializable, bool skip_id)
 Function used to encode serializable field, this function saves serializable metadata and calls serializable encode method. More...
 
template<class Serializable_type >
void encode_serializable_fields (const Serializable_type &serializable, Level_type level)
 Function used to encode fields of specializations of Serializable class, iterates over constant fields allowing them to be saved into an archive. More...
 
template<class Serializable_type >
void decode_serializable (Level_type level, Field_id_type field_id, std::size_t serializable_end_pos, Serializable_type &serializable, bool skip_id)
 Function used to decode serializable field, this function loads serializable metadata and calls serializable decode method. More...
 
template<class Serializable_type >
void decode_serializable_fields (Serializable_type &serializable, Level_type level, std::size_t serializable_end_pos)
 Function used to decode fields of specializations of Serializable class, iterates over non constant fields, allowing them to be filled with data from an archive. More...
 
void clear_error ()
 
virtual ~Serializer ()=default
 Destructor. More...
 

Static Protected Member Functions

template<class Field_type , Field_size field_size_defined>
static std::size_t get_size_field_def (Field_id_type field_id, const Field_definition< Field_type, field_size_defined > &field_definition)
 Function returns size of field object written to an archive. More...
 
template<class Serializable_concrete_type >
static std::size_t get_size_serializable (Field_id_type field_id, const Serializable_concrete_type &serializable, bool skip_id=false)
 Function returns size of serializable object written to an archive. More...
 
template<class Field_type , Field_size field_size_defined>
static constexpr std::size_t get_max_size ()
 Function returns maximum size of the field written to an archive, based on its type. More...
 
template<class Serializable_concrete_type >
static constexpr std::size_t get_max_size ()
 Function returns maximum size of the Serializable_concrete_type class object data written to an archive, based on its type. More...
 

Protected Attributes

Level_type m_level {0}
 Level of the serializable tree. More...
 
Archive_type m_archive
 Archive that stores the data. More...
 
Serialization_error m_error
 Holds information about error. More...
 

Friends

template<typename Serializable_derived_current_type >
class Serializable
 
template<typename Serializer_type , typename Type >
struct Serializable_size_calculator_helper
 

Detailed Description

template<class Serializer_derived_type, class Archive_type>
class mysql::serialization::Serializer< Serializer_derived_type, Archive_type >

Interface for serializer.

This class provides functionality of encoder and decoder, storing the formatted data in the defined Archive_type. This class converts a hierarchical message (Serializable type) into a linear sequence of message boundaries and fields (with the usage of Serializable interface). To do so, it traverses the message in depth-first order and applies the user-defined predicates to determine if a field should be included in encoded message or not. Field ids are generated during iteration over fields with the usage of the Serializable interface. Particular message boundaries formatting and fields formatting is decided by the Serializer_derived_type. The methods that Serializer_derived_type shall provide are explicitly marked in methods documentation as "to be implemented by Serializer_derived_type". Derived class shall provide a specific formatting of message boundaries, specific formatting of particular fields and size calculation methods (get_size_serializable, get_size_field_def, get_max_size for simple/complex fields)

Template Parameters
Serializer_derived_typeConcrete Serializer type, this is CRTP
Archive_typeConcrete archive type to store data

Member Typedef Documentation

◆ Serializer_current_type

template<class Serializer_derived_type , class Archive_type >
using mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::Serializer_current_type = Serializer<Serializer_derived_type, Archive_type>

Constructor & Destructor Documentation

◆ ~Serializer()

template<class Serializer_derived_type , class Archive_type >
virtual mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::~Serializer ( )
protectedvirtualdefault

Destructor.

Note
Cannot create an object of Serializer interface

Member Function Documentation

◆ clear_error()

template<class Serializer_derived_type , class Archive_type >
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::clear_error ( )
inlineprotected

◆ decode_field()

template<class Serializer_derived_type , class Archive_type >
template<class Field_type , Field_size field_size_defined>
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::decode_field ( Level_type  level,
Field_id_type  field_id,
std::size_t  serializable_end_pos,
Field_definition< Field_type, field_size_defined > &  field_definition 
)
protected

Function used to decode one field.

Template Parameters
Field_typeType of field
field_size_definedDefined field size in archive
Parameters
[in]levelLevel of the serializable tree, may be ignored, used mainly for text formatting
[in]field_idExpected field id
[in]serializable_end_posEnd position of current serializable type
[in]field_definitionDefinition of the field
Note
To be implemented in Serializer_derived_type

◆ decode_serializable()

template<class Serializer_derived_type , class Archive_type >
template<class Serializable_type >
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::decode_serializable ( Level_type  level,
Field_id_type  field_id,
std::size_t  serializable_end_pos,
Serializable_type &  serializable,
bool  skip_id 
)
protected

Function used to decode serializable field, this function loads serializable metadata and calls serializable decode method.

Template Parameters
Serializable_typeserializable data type
Parameters
[in]levelLevel of the serializable tree, may be ignored, used mainly for text formatting
[in]field_idField id
[in]serializable_end_posEnd position of current serializable type
[in]serializableSerializable object universal reference
[in]skip_idSkip decoding of serializable id. In case a field is placed in a container, we skip encoding / decoding of the field id. Field id encoding / decoding is skipped in case field_id was already processed or a complex type is put in the container

◆ decode_serializable_fields()

template<class Serializer_derived_type , class Archive_type >
template<class Serializable_type >
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::decode_serializable_fields ( Serializable_type &  serializable,
Level_type  level,
std::size_t  serializable_end_pos 
)
protected

Function used to decode fields of specializations of Serializable class, iterates over non constant fields, allowing them to be filled with data from an archive.

Template Parameters
Serializable_typeserializable data type
Parameters
[in]serializableSerializable object universal reference
[in]levelSerializable tree level, serializable may contain other serializable fields, level is used for informational purpose or additional text formatting for nested types
[in]serializable_end_posEnd position of current serializable type

◆ encode_field()

template<class Serializer_derived_type , class Archive_type >
template<class Field_type , Field_size field_size_defined>
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::encode_field ( Level_type  level,
Field_id_type  field_id,
const Field_definition< Field_type, field_size_defined > &  field_definition 
)
protected

Function used to encode one field.

Template Parameters
Field_typeType of field
field_size_definedDefined field size in archive
Parameters
[in]levelLevel of the serializable tree, may be ignored, used mainly for text formatting
[in]field_idField id
[in]field_definitionDefinition of the field
Note
To be implemented in Serializer_derived_type

◆ encode_serializable()

template<class Serializer_derived_type , class Archive_type >
template<class Serializable_type >
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::encode_serializable ( Level_type  level,
Field_id_type  field_id,
const Serializable_type &  serializable,
bool  skip_id 
)
protected

Function used to encode serializable field, this function saves serializable metadata and calls serializable encode method.

Template Parameters
Serializable_typeserializable data type
Parameters
[in]levelLevel of the serializable tree, may be ignored, used mainly for text formatting
[in]field_idField id
[in]serializableSerializable object universal reference
[in]skip_idSkip encoding of serializable id (for repeated fields)
Note
To be implemented in Serializer_derived_type

◆ encode_serializable_fields()

template<class Serializer_derived_type , class Archive_type >
template<class Serializable_type >
void mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::encode_serializable_fields ( const Serializable_type &  serializable,
Level_type  level 
)
protected

Function used to encode fields of specializations of Serializable class, iterates over constant fields allowing them to be saved into an archive.

Template Parameters
Serializable_typeserializable data type
Parameters
[in]serializableSerializable object universal reference
[in]levelSerializable tree level, serializable may contain other serializable fields, level is used for informational purpose or additional text formatting for nested types
Note
To be implemented in Serializer_derived_type

◆ get_archive()

template<class Serializer_derived_type , class Archive_type >
Archive_type & mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_archive

Function for the API user to access reference of the archive.

Returns
Reference to the archive object

◆ get_derived()

template<class Serializer_derived_type , class Archive_type >
Serializer_derived_type * mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_derived ( )
inlineprotected

Casts this to derived type.

Returns
Derived class pointer to this
Note
To be implemented in Archive_derived_type

◆ get_error()

template<class Serializer_derived_type , class Archive_type >
const Serialization_error & mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_error ( )
inline

◆ get_max_size() [1/2]

template<class Serializer_derived_type , class Archive_type >
template<class Field_type , Field_size field_size_defined>
static constexpr std::size_t mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_max_size ( )
inlinestaticconstexprprotected

Function returns maximum size of the field written to an archive, based on its type.

Template Parameters
Field_typeType of field
field_size_definedDefined field size in archive

◆ get_max_size() [2/2]

template<class Serializer_derived_type , class Archive_type >
template<class Serializable_concrete_type >
static constexpr std::size_t mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_max_size ( )
inlinestaticconstexprprotected

Function returns maximum size of the Serializable_concrete_type class object data written to an archive, based on its type.

Template Parameters
Serializable_concrete_typeType of serializable obj

◆ get_size()

template<class Serializer_derived_type , class Archive_type >
template<typename T >
std::size_t mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_size ( const T &  arg)
static

◆ get_size_field_def()

template<class Serializer_derived_type , class Archive_type >
template<class Field_type , Field_size field_size_defined>
std::size_t mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_size_field_def ( Field_id_type  field_id,
const Field_definition< Field_type, field_size_defined > &  field_definition 
)
staticprotected

Function returns size of field object written to an archive.

Template Parameters
Field_typeType of field
field_size_definedDefined field size in archive
Parameters
[in]field_idField id
[in]field_definitionDefinition of the field
Note
To be implemented in Serializer_derived_type

◆ get_size_serializable()

template<class Serializer_derived_type , class Archive_type >
template<class Serializable_concrete_type >
std::size_t mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::get_size_serializable ( Field_id_type  field_id,
const Serializable_concrete_type &  serializable,
bool  skip_id = false 
)
staticprotected

Function returns size of serializable object written to an archive.

Template Parameters
Serializable_concrete_typeType of serializable obj
Parameters
[in]field_idField id
[in]serializableSerializable universal reference for which size will be calculated
[in]skip_idSkip serializable id (for repeated fields)
Note
To be implemented in Serializer_derived_type

◆ is_error()

template<class Serializer_derived_type , class Archive_type >
bool mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::is_error ( ) const
inline

◆ is_good()

template<class Serializer_derived_type , class Archive_type >
bool mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::is_good ( ) const
inline

◆ operator<<() [1/2]

template<class Serializer_derived_type , class Archive_type >
template<typename T >
Serializer_current_type & mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::operator<< ( const T &  arg)

Function for the API user to serialize data.

Template Parameters
TSerialized type, implementing Serializable interface
Parameters
[in]argData to be written into the archive
Returns
Updated object for chaining

◆ operator<<() [2/2]

template<class Serializer_derived_type , class Archive_type >
template<typename T >
Serializer< Serializer_derived_type, Archive_type > & mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::operator<< ( const T &  arg)

◆ operator>>() [1/2]

template<class Serializer_derived_type , class Archive_type >
template<typename T >
Serializer_current_type & mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::operator>> ( T &  arg)

Function for the API user to serialize data.

Template Parameters
TSerialized type, implementing Serializable interface
Parameters
[in]argDeserialized data will be stored in arg
Returns
Updated object for chaining

◆ operator>>() [2/2]

template<class Serializer_derived_type , class Archive_type >
template<typename T >
Serializer< Serializer_derived_type, Archive_type > & mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::operator>> ( T &  arg)

Friends And Related Function Documentation

◆ Serializable

template<class Serializer_derived_type , class Archive_type >
template<typename Serializable_derived_current_type >
friend class Serializable
friend

◆ Serializable_size_calculator_helper

template<class Serializer_derived_type , class Archive_type >
template<typename Serializer_type , typename Type >
friend struct Serializable_size_calculator_helper
friend

Member Data Documentation

◆ m_archive

template<class Serializer_derived_type , class Archive_type >
Archive_type mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::m_archive
protected

Archive that stores the data.

◆ m_error

template<class Serializer_derived_type , class Archive_type >
Serialization_error mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::m_error
protected

Holds information about error.

◆ m_level

template<class Serializer_derived_type , class Archive_type >
Level_type mysql::serialization::Serializer< Serializer_derived_type, Archive_type >::m_level {0}
protected

Level of the serializable tree.


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