MySQL 8.4.11
Source Code Documentation
tag_plain.h
Go to the documentation of this file.
1// Copyright (c) 2023, 2026, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_GTID_TAG_PLAIN_H
25#define MYSQL_GTID_TAG_PLAIN_H
26
27#include <array>
28#include <cstring>
29#include <memory>
30#include <string>
31#include <type_traits>
32
34#include "mysql/gtid/tag.h"
35
36/// @addtogroup GroupLibsMysqlGtid
37/// @{
38
39namespace mysql::gtid {
40
41class Tag;
42
43/// @brief Tag representation so that:
44/// - Tag_plain is trivial
45/// - Tag_plain is standard layout
46/// Therefore, a Tag_plain object is not empty by default! Use clear() or
47/// brace-enclosed initializer list to create an empty tag.
48/// Tag_plain must be a POD because it is used in Gtid_specification
49struct Tag_plain {
50 /// @brief Default ctor
51 Tag_plain() = default;
52 /// @brief Construct from tag object
53 /// @param tag tag to copy
54 explicit Tag_plain(const Tag &tag);
55
56 /// @brief Clear this tag
57 void clear();
58
59 /// @brief Checks whether tag is defined
60 /// @retval true Tag is defined
61 /// @retval false Tag is empty
62 bool is_defined() const;
63
64 /// @brief Obtains tag length
65 /// @return tag length
66 std::size_t length() const;
67
68 /// @brief Copies internal tag into a given buffer
69 /// @param[in,out] buf Buffer, needs to be pre-allocated
70 /// @return Number of bytes written into the buffer
71 std::size_t to_string(char *buf) const;
72
73 /// @brief Sets internal data to match a given pattern
74 /// @param[in] tag Pattern to copy from
75 void set(const Tag &tag);
76
77 /// @brief Internal data accessor (for encoding)
78 const unsigned char *data() const;
79
80 private:
81 /// null terminated tag representation
82 unsigned char m_data[tag_max_length + 1];
83};
84
85static_assert(std::is_trivial_v<Tag_plain>);
86static_assert(std::is_standard_layout_v<Tag_plain>);
87
88} // namespace mysql::gtid
89
90/// @}
91
92#endif // MYSQL_GTID_TAG_PLAIN_H
Representation of the GTID tag.
Definition: tag.h:51
Definition: buf0block_hint.cc:30
Definition: global.h:35
constexpr std::size_t tag_max_length
Maximal number of characters in a tag.
Definition: gtid_constants.h:44
Tag representation so that:
Definition: tag_plain.h:49
Tag_plain()=default
Default ctor.
bool is_defined() const
Checks whether tag is defined.
Definition: tag_plain.cpp:39
std::size_t length() const
Obtains tag length.
Definition: tag_plain.cpp:41
unsigned char m_data[tag_max_length+1]
null terminated tag representation
Definition: tag_plain.h:82
void set(const Tag &tag)
Sets internal data to match a given pattern.
Definition: tag_plain.cpp:47
const unsigned char * data() const
Internal data accessor (for encoding)
Definition: tag_plain.cpp:56
std::size_t to_string(char *buf) const
Copies internal tag into a given buffer.
Definition: tag_plain.cpp:31
void clear()
Clear this tag.
Definition: tag_plain.cpp:37