26#ifndef ROUTING_CLASSIC_FRAME_INCLUDED
27#define ROUTING_CLASSIC_FRAME_INCLUDED
29#include <system_error>
41 template <
class Proto>
51 template <
class Proto>
69 template <
class Proto>
83 template <
class Msg,
class Proto>
85 Channel &src_channel, Proto &src_protocol,
91 auto num_of_frames = *read_res;
92 if (num_of_frames > 1) {
101 while (!frame_sequence_buf.empty()) {
103 classic_protocol::decode<classic_protocol::frame::Header>(
109 frame_sequence_buf.last(frame_sequence_buf.size() - hdr_res->first);
112 frame_sequence_buf.first(hdr_res->second.payload_size());
114 payload_buf.insert(payload_buf.end(), frame_payload.begin(),
115 frame_payload.end());
117 frame_sequence_buf = frame_sequence_buf.last(
118 frame_sequence_buf.size() - hdr_res->second.payload_size());
122 classic_protocol::decode<Msg>(
net::buffer(payload_buf), caps);
125 return decode_res->second;
130 classic_protocol::decode<classic_protocol::frame::Frame<Msg>>(
134 return decode_res->second.payload();
138 template <
class Msg,
class Proto>
140 Channel &src_channel, Proto &src_protocol) {
141 return recv_msg<Msg>(src_channel, src_protocol,
142 src_protocol.shared_capabilities());
145 template <
class Msg,
class Proto>
157 template <
class Msg,
class Proto>
161 std::is_same_v<Proto, ClientSideClassicProtocolState>))
163 Channel &src_channel, Proto &src_protocol,
171 auto frame_decode_res =
175 if (!frame_decode_res) {
179 src_protocol.seq_id(frame_decode_res->second.seq_id());
181 auto decode_res = classic_protocol::decode<Msg>(
182 net::buffer(frame_decode_res->second.payload().value()), caps,
184 auto stmt_id) ->
stdx::expected<std::vector<typename Msg::ParamDef>,
186 const auto it = src_protocol.prepared_statements().find(stmt_id);
187 if (it == src_protocol.prepared_statements().end()) {
188 return stdx::unexpected(make_error_code(
189 classic_protocol::codec_errc::statement_id_not_found));
192 std::vector<typename Msg::ParamDef> params;
193 params.reserve(it->second.parameters.size());
195 for (
const auto ¶m : it->second.parameters) {
196 params.emplace_back(param.type_and_flags, std::string_view{},
197 param.param_already_sent);
204 return decode_res->second;
213 std::forward<Msg>(msg)),
215 if (!encode_res)
return encode_res;
223 return send_msg<Msg>(dst_channel, dst_protocol, std::forward<Msg>(msg),
227 template <
class Msg,
class Proto>
232 std::forward<Msg>(msg), caps);
235 template <
class Msg,
class Proto>
239 std::forward<Msg>(msg));
245 static void trace_set_attributes(
252 static void trace_set_attributes(
259 static void trace_set_attributes(
SSL aware socket buffers.
Definition: channel.h:65
stdx::expected< size_t, std::error_code > flush_to_send_buf()
flush data to the send buffer.
Definition: channel.cc:151
const recv_buffer_type & payload_buffer() const
payload buffer for
Definition: channel.h:273
recv_buffer_type & send_plain_buffer()
unencrypted data to be sent to the socket.
Definition: channel.cc:275
const recv_view_type & recv_plain_view() const
decrypted data after a recv().
Definition: channel.cc:281
Definition: classic_frame.h:36
static stdx::expected< void, std::error_code > ensure_frame_header(TlsSwitchableConnection< Proto > &conn)
Definition: classic_frame.h:70
static stdx::expected< Msg, std::error_code > recv_msg(TlsSwitchableConnection< Proto > &conn)
Definition: classic_frame.h:146
static stdx::expected< void, std::error_code > ensure_has_full_frame(TlsSwitchableConnection< Proto > &conn)
Definition: classic_frame.h:53
static stdx::expected< size_t, std::error_code > recv_frame_sequence(Channel &src_channel, ClassicProtocolState &src_protocol)
recv a full message sequence into the channel's recv_plain_buffer()
Definition: classic_frame.cc:178
static stdx::expected< void, std::error_code > ensure_has_full_frame(Channel &src_channel, ClassicProtocolState &src_protocol)
Definition: classic_frame.cc:158
static stdx::expected< Msg, std::error_code > recv_msg(Channel &src_channel, Proto &src_protocol, classic_protocol::capabilities::value_type caps)
receive a StmtExecute message from a channel.
Definition: classic_frame.h:162
static stdx::expected< size_t, std::error_code > send_msg(TlsSwitchableConnection< Proto > &conn, Msg msg)
Definition: classic_frame.h:236
static stdx::expected< void, std::error_code > ensure_has_msg_prefix(Channel &src_channel, ClassicProtocolState &src_protocol)
ensure message has a frame-header and msg-type.
Definition: classic_frame.cc:46
static stdx::expected< Msg, std::error_code > recv_msg(Channel &src_channel, Proto &src_protocol, classic_protocol::capabilities::value_type caps)
receive a classic protocol message frame from a channel.
Definition: classic_frame.h:84
static constexpr uint8_t cmd_byte()
Definition: classic_frame.h:76
static stdx::expected< void, std::error_code > ensure_has_msg_prefix(TlsSwitchableConnection< Proto > &conn)
Definition: classic_frame.h:42
static stdx::expected< size_t, std::error_code > send_msg(TlsSwitchableConnection< Proto > &conn, Msg msg, classic_protocol::capabilities::value_type caps)
Definition: classic_frame.h:228
static stdx::expected< size_t, std::error_code > send_msg(Channel &dst_channel, ClassicProtocolState &dst_protocol, Msg msg)
Definition: classic_frame.h:221
static stdx::expected< void, std::error_code > ensure_frame_header(Channel &src_channel, ClassicProtocolState &src_protocol)
ensure current_frame() has a current frame-info.
Definition: classic_frame.cc:133
static stdx::expected< Msg, std::error_code > recv_msg(Channel &src_channel, Proto &src_protocol)
Definition: classic_frame.h:139
static stdx::expected< size_t, std::error_code > send_msg(Channel &dst_channel, ClassicProtocolState &dst_protocol, Msg msg, classic_protocol::capabilities::value_type caps)
Definition: classic_frame.h:208
static stdx::expected< void, std::error_code > ensure_server_greeting(Channel &src_channel, ClassicProtocolState &src_protocol)
protocol state of a classic protocol connection.
Definition: classic_protocol_state.h:39
uint8_t & seq_id()
Definition: classic_protocol_state.h:197
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_protocol_state.h:173
a Connection that can be switched to TLS.
Definition: connection_base.h:264
Channel & channel()
Definition: connection_base.h:359
protocol_state_type & protocol()
Definition: connection_base.h:398
Codec for a type.
Definition: classic_protocol_codec_base.h:72
execute a prepared statement.
Definition: classic_protocol_message.h:1090
Definition: classic_protocol_wire.h:38
Definition: classic_protocol_frame.h:85
Definition: expected.h:284
borrowable::message::server::Eof< true > Eof
Definition: classic_protocol_message.h:1460
borrowable::message::server::Error< true > Error
Definition: classic_protocol_message.h:1459
borrowable::message::server::Ok< true > Ok
Definition: classic_protocol_message.h:1458
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
stdx::expected< size_t, std::error_code > encode(const T &v, capabilities::value_type caps, DynamicBuffer &&dyn_buffer)
encode a message into a dynamic buffer.
Definition: classic_protocol_codec_base.h:84
stdx::expected< std::pair< size_t, T >, std::error_code > decode(const net::const_buffer &buffer, capabilities::value_type caps)
decode a message from a buffer.
Definition: classic_protocol_codec_base.h:119
dynamic_vector_buffer< T, Allocator > dynamic_buffer(std::vector< T, Allocator > &vec) noexcept
Definition: buffer.h:661
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
unexpected(E) -> unexpected< E >
Definition: trace_span.h:35