25#ifndef ROUTING_CLASSIC_FRAME_INCLUDED
26#define ROUTING_CLASSIC_FRAME_INCLUDED
28#include <system_error>
71 auto num_of_frames = *read_res;
72 if (num_of_frames > 1) {
81 while (!frame_sequence_buf.empty()) {
83 classic_protocol::decode<classic_protocol::frame::Header>(
89 frame_sequence_buf.last(frame_sequence_buf.size() - hdr_res->first);
92 frame_sequence_buf.first(hdr_res->second.payload_size());
94 payload_buf.insert(payload_buf.end(), frame_payload.begin(),
97 frame_sequence_buf = frame_sequence_buf.last(
98 frame_sequence_buf.size() - hdr_res->second.payload_size());
102 classic_protocol::decode<Msg>(
net::buffer(payload_buf), caps);
105 return decode_res->second;
110 classic_protocol::decode<classic_protocol::frame::Frame<Msg>>(
114 return decode_res->second.payload();
121 return recv_msg<Msg>(src_channel, src_protocol,
131 std::forward<Msg>(msg)),
133 if (!encode_res)
return encode_res;
141 return send_msg<Msg>(dst_channel, dst_protocol, std::forward<Msg>(msg),
185 const auto &recv_buf = src_channel->recv_plain_view();
190 if (!frame_decode_res) {
194 src_protocol->seq_id(frame_decode_res->second.seq_id());
196 auto decode_res = classic_protocol::decode<msg_type>(
197 net::buffer(frame_decode_res->second.payload().value()), caps,
198 [src_protocol](
auto stmt_id)
199 ->
stdx::expected<std::vector<msg_type::ParamDef>, std::error_code> {
200 const auto it = src_protocol->prepared_statements().find(stmt_id);
201 if (it == src_protocol->prepared_statements().end()) {
202 return stdx::make_unexpected(make_error_code(
203 classic_protocol::codec_errc::statement_id_not_found));
206 std::vector<msg_type::ParamDef> params;
207 params.reserve(it->second.parameters.size());
209 for (
const auto ¶m : it->second.parameters) {
210 params.emplace_back(param.type_and_flags, std::string_view{},
211 param.param_already_sent);
218 return decode_res->second;
SSL aware socket buffers.
Definition: channel.h:63
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:256
recv_buffer_type & send_plain_buffer()
unencrypted data to be sent to the socket.
Definition: channel.cc:276
const recv_view_type & recv_plain_view() const
decrypted data after a recv().
Definition: channel.cc:282
Definition: classic_frame.h:34
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:44
static stdx::expected< Msg, std::error_code > recv_msg(Channel *src_channel, ClassicProtocolState *src_protocol)
Definition: classic_frame.h:119
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:127
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:126
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:172
static constexpr uint8_t cmd_byte()
Definition: classic_frame.h:56
static stdx::expected< size_t, std::error_code > send_msg(Channel *dst_channel, ClassicProtocolState *dst_protocol, Msg msg)
Definition: classic_frame.h:139
static void trace_set_attributes(TraceEvent *ev, ClassicProtocolState *src_protocol, const classic_protocol::borrowed::message::server::Ok &msg)
set attributes from the Ok message in the TraceEvent.
Definition: classic_frame.cc:278
static stdx::expected< Msg, std::error_code > recv_msg(Channel *src_channel, ClassicProtocolState *src_protocol, classic_protocol::capabilities::value_type caps)
receive a classic protocol message frame from a channel.
Definition: classic_frame.h:64
static stdx::expected< void, std::error_code > ensure_has_full_frame(Channel *src_channel, ClassicProtocolState *src_protocol)
Definition: classic_frame.cc:152
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_connection_base.h:54
uint8_t & seq_id()
Definition: classic_connection_base.h:113
classic_protocol::capabilities::value_type shared_capabilities() const
Definition: classic_connection_base.h:89
Codec for a type.
Definition: classic_protocol_codec_base.h:71
execute a prepared statement.
Definition: classic_protocol_message.h:1089
Definition: classic_protocol_frame.h:84
Definition: expected.h:943
borrowable::message::client::StmtExecute< true > StmtExecute
Definition: classic_protocol_message.h:1487
borrowable::message::server::Eof< true > Eof
Definition: classic_protocol_message.h:1459
borrowable::message::server::Error< true > Error
Definition: classic_protocol_message.h:1458
borrowable::message::server::Ok< true > Ok
Definition: classic_protocol_message.h:1457
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:72
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:83
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:118
dynamic_vector_buffer< T, Allocator > dynamic_buffer(std::vector< T, Allocator > &vec) noexcept
Definition: buffer.h:660
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:417
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:124
Definition: trace_span.h:34