MySQL 9.1.0
Source Code Documentation
classic_protocol_wire.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_WIRE_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_WIRE_H_
28
29#include <cstddef>
30#include <string>
31
32namespace classic_protocol {
33
34namespace borrowable {
35namespace wire {
36
37template <bool Borrowed>
38class String {
39 public:
40 using value_type =
41 std::conditional_t<Borrowed, std::string_view, std::string>;
42
43 constexpr String() = default;
44 constexpr String(value_type str) : str_{std::move(str)} {}
45
46 constexpr value_type value() const { return str_; }
47
48 private:
50};
51
52template <bool Borrowed>
53inline bool operator==(const String<Borrowed> &lhs,
54 const String<Borrowed> &rhs) {
55 return lhs.value() == rhs.value();
56}
57
58template <bool Borrowed>
59class NulTermString : public String<Borrowed> {
60 public:
62};
63
64template <bool Borrowed>
65class VarString : public String<Borrowed> {
66 public:
68};
69
70// basic POD types of the mysql classic-protocol's wire encoding:
71//
72// - fixed size integers
73// - variable sized integers
74// - fixed size strings
75// - variable sized strings
76// - nul-terminated strings
77// - NULL
78
79template <class U>
80class BasicInt {
81 public:
82 using value_type = U;
83
84 constexpr BasicInt(value_type val) : val_{val} {}
85
86 constexpr value_type value() const { return val_; }
87
88 private:
90};
91
92template <class U>
93constexpr bool operator==(const BasicInt<U> &lhs, const BasicInt<U> &rhs) {
94 return lhs.value() == rhs.value();
95}
96
97class VarInt : public BasicInt<int64_t> {
98 public:
100};
101
102template <int Size>
104
105template <>
106class FixedInt<1> : public BasicInt<uint8_t> {
107 public:
108 using BasicInt::BasicInt;
109};
110
111template <>
112class FixedInt<2> : public BasicInt<uint16_t> {
113 public:
114 using BasicInt::BasicInt;
115};
116
117template <>
118class FixedInt<3> : public BasicInt<uint32_t> {
119 public:
120 using BasicInt::BasicInt;
121};
122
123template <>
124class FixedInt<4> : public BasicInt<uint32_t> {
125 public:
126 using BasicInt::BasicInt;
127};
128
129template <>
130class FixedInt<8> : public BasicInt<uint64_t> {
131 public:
132 using BasicInt::BasicInt;
133};
134
135class Null {};
136} // namespace wire
137} // namespace borrowable
138
139namespace borrowed {
140namespace wire {
141
146template <int Size>
149} // namespace wire
150} // namespace borrowed
151
152namespace wire {
153
158
159template <int Size>
161
163} // namespace wire
164
165} // namespace classic_protocol
166
167#endif
Definition: classic_protocol_wire.h:80
constexpr BasicInt(value_type val)
Definition: classic_protocol_wire.h:84
value_type val_
Definition: classic_protocol_wire.h:89
constexpr value_type value() const
Definition: classic_protocol_wire.h:86
Definition: classic_protocol_wire.h:103
Definition: classic_protocol_wire.h:59
Definition: classic_protocol_wire.h:135
Definition: classic_protocol_wire.h:38
constexpr value_type value() const
Definition: classic_protocol_wire.h:46
std::conditional_t< Borrowed, std::string_view, std::string > value_type
Definition: classic_protocol_wire.h:41
value_type str_
Definition: classic_protocol_wire.h:49
constexpr String(value_type str)
Definition: classic_protocol_wire.h:44
Definition: classic_protocol_wire.h:97
Definition: classic_protocol_wire.h:65
#define U
Definition: ctype-tis620.cc:74
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
bool operator==(const String< Borrowed > &lhs, const String< Borrowed > &rhs)
Definition: classic_protocol_wire.h:53
borrowable::wire::Null Null
Definition: classic_protocol_wire.h:157
borrowable::wire::VarInt VarInt
Definition: classic_protocol_wire.h:162
Definition: classic_protocol_binary.h:39
Definition: gcs_xcom_synode.h:64
Definition: dtoa.cc:595