26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_WIRE_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_WIRE_H_
34#include <system_error>
54 static constexpr size_t int_size{IntSize};
63 static constexpr size_t size() noexcept {
return int_size; }
74 auto int_val = v_.value();
80 std::copy_n(
reinterpret_cast<const std::byte *
>(&int_val), int_size,
89 static constexpr size_t max_size() noexcept {
return int_size; }
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};
228 const uint8_t nul_val = *
static_cast<const uint8_t *
>(
buffer.
data());
230 if (nul_val != nul_byte) {
250 size_t size() const noexcept {
return v_; }
253 return std::numeric_limits<size_t>::max();
262 auto *first =
static_cast<std::uint8_t *
>(
buffer.
data());
263 auto *
last = first + size();
266 std::fill(first,
last, 0);
288template <
bool Borrowed>
294 : v_{
std::move(v)}, caps_{caps} {}
296 constexpr size_t size() const noexcept {
return v_.value().size(); }
301 return std::numeric_limits<size_t>::max();
311 std::copy_n(
reinterpret_cast<const std::byte *
>(v_.value().data()), size(),
323 return std::make_pair(
339template <
bool Borrowed>
342 template <
class Accumulator>
361 return std::numeric_limits<size_t>::max();
368 auto var_string_len_res = accu.template step<borrowable::wire::VarInt>();
372 auto var_string_res =
373 accu.template step<borrowable::wire::String<Borrowed>>(
374 var_string_len_res->value());
389template <
bool Borrowed>
392 Codec<borrowable::wire::NulTermString<Borrowed>>> {
393 template <
class Accumulator>
395 return accu.template step<borrowable::wire::String<Borrowed>>(v_)
412 return std::numeric_limits<size_t>::max();
419 const auto *first =
static_cast<const uint8_t *
>(
buffer.
data());
435 return std::make_pair(len + 1,
constexpr Codec(value_type v, capabilities::value_type)
Definition: classic_protocol_codec_wire.h:58
static constexpr size_t max_size() noexcept
maximum bytes which may scanned by the decoder.
Definition: classic_protocol_codec_wire.h:89
stdx::expected< size_t, std::error_code > encode(net::mutable_buffer buffer) const
encode value_type into buffer.
Definition: classic_protocol_codec_wire.h:68
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:91
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:63
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_wire.h:394
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:415
friend base_type
Definition: classic_protocol_codec_wire.h:404
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:409
const value_type v_
Definition: classic_protocol_codec_wire.h:441
constexpr Codec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:406
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:330
constexpr Codec(value_type v, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:293
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:317
stdx::expected< size_t, std::error_code > encode(const net::mutable_buffer &buffer) const
Definition: classic_protocol_codec_wire.h:304
constexpr size_t size() const noexcept
Definition: classic_protocol_codec_wire.h:296
const value_type v_
Definition: classic_protocol_codec_wire.h:329
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:298
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:383
constexpr Codec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:355
constexpr auto accumulate_fields(Accumulator &&accu) const
Definition: classic_protocol_codec_wire.h:343
friend base_type
Definition: classic_protocol_codec_wire.h:353
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:364
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:358
Codec(value_type val, capabilities::value_type caps)
Definition: classic_protocol_codec_wire.h:248
size_t size() const noexcept
Definition: classic_protocol_codec_wire.h:250
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:271
stdx::expected< size_t, std::error_code > encode(const net::mutable_buffer &buffer) const
Definition: classic_protocol_codec_wire.h:256
const capabilities::value_type caps_
Definition: classic_protocol_codec_wire.h:280
const value_type v_
Definition: classic_protocol_codec_wire.h:279
size_t value_type
Definition: classic_protocol_codec_wire.h:246
static size_t max_size() noexcept
Definition: classic_protocol_codec_wire.h:252
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:375
void * data() const noexcept
Definition: buffer.h:119
size_t size() const noexcept
Definition: buffer.h:120
constexpr const value_type & value() const &
Definition: expected.h:688
constexpr const error_type & error() const &
Definition: expected.h:737
constexpr DWORD buf_size
Definition: create_def.cc:228
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
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:3564
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
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:315
Definition: gcs_xcom_synode.h:64
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:125
constexpr std::enable_if_t< std::is_integral< IntegerType >::value, IntegerType > byteswap(IntegerType t) noexcept
Definition: bit.h:142