26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_BINARY_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_BINARY_H_
31#include <system_error>
46template <
bool Borrowed>
54 static constexpr const uint8_t byte_size = 1;
60 static constexpr const uint8_t byte_size = 2;
66 static constexpr const uint8_t byte_size = 4;
72 static constexpr const uint8_t byte_size = 4;
78 static constexpr const uint8_t byte_size = 8;
94 static constexpr const uint8_t byte_size = 8;
100 static constexpr const uint8_t byte_size = 4;
121 static constexpr const uint8_t byte_size = 2;
124template <
bool Borrowed>
129template <
bool Borrowed>
134template <
bool Borrowed>
139template <
bool Borrowed>
144template <
bool Borrowed>
149template <
bool Borrowed>
154template <
bool Borrowed>
159template <
bool Borrowed>
164template <
bool Borrowed>
169template <
bool Borrowed>
174template <
bool Borrowed>
179template <
bool Borrowed>
184template <
bool Borrowed>
195 template <
class Accumulator>
199 return accu.result();
211 static constexpr uint16_t
type() {
219 auto value_res = accu.template step<wire::FixedInt<byte_size>>();
234 template <
class Accumulator>
239 union overlapped_storage {
245 char addr_[
sizeof(
val_)];
246 } overlapped(
val_.value());
248 static_assert(
sizeof(overlapped.val_) ==
byte_size);
252 std::string_view((&overlapped.addr_[0]),
sizeof(overlapped.val_))})
265 static constexpr uint16_t
type() {
273 auto value_res = accu.template step<borrowed::wire::String>(
byte_size);
278 memcpy(&val, value_res->value().data(),
byte_size);
287template <
bool Borrowed,
class T>
289 template <
class Accumulator>
293 return accu.result();
305 static constexpr uint16_t
type() {
313 auto value_res = accu.template step<borrowable::wire::String<Borrowed>>();
326 template <
class Accumulator>
328 const bool has_ms =
val_.microsecond();
329 const bool has_time =
330 val_.hour() ||
val_.minute() ||
val_.second() || has_ms;
331 const bool has_date =
val_.year() ||
val_.month() ||
val_.day() || has_time;
346 return accu.result();
358 static constexpr uint16_t
type() {
366 auto year_res = accu.template try_step<wire::FixedInt<2>>();
371 auto month_res = accu.template step<wire::FixedInt<1>>();
372 auto day_res = accu.template step<wire::FixedInt<1>>();
375 auto hour_res = accu.template try_step<wire::FixedInt<1>>();
377 return std::make_pair(
379 value_type(year_res->value(), month_res->value(), day_res->value()));
382 auto minute_res = accu.template step<wire::FixedInt<1>>();
383 auto second_res = accu.template step<wire::FixedInt<1>>();
386 auto microsecond_res = accu.template try_step<wire::FixedInt<4>>();
387 if (!microsecond_res) {
388 return std::make_pair(
390 value_type(year_res->value(), month_res->value(), day_res->value(),
391 hour_res->value(), minute_res->value(),
392 second_res->value()));
397 return std::make_pair(
399 value_type(year_res->value(), month_res->value(), day_res->value(),
400 hour_res->value(), minute_res->value(), second_res->value(),
401 microsecond_res->value()));
410 template <
class Accumulator>
413 val_.microsecond()) {
419 if (
val_.microsecond()) {
423 return accu.result();
435 static constexpr uint16_t
type() {
443 auto is_negative_res = accu.template try_step<wire::FixedInt<1>>();
444 if (!is_negative_res) {
447 auto days_res = accu.template step<wire::FixedInt<4>>();
448 auto hour_res = accu.template step<wire::FixedInt<1>>();
449 auto minute_res = accu.template step<wire::FixedInt<1>>();
450 auto second_res = accu.template step<wire::FixedInt<1>>();
451 auto microsecond_res = accu.template try_step<wire::FixedInt<4>>();
453 if (!microsecond_res) {
456 return std::make_pair(
458 value_type(is_negative_res->value(), days_res->value(),
459 hour_res->value(), minute_res->value(),
460 second_res->value()));
465 return std::make_pair(
467 value_type(is_negative_res->value(), days_res->value(),
468 hour_res->value(), minute_res->value(), second_res->value(),
469 microsecond_res->value()));
481 template <
class Accumulator>
483 return accu.result();
495 static constexpr uint16_t
type() {
510 using FixedIntCodec::FixedIntCodec;
517 using FixedIntCodec::FixedIntCodec;
524 using FixedIntCodec::FixedIntCodec;
531 using FixedIntCodec::FixedIntCodec;
538 using FixedIntCodec::FixedIntCodec;
545 using FixedIntCodec::FixedIntCodec;
552 using FloatCodec::FloatCodec;
559 using FloatCodec::FloatCodec;
562template <
bool Borrowed>
570template <
bool Borrowed>
573 borrowable::binary::VarString<Borrowed>> {
579template <
bool Borrowed>
582 borrowable::binary::Varchar<Borrowed>> {
588template <
bool Borrowed>
596template <
bool Borrowed>
604template <
bool Borrowed>
607 borrowable::binary::TinyBlob<Borrowed>> {
613template <
bool Borrowed>
616 borrowable::binary::MediumBlob<Borrowed>> {
622template <
bool Borrowed>
625 borrowable::binary::LongBlob<Borrowed>> {
631template <
bool Borrowed>
639template <
bool Borrowed>
647template <
bool Borrowed>
650 borrowable::binary::Decimal<Borrowed>> {
656template <
bool Borrowed>
659 borrowable::binary::NewDecimal<Borrowed>> {
665template <
bool Borrowed>
673template <
bool Borrowed>
676 borrowable::binary::Geometry<Borrowed>> {
686 using DatetimeCodec::DatetimeCodec;
693 using DatetimeCodec::DatetimeCodec;
700 using DatetimeCodec::DatetimeCodec;
707 using TimeCodec::TimeCodec;
constexpr Codec(value_type, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:492
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:495
friend base_
Definition: classic_protocol_codec_binary.h:490
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:482
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &, capabilities::value_type)
Definition: classic_protocol_codec_binary.h:499
Codec for a type.
Definition: classic_protocol_codec_base.h:72
Definition: classic_protocol_binary.h:293
Definition: classic_protocol_binary.h:245
Definition: classic_protocol_binary.h:123
Definition: classic_protocol_binary.h:133
Definition: classic_protocol_binary.h:281
Definition: classic_protocol_binary.h:210
Definition: classic_protocol_binary.h:269
Definition: classic_protocol_binary.h:215
Definition: classic_protocol_binary.h:299
Definition: classic_protocol_binary.h:190
Definition: classic_protocol_binary.h:239
Definition: classic_protocol_binary.h:263
Definition: classic_protocol_binary.h:180
Definition: classic_protocol_binary.h:185
Definition: classic_protocol_binary.h:257
Definition: classic_protocol_binary.h:287
Definition: classic_protocol_binary.h:304
Definition: classic_protocol_binary.h:275
Definition: classic_protocol_binary.h:195
Definition: classic_protocol_binary.h:221
Definition: classic_protocol_binary.h:138
Definition: classic_protocol_binary.h:128
Definition: classic_protocol_binary.h:251
Definition: classic_protocol_binary.h:205
Definition: classic_protocol_binary.h:227
Definition: classic_protocol_binary.h:233
Definition: classic_protocol_binary.h:200
Definition: classic_protocol_wire.h:103
Definition: classic_protocol_wire.h:38
Definition: classic_protocol_codec_binary.h:325
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:327
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:358
constexpr DatetimeCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:355
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_binary.h:362
friend base_
Definition: classic_protocol_codec_binary.h:353
value_type val_
Definition: classic_protocol_codec_binary.h:405
T value_type
Definition: classic_protocol_codec_binary.h:350
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
constexpr capabilities::value_type caps() const noexcept
Definition: classic_protocol_codec_base.h:390
Definition: classic_protocol_codec_binary.h:192
static constexpr const int byte_size
Definition: classic_protocol_codec_binary.h:193
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:196
friend base_
Definition: classic_protocol_codec_binary.h:206
constexpr FixedIntCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:208
const value_type val_
Definition: classic_protocol_codec_binary.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_binary.h:215
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:211
T value_type
Definition: classic_protocol_codec_binary.h:203
Definition: classic_protocol_codec_binary.h:231
T value_type
Definition: classic_protocol_codec_binary.h:257
const value_type val_
Definition: classic_protocol_codec_binary.h:284
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:235
constexpr FloatCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:262
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_binary.h:269
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:265
static constexpr const int byte_size
Definition: classic_protocol_codec_binary.h:232
friend base_
Definition: classic_protocol_codec_binary.h:260
Definition: classic_protocol_codec_binary.h:288
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_binary.h:309
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:290
const value_type val_
Definition: classic_protocol_codec_binary.h:321
friend base_
Definition: classic_protocol_codec_binary.h:300
constexpr StringCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:302
T value_type
Definition: classic_protocol_codec_binary.h:297
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:305
Definition: classic_protocol_codec_binary.h:409
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:435
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:411
const value_type val_
Definition: classic_protocol_codec_binary.h:473
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_binary.h:439
T value_type
Definition: classic_protocol_codec_binary.h:427
constexpr TimeCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:432
friend base_
Definition: classic_protocol_codec_binary.h:430
constexpr const value_type & value() const &
Definition: expected.h:688
constexpr const error_type & error() const &
Definition: expected.h:737
Definition: expected.h:944
uint16_t value_type
Definition: vt100.h:184
borrowable::binary::Null Null
Definition: classic_protocol_binary.h:337
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
constexpr value_type Short
Definition: classic_protocol_constants.h:233
constexpr value_type DateTime
Definition: classic_protocol_constants.h:243
constexpr value_type LongLong
Definition: classic_protocol_constants.h:239
constexpr value_type Varchar
Definition: classic_protocol_constants.h:246
constexpr value_type NewDecimal
Definition: classic_protocol_constants.h:253
constexpr value_type Time
Definition: classic_protocol_constants.h:242
constexpr value_type Decimal
Definition: classic_protocol_constants.h:231
constexpr value_type VarString
Definition: classic_protocol_constants.h:260
constexpr value_type MediumBlob
Definition: classic_protocol_constants.h:257
constexpr value_type String
Definition: classic_protocol_constants.h:261
constexpr value_type Set
Definition: classic_protocol_constants.h:255
constexpr value_type Geometry
Definition: classic_protocol_constants.h:262
constexpr value_type Bit
Definition: classic_protocol_constants.h:247
constexpr value_type Tiny
Definition: classic_protocol_constants.h:232
constexpr value_type TinyBlob
Definition: classic_protocol_constants.h:256
constexpr value_type Json
Definition: classic_protocol_constants.h:252
constexpr value_type Int24
Definition: classic_protocol_constants.h:240
constexpr value_type Enum
Definition: classic_protocol_constants.h:254
constexpr value_type Long
Definition: classic_protocol_constants.h:234
constexpr value_type Double
Definition: classic_protocol_constants.h:236
constexpr value_type Year
Definition: classic_protocol_constants.h:244
constexpr value_type Timestamp
Definition: classic_protocol_constants.h:238
constexpr value_type LongBlob
Definition: classic_protocol_constants.h:258
constexpr value_type Null
Definition: classic_protocol_constants.h:237
constexpr value_type Blob
Definition: classic_protocol_constants.h:259
constexpr value_type Date
Definition: classic_protocol_constants.h:241
constexpr value_type Float
Definition: classic_protocol_constants.h:235
Definition: classic_protocol_binary.h:39
Definition: authentication.cc:36
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 result result
Definition: result.h:34
Definition: classic_protocol_codec_binary.h:44