MySQL 8.0.33
Source Code Documentation
classic_protocol_codec_clone.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2023, 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 also distributed 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 included with MySQL.
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 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
25#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_CLONE_H_
26#define MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_CLONE_H_
27
31
32namespace classic_protocol {
33namespace clone::client {
34enum class CommandByte {
35 Init = 0x01,
36 Attach,
37 Reinit,
38 Execute,
39 Ack,
40 Exit,
41};
42}
43
44/**
45 * codec for clone::client::Init message.
46 *
47 * - Fixed<1> cmd_byte
48 * - Fixed<4> protocol version
49 * - Fixed<4> ddl_timeout
50 * - 0-or-more
51 * - 1 SE type
52 * - Fixed<4> locator_len
53 * - String<locator_len> locator
54 */
55template <>
57 : public impl::EncodeBase<Codec<clone::client::Init>> {
58 template <class Accumulator>
59 constexpr auto accumulate_fields(Accumulator &&accu) const {
60 return accu.step(wire::FixedInt<1>(cmd_byte()))
61 .step(wire::FixedInt<4>(v_.protocol_version))
62 .step(wire::FixedInt<4>(v_.ddl_timeout))
63 .result();
64 }
65
66 public:
69
70 friend __base;
71
73 : __base(caps), v_{std::move(v)} {}
74
75 constexpr static uint8_t cmd_byte() noexcept {
76 return static_cast<uint8_t>(clone::client::CommandByte::Init);
77 }
78
82
83 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
84 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
85
86 auto protocol_version_res = accu.template step<wire::FixedInt<4>>();
87 auto ddl_timeout_res = accu.template step<wire::FixedInt<4>>();
88
89 // TODO(jkneschk): if there is more data, 1-or-more Locators
90
91 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
92 return std::make_pair(accu.result().value(), value_type());
93 }
94
95 private:
97};
98
99// Reinit decodes the same way as Init
100// Ack decodes the same way as Init
101
102template <>
103class Codec<clone::client::Execute>
104 : public impl::EncodeBase<Codec<clone::client::Execute>> {
105 template <class Accumulator>
106 constexpr auto accumulate_fields(Accumulator &&accu) const {
107 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
108 }
109
110 public:
113
114 friend __base;
115
117 : __base(caps), v_{std::move(v)} {}
118
119 constexpr static uint8_t cmd_byte() noexcept {
120 return static_cast<uint8_t>(clone::client::CommandByte::Execute);
121 }
122
123 template <class ConstBufferSequence>
127
128 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
129 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
130
131 return std::make_pair(accu.result().value(), value_type());
132 }
133
134 private:
136};
137
138template <>
139class Codec<clone::client::Attach>
140 : public impl::EncodeBase<Codec<clone::client::Attach>> {
141 template <class Accumulator>
142 constexpr auto accumulate_fields(Accumulator &&accu) const {
143 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
144 }
145
146 public:
149
150 friend __base;
151
153 : __base(caps), v_{std::move(v)} {}
154
155 constexpr static uint8_t cmd_byte() noexcept {
156 return static_cast<uint8_t>(clone::client::CommandByte::Attach);
157 }
158
159 template <class ConstBufferSequence>
163
164 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
165 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
166
167 return std::make_pair(accu.result().value(), value_type());
168 }
169
170 private:
172};
173
174template <>
175class Codec<clone::client::Reinit>
176 : public impl::EncodeBase<Codec<clone::client::Reinit>> {
177 template <class Accumulator>
178 constexpr auto accumulate_fields(Accumulator &&accu) const {
179 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
180 }
181
182 public:
185
186 friend __base;
187
189 : __base(caps), v_{std::move(v)} {}
190
191 constexpr static uint8_t cmd_byte() noexcept {
192 return static_cast<uint8_t>(clone::client::CommandByte::Reinit);
193 }
194
195 template <class ConstBufferSequence>
199
200 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
201 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
202
203 return std::make_pair(accu.result().value(), value_type());
204 }
205
206 private:
208};
209
210template <>
211class Codec<clone::client::Ack>
212 : public impl::EncodeBase<Codec<clone::client::Ack>> {
213 template <class Accumulator>
214 constexpr auto accumulate_fields(Accumulator &&accu) const {
215 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
216 }
217
218 public:
221
222 friend __base;
223
225 : __base(caps), v_{std::move(v)} {}
226
227 constexpr static uint8_t cmd_byte() noexcept {
228 return static_cast<uint8_t>(clone::client::CommandByte::Ack);
229 }
230
231 template <class ConstBufferSequence>
235
236 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
237 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
238
239 return std::make_pair(accu.result().value(), value_type());
240 }
241
242 private:
244};
245
246template <>
247class Codec<clone::client::Exit>
248 : public impl::EncodeBase<Codec<clone::client::Exit>> {
249 template <class Accumulator>
250 constexpr auto accumulate_fields(Accumulator &&accu) const {
251 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
252 }
253
254 public:
257
258 friend __base;
259
261 : __base(caps), v_{std::move(v)} {}
262
263 constexpr static uint8_t cmd_byte() noexcept {
264 return static_cast<uint8_t>(clone::client::CommandByte::Exit);
265 }
266
267 template <class ConstBufferSequence>
271
272 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
273 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
274
275 return std::make_pair(accu.result().value(), value_type());
276 }
277
278 private:
280};
281
282namespace clone::server {
283enum class CommandByte {
284 Locators = 0x01,
286 Data,
287 Plugin,
288 Config,
289 Collation,
290 PluginV2, // version: 0x0101
291 ConfigV3, // version: 0x0102
292 Complete = 99,
293 Error = 100,
294};
295}
296
297// clone::string:
298// Fixed<4> len
299// String<len> payload
300//
301// Plugin:
302// - clone::string
303// PluginV2:
304// - key clone::string
305// - value clone::string
306// Collation:
307// - clone::string
308// Config
309// - key clone::string
310// - value clone::string
311
312template <>
313class Codec<clone::server::Complete>
314 : public impl::EncodeBase<Codec<clone::server::Complete>> {
315 template <class Accumulator>
316 constexpr auto accumulate_fields(Accumulator &&accu) const {
317 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
318 }
319
320 public:
321 using value_type = clone::server::Complete;
323
324 friend __base;
325
327 : __base(caps), v_{std::move(v)} {}
328
329 constexpr static uint8_t cmd_byte() noexcept {
330 return static_cast<uint8_t>(clone::server::CommandByte::Complete);
331 }
332
333 template <class ConstBufferSequence>
337
338 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
339 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
340
341 return std::make_pair(accu.result().value(), value_type());
342 }
343
344 private:
346};
347
348template <>
349class Codec<clone::server::Error>
350 : public impl::EncodeBase<Codec<clone::server::Error>> {
351 template <class Accumulator>
352 constexpr auto accumulate_fields(Accumulator &&accu) const {
353 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
354 }
355
356 public:
357 using value_type = clone::server::Error;
359
360 friend __base;
361
363 : __base(caps), v_{std::move(v)} {}
364
365 constexpr static uint8_t cmd_byte() noexcept {
366 return static_cast<uint8_t>(clone::server::CommandByte::Error);
367 }
368
369 template <class ConstBufferSequence>
373
374 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
375 if (!accu.result()) return stdx::make_unexpected(accu.result().error());
376
377 return std::make_pair(accu.result().value(), value_type());
378 }
379
380 private:
382};
383
384} // namespace classic_protocol
385#endif
const value_type v_
Definition: classic_protocol_codec_clone.h:243
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:224
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:214
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:227
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:232
friend __base
Definition: classic_protocol_codec_clone.h:222
const value_type v_
Definition: classic_protocol_codec_clone.h:171
friend __base
Definition: classic_protocol_codec_clone.h:150
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:155
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:142
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:160
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:152
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:119
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:116
friend __base
Definition: classic_protocol_codec_clone.h:114
const value_type v_
Definition: classic_protocol_codec_clone.h:135
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:124
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:106
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:260
const value_type v_
Definition: classic_protocol_codec_clone.h:279
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:250
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:268
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:263
friend __base
Definition: classic_protocol_codec_clone.h:258
friend __base
Definition: classic_protocol_codec_clone.h:70
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:79
const value_type v_
Definition: classic_protocol_codec_clone.h:96
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:72
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:59
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:75
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:178
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:188
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:191
const value_type v_
Definition: classic_protocol_codec_clone.h:207
friend __base
Definition: classic_protocol_codec_clone.h:186
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:196
friend __base
Definition: classic_protocol_codec_clone.h:324
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:334
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:326
const value_type v_
Definition: classic_protocol_codec_clone.h:345
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:329
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:316
clone::server::Complete value_type
Definition: classic_protocol_codec_clone.h:321
clone::server::Error value_type
Definition: classic_protocol_codec_clone.h:357
const value_type v_
Definition: classic_protocol_codec_clone.h:381
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:370
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:362
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:352
friend __base
Definition: classic_protocol_codec_clone.h:360
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:365
Codec for a type.
Definition: classic_protocol_codec_base.h:71
Definition: classic_protocol_wire.h:102
Definition: classic_protocol_clone.h:56
Definition: classic_protocol_clone.h:50
Definition: classic_protocol_clone.h:54
Definition: classic_protocol_clone.h:65
Definition: classic_protocol_clone.h:42
Definition: classic_protocol_clone.h:51
Definition: classic_protocol_clone.h:82
Definition: classic_protocol_clone.h:83
Definition: classic_protocol_clone.h:69
Generator of decoded Types of a buffer.
Definition: classic_protocol_codec_base.h:152
result_type result() const
get result of the step().
Definition: classic_protocol_codec_base.h:218
CRTP base for the Codec's encode part.
Definition: classic_protocol_codec_base.h:374
Definition: buffer.h:134
constexpr const value_type & value() const &
Definition: expected.h:687
constexpr const error_type & error() const &
Definition: expected.h:736
Definition: expected.h:943
static int Init(MYSQL_PLUGIN p)
Definition: ha_mock.cc:356
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:72
CommandByte
Definition: classic_protocol_codec_clone.h:34
CommandByte
Definition: classic_protocol_codec_clone.h:283
Definition: classic_protocol_clone.h:31
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:419
Definition: varlen_sort.h:183
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:124
struct server server
Definition: server_struct.h:58
static ORDER * clone(THD *thd, ORDER *order)
Shallow clone the list of ORDER objects using mem_root and return the cloned list.
Definition: window.cc:83