MySQL 9.6.0
Source Code Documentation
gtid_binary_format.h
Go to the documentation of this file.
1// Copyright (c) 2025, 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_GTIDS_STRCONV_GTID_BINARY_FORMAT_H
25#define MYSQL_GTIDS_STRCONV_GTID_BINARY_FORMAT_H
26
27/// @file
28/// Experimental API header
29
30#include <cassert> // assert
31#include "mysql/gtids/gtid.h" // Is_gtid
32#include "mysql/gtids/gtid_set.h" // Is_gtid_set
33#include "mysql/gtids/tag.h" // Is_tag
34#include "mysql/gtids/tsid.h" // Is_tsid
35#include "mysql/strconv/strconv.h" // Format_base
36#include "mysql/utils/enumeration_utils.h" // enum_max
37
38/// @addtogroup GroupLibsMysqlGtids
39/// @{
40
41namespace mysql::strconv {
42
44 // NOLINTBEGIN(performance-enum-size): silence clang-tidy's pointless hint
45
46 /// The format version. See readme.md for format specifications.
47 enum class Version {
48 /// Version 0, which does not support tags.
49 /// Encoding a nonempty tag with this is undefined behavior.
50 /// Decoding a tag with this clears the tag without reading any input.
51 v0_tagless = 0,
52
53 /// Version 1, which supports tags.
54 v1_tags = 1,
55
56 /// Version 2, which supports tags and is more space-efficient.
58 };
59
60 /// Policy for choosing a version. This either a specified version, or
61 /// 'automatic'.
62 enum class Version_policy {
63 v0_tagless = 0,
64 v1_tags = 1,
66
67 /// Encode using an automatically selected format. Currently, this favors
68 /// compatibility and uses the minimum version supported by the object type,
69 /// i.e.:
70 /// - v0_tagless if the set does not have tags
71 /// - v1_tags if the set has tags.
72 ///
73 /// Decode Gtid sets using whatever format is encoded in the object.
74 ///
75 /// Decode Gtids/Tsids/Uuids/Tags using v1 (which coincides with v2 for
76 /// these objects).
77 automatic = 3
78 };
79
80 // NOLINTEND(performance-enum-size)
81
82 /// Returns the Version_policy that specifies the given concrete version.
84 switch (version) {
91 default:
92 assert(0);
94 }
95 }
96
97 Gtid_binary_format() = default;
98 explicit constexpr Gtid_binary_format(const Version_policy &version_policy)
99 : m_version_policy(version_policy) {}
100
101 [[nodiscard]] auto parent() const { return Binary_format{}; }
102
103 /// Policy for the version to use.
104 ///
105 /// Note: user code should rely on the default, which is `automatic`. Other
106 /// modes are available only for unittests.
108};
109
110template <class Object_t>
114auto get_default_format(const Binary_format &, const Object_t &) {
115 return Gtid_binary_format{};
116}
117
118} // namespace mysql::strconv
119
120namespace mysql::utils {
121template <>
123enum_max<mysql::strconv::Gtid_binary_format::Version>() {
125}
126} // namespace mysql::utils
127
128// addtogroup GroupLibsMysqlGtids
129/// @}
130
131#endif // ifndef MYSQL_GTIDS_STRCONV_GTID_BINARY_FORMAT_H
Class representing a version.
Definition: designator.h:45
True for all Gtid set types.
Definition: gtid_set.h:178
Definition: gtid.h:53
True if Test is one of the tag classes.
Definition: tag.h:192
Definition: tsid.h:50
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Experimental API header.
Definition: gtid_binary_format.h:41
auto get_default_format(const Binary_format &, const Object_t &)
Definition: gtid_binary_format.h:114
Definition: gtid_format.h:47
required uint64 version
Definition: replication_group_member_actions.proto:41
Format tag to identify binary format.
Definition: binary_format.h:38
Top of the hierarchy.
Definition: format.h:38
Definition: gtid_binary_format.h:43
constexpr Gtid_binary_format(const Version_policy &version_policy)
Definition: gtid_binary_format.h:98
static Version_policy to_version_policy(Version version)
Returns the Version_policy that specifies the given concrete version.
Definition: gtid_binary_format.h:83
Version_policy
Policy for choosing a version.
Definition: gtid_binary_format.h:62
@ automatic
Encode using an automatically selected format.
auto parent() const
Definition: gtid_binary_format.h:101
Version
The format version. See readme.md for format specifications.
Definition: gtid_binary_format.h:47
@ v2_tags_compact
Version 2, which supports tags and is more space-efficient.
@ v1_tags
Version 1, which supports tags.
@ v0_tagless
Version 0, which does not support tags.
Version_policy m_version_policy
Policy for the version to use.
Definition: gtid_binary_format.h:107