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