MySQL 8.4.0
Source Code Documentation
mysql::gtid::Tag Class Reference

Representation of the GTID tag. More...

#include <tag.h>

Classes

struct  Hash
 Structure to compute hash function of a given Tag object. More...
 

Public Types

using Tag_data = std::string
 

Public Member Functions

 Tag ()=default
 Constructs an empty, valid tag. More...
 
 Tag (const Tag_plain &tag)
 Construct from Tag_plain object. More...
 
 Tag (const std::string &text)
 Constructs tag from a given text. More...
 
std::string to_string () const
 Obtains textual representation of internal tag. More...
 
std::size_t to_string (char *out) const
 Obtains textual representation of internal tag and writes it to out. More...
 
std::size_t from_string (const std::string &text)
 Creates Tag object from a given text. More...
 
std::size_t from_cstring (const char *text)
 Creates Tag object from a given text. More...
 
bool is_empty () const
 Indicates whether transaction tag is empty. More...
 
bool is_defined () const
 Indicates whether transaction tag is defined (is not empty) More...
 
bool operator== (const Tag &other) const
 Operator ==. More...
 
bool operator!= (const Tag &other) const
 Operator !=. More...
 
bool operator< (const Tag &other) const
 Compares this tag with other, <. More...
 
std::size_t encode_tag (unsigned char *buf, const Gtid_format &gtid_format) const
 stores Tag in buffer More...
 
std::size_t get_encoded_length (const Gtid_format &gtid_format) const
 returns length of encoded tag, based on defined format More...
 
std::size_t get_length () const
 returns length of tag More...
 
std::size_t decode_tag (const unsigned char *buf, std::size_t buf_len, const Gtid_format &gtid_format)
 Reads Tag data from the buffer. More...
 
const Tag_dataget_data () const
 Internal data accessor. More...
 
Tag_dataget_data ()
 Internal data accessor, non const (serialization) More...
 

Static Public Member Functions

static constexpr std::size_t get_max_encoded_length ()
 Obtains maximum length of encoded tag (compile time) More...
 

Protected Member Functions

void replace (const char *text, std::size_t len)
 Replaces internal tag data with a given text, includes text normalization. More...
 

Static Protected Member Functions

static bool is_valid_end_char (const char &character)
 Checks whether current character is a valid ending of a Tag string. More...
 
static bool is_character_valid (const char &character, std::size_t pos)
 Checks whether current character is a valid Tag character. More...
 

Protected Attributes

Tag_data m_data = ""
 internal tag representation More...
 

Detailed Description

Representation of the GTID tag.

Tag format: [a-z_]{a-z0-9_}{0,31} Tag may be created from a given text. Text may contain leading and trailing spaces which will be omitted during Tag creation. Text may also contain uppercase characters. Acceptable format for text is as follows: [:space:][a-zA-Z_][a-zA-Z0-9_]{0,31}[:space:]

Member Typedef Documentation

◆ Tag_data

using mysql::gtid::Tag::Tag_data = std::string

Constructor & Destructor Documentation

◆ Tag() [1/3]

mysql::gtid::Tag::Tag ( )
default

Constructs an empty, valid tag.

◆ Tag() [2/3]

mysql::gtid::Tag::Tag ( const Tag_plain tag)
explicit

Construct from Tag_plain object.

Parameters
tagpattern

◆ Tag() [3/3]

mysql::gtid::Tag::Tag ( const std::string &  text)

Constructs tag from a given text.

If passed text is not a valid tag representation, object remains empty (empty tag)

Parameters
[in]textTextual representation of a tag
See also
from_cstring

Member Function Documentation

◆ decode_tag()

std::size_t mysql::gtid::Tag::decode_tag ( const unsigned char *  buf,
std::size_t  buf_len,
const Gtid_format gtid_format 
)

Reads Tag data from the buffer.

Parameters
bufBuffer to read tag from
buf_lenNumber of bytes in the buffer
gtid_formatGtid format read from stream, if untagged, tag information is assumed to be empty. If tagged, gtid tag length will be read from the stream both for untagged and tagged GTIDs
Returns
The number of bytes read or 0. For Gtid_format::untagged, function will read bytes. For Gtid_format::tagged, 0 means that an error occurred (e.g. not enough bytes in the buffer to read the tag - corrupted bytes in the buffer).

◆ encode_tag()

std::size_t mysql::gtid::Tag::encode_tag ( unsigned char *  buf,
const Gtid_format gtid_format 
) const

stores Tag in buffer

