MySQL 8.4.0
Source Code Documentation
tag_plain.h
Go to the documentation of this file.
1// Copyright (c) 2023, 2024, 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
33#include "mysql/gtid/tag.h"
34
35/// @addtogroup GroupLibsMysqlGtid
36/// @{
37
38namespace mysql::gtid {
39
40class Tag;
41
42/// @brief Tag representation so that:
43/// - Tag_plain is trivial
44/// - Tag_plain is standard layout
45/// Therefore, a Tag_plain object is not empty by default! Use clear() or
46/// brace-enclosed initializer list to create an empty tag.
47/// Tag_plain must be a POD because it is used in Gtid_specification
48struct Tag_plain {
49 /// @brief Default ctor
50 Tag_plain() = default;
51 /// @brief Construct from tag object
52 /// @param tag tag to copy
53 explicit Tag_plain(const Tag &tag);
54
55 /// @brief Clear this tag
56 void clear();
57
58 /// @brief Checks whether tag is defined
59 /// @retval true Tag is defined
60 /// @retval false Tag is empty
61 bool is_defined() const;
62
63 /// @brief Obtains tag length
64 /// @return tag length
65 std::size_t length() const;
66
67 /// @brief Copies internal tag into a given buffer
68 /// @param[in,out] buf Buffer, needs to be pre-allocated
69 /// @return Number of bytes written into the buffer
70 std::size_t to_string(char *buf) const;
71
72 /// @brief Sets internal data to match a given pattern
73 /// @param[in] tag Pattern to copy from
74 void set(const Tag &tag);
75
76 /// @brief Internal data accessor (for encoding)
77 const unsigned char *data() const;
78
79 private:
80 /// null terminated tag representation
81 unsigned char m_data[tag_max_length + 1];
82};
83
84static_assert(std::is_trivial_v<Tag_plain>);
85static_assert(std::is_standard_layout_v<Tag_plain>);
86
87} // namespace mysql::gtid
88
89/// @}
90
91#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:48
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:81
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