26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_WIRE_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_WIRE_H_
35#include <system_error>
55 static constexpr size_t int_size{IntSize};
64 static constexpr size_t size() noexcept {
return int_size; }
75 auto int_val = v_.value();
77 if (std::endian::native == std::endian::big) {
81 std::copy_n(
reinterpret_cast<const std::byte *
>(&int_val), int_size,
90 static constexpr size_t max_size() noexcept {
return int_size; }
104 if (std::endian::native == std::endian::big) {
108 return std::make_pair(int_size,
value_type(value));
138 template <
class Accumulator>
140 if (v_.value() < 251) {
142 }
else if (v_.value() < 1 << 16) {
146 }
else if (v_.value() < (1 << 24)) {
158 static constexpr uint8_t varint_16{0xfc};
159 static constexpr uint8_t varint_24{0xfd};
160 static constexpr uint8_t varint_64{0xfe};
169 static constexpr size_t max_size() noexcept {
return 9; }
176 auto first_byte_res = accu.template step<borrowable::wire::FixedInt<1>>();
179 auto first_byte = first_byte_res->value();
181 if (first_byte < 251) {
183 }
else if (first_byte == varint_16) {
184 auto value_res = accu.template step<borrowable::wire::FixedInt<2>>();
188 }
else if (first_byte == varint_24) {
189 auto value_res = accu.template step<borrowable::wire::FixedInt<3>>();
193 }
else if (first_byte == varint_64) {
194 auto value_res = accu.template step<borrowable::wire::FixedInt<8>>();
212 :
public Codec<borrowable::wire::FixedInt<1>> {
216 static constexpr uint8_t nul_byte{0xfb};
227 const uint8_t nul_val = *
static_cast<const uint8_t *
>(
buffer.
data());
229 if (nul_val != nul_byte) {
249 size_t size() const noexcept {
return v_; }
252 return std::numeric_limits<size_t>::max();
261 auto *first =
static_cast<std::uint8_t *
>(
buffer.
data());
262 auto *last = first +
size();
265 std::fill(first, last, 0);
287template <
bool Borrowed>
293 : v_{
std::move(v)}, caps_{caps} {}
295 constexpr size_t size() const noexcept {
return v_.value().size(); }
300 return std::numeric_limits<size_t>::max();
310 std::copy_n(
reinterpret_cast<const std::byte *
>(v_.value().data()),
size(),
322 return std::make_pair(
338template <
bool Borrowed>
341 template <
class Accumulator>
360 return std::numeric_limits<size_t>::max();
367 auto var_string_len_res = accu.template step<borrowable::wire::VarInt>();
371 auto var_string_res =
372 accu.template step<borrowable::wire::String<Borrowed>>(
373 var_string_len_res->value());
388template <
bool Borrowed>
391 Codec<borrowable::wire::NulTermString<Borrowed>>> {
392 template <
class Accumulator>
394 return accu.template step<borrowable::wire::String<Borrowed>>(v_)
411 return std::numeric_limits<size_t>::max();
418 const auto *first =
static_cast<const uint8_t *
>(
buffer.
data());
421 const auto *pos =
std::find(first, last,
'\0');
433 return std::make_pair(len + 1,
constexpr Codec(value_type v, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:59
static constexpr size_t max_size() noexcept
maximum bytes which may scanned by the decoder.
Definition: classic_protocol_codec_wire.h:90
stdx::expected< size_t, std::error_code > encode(net::mutable_buffer buffer) const
encode value_type into buffer.
Definition: classic_protocol_codec_wire.h:69
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:92
const value_type v_
Definition: classic_protocol_codec_wire.h:112
static constexpr size_t size() noexcept
size of the encoded object.
Definition: classic_protocol_codec_wire.h:64
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_wire.h:393
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:414
friend base_type
Definition: classic_protocol_codec_wire.h:403
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:408
const value_type v_
Definition: classic_protocol_codec_wire.h:439
constexpr Codec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:405
Codec(value_type, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:218
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:221
const capabilities::value_type caps_
Definition: classic_protocol_codec_wire.h:329
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:292
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:316
stdx::expected< size_t, std::error_code > encode(const net::mutable_buffer &buffer) const
Definition: classic_protocol_codec_wire.h:303
constexpr size_t size() const noexcept
Definition: classic_protocol_codec_wire.h:295
const value_type v_
Definition: classic_protocol_codec_wire.h:328
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:297
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:166
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_wire.h:139
const value_type v_
Definition: classic_protocol_codec_wire.h:204
friend __base
Definition: classic_protocol_codec_wire.h:164
static constexpr size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:169
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_wire.h:171
const value_type v_
Definition: classic_protocol_codec_wire.h:382
constexpr Codec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:354
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_wire.h:342
friend base_type
Definition: classic_protocol_codec_wire.h:352
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_wire.h:363
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:357
Codec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:247
size_t size() const noexcept
Definition: classic_protocol_codec_wire.h:249
static stdx::expected< std::pair< size_t, value_type >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:270
stdx::expected< size_t, std::error_code > encode(const net::mutable_buffer &buffer) const
Definition: classic_protocol_codec_wire.h:255
const capabilities::value_type caps_
Definition: classic_protocol_codec_wire.h:279
const value_type v_
Definition: classic_protocol_codec_wire.h:278
size_t value_type
Definition: classic_protocol_codec_wire.h:245
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:251
Codec for a type.
Definition: classic_protocol_codec_base.h:72
Definition: classic_protocol_wire.h:106
Definition: classic_protocol_wire.h:112
Definition: classic_protocol_wire.h:118
Definition: classic_protocol_wire.h:130
Definition: classic_protocol_wire.h:103
Definition: classic_protocol_wire.h:59
Definition: classic_protocol_wire.h:135
Definition: classic_protocol_wire.h:38
Definition: classic_protocol_wire.h:97
Definition: classic_protocol_wire.h:65
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
void * data() const noexcept
Definition: buffer.h:119
size_t size() const noexcept
Definition: buffer.h:120
constexpr const error_type & error() const &
Definition: expected.h:760
constexpr value_type & value() &
Definition: expected.h:645
Definition: expected.h:112
constexpr DWORD buf_size
Definition: create_def.cc:229
unsigned char byte
Blob class.
Definition: common.h:151
uint16_t value_type
Definition: vt100.h:184
borrowable::binary::Null Null
Definition: classic_protocol_binary.h:337
borrowable::wire::FixedInt< Size > FixedInt
Definition: classic_protocol_wire.h:147
borrowable::wire::VarInt VarInt
Definition: classic_protocol_wire.h:148
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
Definition: classic_protocol_binary.h:39
std::error_code make_error_code(codec_errc e) noexcept
Definition: classic_protocol_codec_error.h:86
bool distance(const dd::Spatial_reference_system *srs, const Geometry *g1, const Geometry *g2, double *distance, bool *is_null) noexcept
Computes the distance between two geometries.
Definition: distance.cc:40
Container::const_iterator find(const Container &c, Value &&value)
Definition: generic.h:39
size_t size(const char *const c)
Definition: base64.h:46
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
Definition: gcs_xcom_synode.h:64
unexpected(E) -> unexpected< E >
constexpr T byteswap(T num) noexcept
Definition: bit.h:52