Parameters
bufBuffer to store bytes, must contain at least get_encoded_length() bytes
gtid_formatFormat of encoded GTID. If tag is not defined for this GTID and tagged format is used, 0 will be encoded as length of the string. In case "untagged" format is requested, function won't encode additional tag information for untagged GTIDs. When using untagged, tag is required to be empty.
Returns
the number of bytes written into the buf

◆ from_cstring()

size_t mysql::gtid::Tag::from_cstring ( const char *  text)

Creates Tag object from a given text.

If passed text is not a valid tag representation, object remains empty (empty tag) Since length of text is unknown, it is expected to be null terminated

Parameters
[in]textTextual representation of a tag
Returns
Number of characters read, 0 means that either tag is empty or invalid

◆ from_string()

size_t mysql::gtid::Tag::from_string ( const std::string &  text)

Creates Tag object from a given text.

If passed text is not a valid tag representation, object remains empty (empty tag). Text must end with a null character or a gtid separator

Parameters
[in]textTextual representation of a tag
Returns
Number of characters read, 0 means that either tag is empty or invalid

◆ get_data() [1/2]

Tag_data & mysql::gtid::Tag::get_data ( )
inline

Internal data accessor, non const (serialization)

Returns
Reference to internal tag data

◆ get_data() [2/2]

const Tag_data & mysql::gtid::Tag::get_data ( ) const
inline

Internal data accessor.

Returns
Const reference to internal tag data

◆ get_encoded_length()

size_t mysql::gtid::Tag::get_encoded_length ( const Gtid_format gtid_format) const

returns length of encoded tag, based on defined format

Parameters
gtid_formatFormat of encoded GTID. If tag is not defined for this GTID and tagged format is used, 0 will be encoded as length of the string. In case "untagged" format is requested, function won't encode additional tag information for untagged GTIDs. When using untagged, tag is required to be empty.
Returns
length of encoded tag in bytes

Note that in case encoded format is "tagged" and tag is empty, we still to encode tag length (1 byte for length equal to 0).

◆ get_length()

std::size_t mysql::gtid::Tag::get_length ( ) const

returns length of tag

Returns
tag length

◆ get_max_encoded_length()

static constexpr std::size_t mysql::gtid::Tag::get_max_encoded_length ( )
inlinestaticconstexpr

Obtains maximum length of encoded tag (compile time)

Returns
Maximum length of encoded tag in bytes

◆ is_character_valid()

bool mysql::gtid::Tag::is_character_valid ( const char &  character,
std::size_t  pos 
)
staticprotected

Checks whether current character is a valid Tag character.

Parameters
[in]characterA character under test
[in]posPosition within a tag
Returns
Answer to question: is character a valid tag character?

◆ is_defined()

bool mysql::gtid::Tag::is_defined ( ) const
inline

Indicates whether transaction tag is defined (is not empty)

Returns
Answer to question: is tag defined?

◆ is_empty()

bool mysql::gtid::Tag::is_empty ( ) const
inline

Indicates whether transaction tag is empty.

Returns
Answer to question: is tag empty?

◆ is_valid_end_char()

bool mysql::gtid::Tag::is_valid_end_char ( const char &  character)
staticprotected

Checks whether current character is a valid ending of a Tag string.

Parameters
[in]characterA character under test
Returns
Answer to question: is character a valid tag ending?

◆ operator!=()

bool mysql::gtid::Tag::operator!= ( const Tag other) const

Operator !=.

Parameters
otherpattern to compare against
Returns
Result of comparison !=

◆ operator<()

bool mysql::gtid::Tag::operator< ( const Tag other) const
inline

Compares this tag with other, <.

Return values
trueThis tag is before other (alphabetical order)
falseOther tag is before this (alphabetical order)

◆ operator==()

bool mysql::gtid::Tag::operator== ( const Tag other) const

Operator ==.

Parameters
otherpattern to compare against
Returns
Result of comparison ==

◆ replace()

void mysql::gtid::Tag::replace ( const char *  text,
std::size_t  len 
)
protected

Replaces internal tag data with a given text, includes text normalization.

Parameters
[in]textPattern to copy from, valid tag string
[in]lenNumber of characters to copy

◆ to_string() [1/2]

std::string mysql::gtid::Tag::to_string ( ) const

Obtains textual representation of internal tag.

Returns
tag string

◆ to_string() [2/2]

std::size_t mysql::gtid::Tag::to_string ( char *  out) const

Obtains textual representation of internal tag and writes it to out.

Parameters
[out]outOutput string
Returns
Number of characters written to out

Member Data Documentation

◆ m_data

Tag_data mysql::gtid::Tag::m_data = ""
protected

internal tag representation


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