26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_BINARY_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_BINARY_H_
32#include <system_error>
47template <
bool Borrowed>
55 static constexpr const uint8_t byte_size = 1;
61 static constexpr const uint8_t byte_size = 2;
67 static constexpr const uint8_t byte_size = 4;
73 static constexpr const uint8_t byte_size = 4;
79 static constexpr const uint8_t byte_size = 8;
95 static constexpr const uint8_t byte_size = 8;
101 static constexpr const uint8_t byte_size = 4;
122 static constexpr const uint8_t byte_size = 2;
125template <
bool Borrowed>
130template <
bool Borrowed>
135template <
bool Borrowed>
140template <
bool Borrowed>
145template <
bool Borrowed>
150template <
bool Borrowed>
155template <
bool Borrowed>
160template <
bool Borrowed>
165template <
bool Borrowed>
170template <
bool Borrowed>
175template <
bool Borrowed>
180template <
bool Borrowed>
185template <
bool Borrowed>
196 template <
class Accumulator>
200 return accu.result();
212 static constexpr uint16_t
type() {
220 auto value_res = accu.template step<wire::FixedInt<byte_size>>();
235 template <
class Accumulator>
240 union overlapped_storage {
246 char addr_[
sizeof(
val_)];
247 } overlapped(
val_.value());
249 static_assert(
sizeof(overlapped.val_) ==
byte_size);
253 std::string_view((&overlapped.addr_[0]),
sizeof(overlapped.val_))})
266 static constexpr uint16_t
type() {
274 auto value_res = accu.template step<borrowed::wire::String>(
byte_size);
279 memcpy(&val, value_res->value().data(),
byte_size);
288template <
bool Borrowed,
class T>
290 template <
class Accumulator>
294 return accu.result();
306 static constexpr uint16_t
type() {
314 auto value_res = accu.template step<borrowable::wire::String<Borrowed>>();
327 template <
class Accumulator>
329 const bool has_ms =
val_.microsecond();
330 const bool has_time =
331 val_.hour() ||
val_.minute() ||
val_.second() || has_ms;
332 const bool has_date =
val_.year() ||
val_.month() ||
val_.day() || has_time;
347 return accu.result();
359 static constexpr uint16_t
type() {
367 auto year_res = accu.template try_step<wire::FixedInt<2>>();
372 auto month_res = accu.template step<wire::FixedInt<1>>();
373 auto day_res = accu.template step<wire::FixedInt<1>>();
376 auto hour_res = accu.template try_step<wire::FixedInt<1>>();
378 return std::make_pair(
380 value_type(year_res->value(), month_res->value(), day_res->value()));
383 auto minute_res = accu.template step<wire::FixedInt<1>>();
384 auto second_res = accu.template step<wire::FixedInt<1>>();
387 auto microsecond_res = accu.template try_step<wire::FixedInt<4>>();
388 if (!microsecond_res) {
389 return std::make_pair(
391 value_type(year_res->value(), month_res->value(), day_res->value(),
392 hour_res->value(), minute_res->value(),
393 second_res->value()));
398 return std::make_pair(
400 value_type(year_res->value(), month_res->value(), day_res->value(),
401 hour_res->value(), minute_res->value(), second_res->value(),
402 microsecond_res->value()));
411 template <
class Accumulator>
414 val_.microsecond()) {
420 if (
val_.microsecond()) {
424 return accu.result();
436 static constexpr uint16_t
type() {
444 auto is_negative_res = accu.template try_step<wire::FixedInt<1>>();
445 if (!is_negative_res) {
448 auto days_res = accu.template step<wire::FixedInt<4>>();
449 auto hour_res = accu.template step<wire::FixedInt<1>>();
450 auto minute_res = accu.template step<wire::FixedInt<1>>();
451 auto second_res = accu.template step<wire::FixedInt<1>>();
452 auto microsecond_res = accu.template try_step<wire::FixedInt<4>>();
454 if (!microsecond_res) {
457 return std::make_pair(
459 value_type(is_negative_res->value(), days_res->value(),
460 hour_res->value(), minute_res->value(),
461 second_res->value()));
466 return std::make_pair(
468 value_type(is_negative_res->value(), days_res->value(),
469 hour_res->value(), minute_res->value(), second_res->value(),
470 microsecond_res->value()));
482 template <
class Accumulator>
484 return accu.result();
496 static constexpr uint16_t
type() {
511 using FixedIntCodec::FixedIntCodec;
518 using FixedIntCodec::FixedIntCodec;
525 using FixedIntCodec::FixedIntCodec;
532 using FixedIntCodec::FixedIntCodec;
539 using FixedIntCodec::FixedIntCodec;
546 using FixedIntCodec::FixedIntCodec;
553 using FloatCodec::FloatCodec;
560 using FloatCodec::FloatCodec;
563template <
bool Borrowed>
571template <
bool Borrowed>
574 borrowable::binary::VarString<Borrowed>> {
580template <
bool Borrowed>
583 borrowable::binary::Varchar<Borrowed>> {
589template <
bool Borrowed>
597template <
bool Borrowed>
605template <
bool Borrowed>
608 borrowable::binary::TinyBlob<Borrowed>> {
614template <
bool Borrowed>
617 borrowable::binary::MediumBlob<Borrowed>> {
623template <
bool Borrowed>
626 borrowable::binary::LongBlob<Borrowed>> {
632template <
bool Borrowed>
640template <
bool Borrowed>
648template <
bool Borrowed>
651 borrowable::binary::Decimal<Borrowed>> {
657template <
bool Borrowed>
660 borrowable::binary::NewDecimal<Borrowed>> {
666template <
bool Borrowed>
674template <
bool Borrowed>
677 borrowable::binary::Geometry<Borrowed>> {
687 using DatetimeCodec::DatetimeCodec;
694 using DatetimeCodec::DatetimeCodec;
701 using DatetimeCodec::DatetimeCodec;
708 using TimeCodec::TimeCodec;
constexpr Codec(value_type, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:493
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:496
friend base_
Definition: classic_protocol_codec_binary.h:491
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:483
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:500
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:326
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:328
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:359
constexpr DatetimeCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:356
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:363
friend base_
Definition: classic_protocol_codec_binary.h:354
value_type val_
Definition: classic_protocol_codec_binary.h:406
T value_type
Definition: classic_protocol_codec_binary.h:351
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
constexpr capabilities::value_type caps() const noexcept
Definition: classic_protocol_codec_base.h:389
Definition: classic_protocol_codec_binary.h:193
static constexpr const int byte_size
Definition: classic_protocol_codec_binary.h:194
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:197
friend base_
Definition: classic_protocol_codec_binary.h:207
constexpr FixedIntCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:209
const value_type val_
Definition: classic_protocol_codec_binary.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_binary.h:216
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:212
T value_type
Definition: classic_protocol_codec_binary.h:204
Definition: classic_protocol_codec_binary.h:232
T value_type
Definition: classic_protocol_codec_binary.h:258
const value_type val_
Definition: classic_protocol_codec_binary.h:285
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:236
constexpr FloatCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:263
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:270
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:266
static constexpr const int byte_size
Definition: classic_protocol_codec_binary.h:233
friend base_
Definition: classic_protocol_codec_binary.h:261
Definition: classic_protocol_codec_binary.h:289
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:310
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:291
const value_type val_
Definition: classic_protocol_codec_binary.h:322
friend base_
Definition: classic_protocol_codec_binary.h:301
constexpr StringCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:303
T value_type
Definition: classic_protocol_codec_binary.h:298
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:306
Definition: classic_protocol_codec_binary.h:410
static constexpr uint16_t type()
Definition: classic_protocol_codec_binary.h:436
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_binary.h:412
const value_type val_
Definition: classic_protocol_codec_binary.h:474
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:440
T value_type
Definition: classic_protocol_codec_binary.h:428
constexpr TimeCodec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_binary.h:433
friend base_
Definition: classic_protocol_codec_binary.h:431
Definition: expected.h:284
constexpr const error_type & error() const &
Definition: expected.h:751
constexpr value_type & value() &
Definition: expected.h:636
Definition: expected.h:112
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: http_server_component.cc:34
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Definition: gcs_xcom_synode.h:64
unexpected(E) -> unexpected< E >
struct result result
Definition: result.h:34
Definition: classic_protocol_codec_binary.h:45