MySQL 8.4.2
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
33
34namespace classic_protocol {
35namespace clone::client {
36enum class CommandByte {
37 Init = 0x01,
38 Attach,
39 Reinit,
40 Execute,
41 Ack,
42 Exit,
43};
44} // namespace clone::client
45
46/**
47 * codec for clone::client::Init message.
48 *
49 * - Fixed<1> cmd_byte
50 * - Fixed<4> protocol version
51 * - Fixed<4> ddl_timeout
52 * - 0-or-more
53 * - 1 SE type
54 * - Fixed<4> locator_len
55 * - String<locator_len> locator
56 */
57template <>
59 : public impl::EncodeBase<Codec<clone::client::Init>> {
60 template <class Accumulator>
61 constexpr auto accumulate_fields(Accumulator &&accu) const {
62 return accu.step(wire::FixedInt<1>(cmd_byte()))
63 .step(wire::FixedInt<4>(v_.protocol_version))
64 .step(wire::FixedInt<4>(v_.ddl_timeout))
65 .result();
66 }
67
68 public:
71
72 friend __base;
73
75 : __base(caps), v_{std::move(v)} {}
76
77 constexpr static uint8_t cmd_byte() noexcept {
78 return static_cast<uint8_t>(clone::client::CommandByte::Init);
79 }
80
84
85 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
86 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
87
88 auto protocol_version_res = accu.template step<wire::FixedInt<4>>();
89 if (!protocol_version_res) {
90 return stdx::unexpected(protocol_version_res.error());
91 }
92 auto ddl_timeout_res = accu.template step<wire::FixedInt<4>>();
93 if (!ddl_timeout_res) {
94 return stdx::unexpected(ddl_timeout_res.error());
95 }
96
97 // TODO(jkneschk): if there is more data, 1-or-more Locators
98
99 if (!accu.result()) return stdx::unexpected(accu.result().error());
100 return std::make_pair(accu.result().value(), value_type());
101 }
102
103 private:
105};
106
107// Reinit decodes the same way as Init
108// Ack decodes the same way as Init
109
110template <>
111class Codec<clone::client::Execute>
112 : public impl::EncodeBase<Codec<clone::client::Execute>> {
113 template <class Accumulator>
114 constexpr auto accumulate_fields(Accumulator &&accu) const {
115 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
116 }
117
118 public:
121
122 friend __base;
123
125 : __base(caps), v_{std::move(v)} {}
126
127 constexpr static uint8_t cmd_byte() noexcept {
128 return static_cast<uint8_t>(clone::client::CommandByte::Execute);
129 }
130
131 template <class ConstBufferSequence>
135
136 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
137 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
138
139 return std::make_pair(accu.result().value(), value_type());
140 }
141
142 private:
144};
145
146template <>
147class Codec<clone::client::Attach>
148 : public impl::EncodeBase<Codec<clone::client::Attach>> {
149 template <class Accumulator>
150 constexpr auto accumulate_fields(Accumulator &&accu) const {
151 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
152 }
153
154 public:
157
158 friend __base;
159
161 : __base(caps), v_{std::move(v)} {}
162
163 constexpr static uint8_t cmd_byte() noexcept {
164 return static_cast<uint8_t>(clone::client::CommandByte::Attach);
165 }
166
167 template <class ConstBufferSequence>
171
172 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
173 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
174
175 return std::make_pair(accu.result().value(), value_type());
176 }
177
178 private:
180};
181
182template <>
183class Codec<clone::client::Reinit>
184 : public impl::EncodeBase<Codec<clone::client::Reinit>> {
185 template <class Accumulator>
186 constexpr auto accumulate_fields(Accumulator &&accu) const {
187 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
188 }
189
190 public:
193
194 friend __base;
195
197 : __base(caps), v_{std::move(v)} {}
198
199 constexpr static uint8_t cmd_byte() noexcept {
200 return static_cast<uint8_t>(clone::client::CommandByte::Reinit);
201 }
202
203 template <class ConstBufferSequence>
207
208 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
209 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
210
211 return std::make_pair(accu.result().value(), value_type());
212 }
213
214 private:
216};
217
218template <>
219class Codec<clone::client::Ack>
220 : public impl::EncodeBase<Codec<clone::client::Ack>> {
221 template <class Accumulator>
222 constexpr auto accumulate_fields(Accumulator &&accu) const {
223 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
224 }
225
226 public:
229
230 friend __base;
231
233 : __base(caps), v_{std::move(v)} {}
234
235 constexpr static uint8_t cmd_byte() noexcept {
236 return static_cast<uint8_t>(clone::client::CommandByte::Ack);
237 }
238
239 template <class ConstBufferSequence>
243
244 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
245 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
246
247 return std::make_pair(accu.result().value(), value_type());
248 }
249
250 private:
252};
253
254template <>
255class Codec<clone::client::Exit>
256 : public impl::EncodeBase<Codec<clone::client::Exit>> {
257 template <class Accumulator>
258 constexpr auto accumulate_fields(Accumulator &&accu) const {
259 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
260 }
261
262 public:
265
266 friend __base;
267
269 : __base(caps), v_{std::move(v)} {}
270
271 constexpr static uint8_t cmd_byte() noexcept {
272 return static_cast<uint8_t>(clone::client::CommandByte::Exit);
273 }
274
275 template <class ConstBufferSequence>
279
280 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
281 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
282
283 return std::make_pair(accu.result().value(), value_type());
284 }
285
286 private:
288};
289
290namespace clone::server {
291enum class CommandByte {
292 Locators = 0x01,
294 Data,
295 Plugin,
296 Config,
297 Collation,
298 PluginV2, // version: 0x0101
299 ConfigV3, // version: 0x0102
300 Complete = 99,
301 Error = 100,
302};
303}
304
305// clone::string:
306// Fixed<4> len
307// String<len> payload
308//
309// Plugin:
310// - clone::string
311// PluginV2:
312// - key clone::string
313// - value clone::string
314// Collation:
315// - clone::string
316// Config
317// - key clone::string
318// - value clone::string
319
320template <>
321class Codec<clone::server::Complete>
322 : public impl::EncodeBase<Codec<clone::server::Complete>> {
323 template <class Accumulator>
324 constexpr auto accumulate_fields(Accumulator &&accu) const {
325 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
326 }
327
328 public:
329 using value_type = clone::server::Complete;
331
332 friend __base;
333
335 : __base(caps), v_{std::move(v)} {}
336
337 constexpr static uint8_t cmd_byte() noexcept {
338 return static_cast<uint8_t>(clone::server::CommandByte::Complete);
339 }
340
341 template <class ConstBufferSequence>
345
346 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
347 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
348
349 return std::make_pair(accu.result().value(), value_type());
350 }
351
352 private:
354};
355
356template <>
357class Codec<clone::server::Error>
358 : public impl::EncodeBase<Codec<clone::server::Error>> {
359 template <class Accumulator>
360 constexpr auto accumulate_fields(Accumulator &&accu) const {
361 return accu.step(wire::FixedInt<1>(cmd_byte())).result();
362 }
363
364 public:
365 using value_type = clone::server::Error;
367
368 friend __base;
369
371 : __base(caps), v_{std::move(v)} {}
372
373 constexpr static uint8_t cmd_byte() noexcept {
374 return static_cast<uint8_t>(clone::server::CommandByte::Error);
375 }
376
377 template <class ConstBufferSequence>
381
382 auto cmd_byte_res = accu.template step<wire::FixedInt<1>>();
383 if (!cmd_byte_res) return stdx::unexpected(cmd_byte_res.error());
384
385 return std::make_pair(accu.result().value(), value_type());
386 }
387
388 private:
390};
391
392} // namespace classic_protocol
393#endif
const value_type v_
Definition: classic_protocol_codec_clone.h:251
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:232
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:222
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:235
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:240
friend __base
Definition: classic_protocol_codec_clone.h:230
const value_type v_
Definition: classic_protocol_codec_clone.h:179
friend __base
Definition: classic_protocol_codec_clone.h:158
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:163
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:150
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:168
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:160
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:127
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:124
friend __base
Definition: classic_protocol_codec_clone.h:122
const value_type v_
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:132
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:114
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:268
const value_type v_
Definition: classic_protocol_codec_clone.h:287
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:258
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:276
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:271
friend __base
Definition: classic_protocol_codec_clone.h:266
friend __base
Definition: classic_protocol_codec_clone.h:72
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:81
const value_type v_
Definition: classic_protocol_codec_clone.h:104
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:74
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:61
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:77
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:186
Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:196
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:199
const value_type v_
Definition: classic_protocol_codec_clone.h:215
friend __base
Definition: classic_protocol_codec_clone.h:194
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:204
friend __base
Definition: classic_protocol_codec_clone.h:332
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:342
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:334
const value_type v_
Definition: classic_protocol_codec_clone.h:353
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:337
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:324
clone::server::Complete value_type
Definition: classic_protocol_codec_clone.h:329
clone::server::Error value_type
Definition: classic_protocol_codec_clone.h:365
const value_type v_
Definition: classic_protocol_codec_clone.h:389
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:378
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_clone.h:370
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_clone.h:360
friend __base
Definition: classic_protocol_codec_clone.h:368
constexpr static uint8_t cmd_byte() noexcept
Definition: classic_protocol_codec_clone.h:373
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:374
Definition: buffer.h:135
Definition: expected.h:284
constexpr const error_type & error() const &
Definition: expected.h:751
constexpr value_type & value() &
Definition: expected.h:636
static int Init(MYSQL_PLUGIN p)
Definition: ha_mock.cc:392
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
CommandByte
Definition: classic_protocol_codec_clone.h:36
CommandByte
Definition: classic_protocol_codec_clone.h:291
Definition: classic_protocol_binary.h:39
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Definition: gcs_xcom_synode.h:64
unexpected(E) -> unexpected< E >
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:85