17 template <
typename In>
20 auto& request_body = ctx->get_request_body();
21 auto request_content_type =
22 ctx->get_request_header(http::headers::CONTENT_TYPE);
24 auto data = request_body.data();
25 auto size = request_body.size();
27 if (request_content_type != http::headervalues::contenttype::GRPC)
30 HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
31 ccf::errors::UnsupportedContentType,
33 "Unsupported content type. Only {} is supported ",
34 http::headervalues::contenttype::GRPC));
39 using Message =
typename In::value_type;
43 const auto message_length = impl::read_message_frame(data, size);
44 if (message_length > size)
46 throw std::logic_error(fmt::format(
47 "Error in gRPC frame: only {} bytes remaining but message header "
48 "says messages is {} bytes",
53 Message& msg = messages.emplace_back();
54 if (!msg.ParseFromArray(data, message_length))
56 throw std::logic_error(fmt::format(
57 "Error deserialising protobuf payload of type {}, size {} (message "
64 data += message_length;
65 size -= message_length;
71 const auto message_length = impl::read_message_frame(data, size);
72 if (size != message_length)
74 throw std::logic_error(fmt::format(
75 "Error in gRPC frame: frame size is {} but messages is {} bytes",
81 if (!in.ParseFromArray(data, message_length))
83 throw std::logic_error(fmt::format(
84 "Error deserialising protobuf payload of type {}, size {}",
93 const std::shared_ptr<ccf::RpcContext>& ctx)
95 for (
auto const& h : default_response_headers)
97 ctx->set_response_header(h.first, h.second);
102 const std::shared_ptr<ccf::RpcContext>& ctx,
103 const ccf::protobuf::Status& status)
105 ctx->set_response_trailer(make_status_trailer(status.code()));
106 ctx->set_response_trailer(make_message_trailer(status.message()));
109 template <
typename Out>
112 const std::shared_ptr<ccf::RpcContext>& ctx)
118 std::vector<uint8_t> v;
122 v = serialise_grpc_messages(success_response->body);
126 v = serialise_grpc_message(success_response->body);
129 ctx->set_response_body(v);
133 else if (std::get_if<ErrorResponse>(&r))
135 auto error_response = std::get<ErrorResponse>(r);
144 template <
typename In,
typename Out>
148 template <
typename In,
typename Out>
152 template <
typename In,
typename Out>
156 template <
typename In,
typename Out>
161 template <
typename In,
typename Out>
165 grpc::set_grpc_response<Out>(
166 f(ctx, grpc::get_grpc_payload<In>(ctx.rpc_ctx)), ctx.rpc_ctx);
170 template <
typename In,
typename Out>
175 grpc::set_grpc_response<Out>(
176 f(ctx, grpc::get_grpc_payload<In>(ctx.rpc_ctx)), ctx.rpc_ctx);
180 template <
typename In,
typename Out>
185 grpc::set_grpc_response<Out>(
186 f(ctx, grpc::get_grpc_payload<In>(ctx.rpc_ctx)), ctx.rpc_ctx);
192 template <
typename In,
typename Out>
200 grpc::get_grpc_payload<In>(ctx.rpc_ctx),
201 grpc::make_stream<Out>(ctx.rpc_ctx));
203 if (
auto error_response = std::get_if<grpc::ErrorResponse>(&result))
std::function< void(CommandEndpointContext &args)> CommandEndpointFunction
Definition endpoint_context.h:52
std::function< void(ReadOnlyEndpointContext &args)> ReadOnlyEndpointFunction
Definition endpoint_context.h:80
std::function< void(EndpointContext &args)> EndpointFunction
Definition endpoint_context.h:63
Definition grpc_status.h:98
void set_grpc_default_headers(const std::shared_ptr< ccf::RpcContext > &ctx)
Definition grpc.h:92
std::unique_ptr< Stream< T > > StreamPtr
Definition stream.h:114
In get_grpc_payload(const std::shared_ptr< ccf::RpcContext > &ctx)
Definition grpc.h:18
std::variant< ErrorResponse, SuccessResponse< T > > GrpcAdapterResponse
Definition types.h:34
std::variant< ErrorResponse, PendingResponse > GrpcAdapterStreamingResponse
Definition types.h:42
void set_grpc_response(const GrpcAdapterResponse< Out > &r, const std::shared_ptr< ccf::RpcContext > &ctx)
Definition grpc.h:110
void set_grpc_response_trailers(const std::shared_ptr< ccf::RpcContext > &ctx, const ccf::protobuf::Status &status)
Definition grpc.h:101
Definition app_interface.h:15
std::function< grpc::GrpcAdapterResponse< Out >(endpoints::ReadOnlyEndpointContext &, In &&)> GrpcReadOnlyEndpoint
Definition grpc.h:150
endpoints::EndpointFunction grpc_adapter(const GrpcEndpoint< In, Out > &f)
Definition grpc.h:162
std::function< grpc::GrpcAdapterResponse< Out >(endpoints::EndpointContext &, In &&)> GrpcEndpoint
Definition grpc.h:146
std::function< grpc::GrpcAdapterStreamingResponse(endpoints::CommandEndpointContext &, In &&, grpc::StreamPtr< Out > &&)> GrpcCommandUnaryStreamEndpoint
Definition grpc.h:159
endpoints::CommandEndpointFunction grpc_command_adapter(const GrpcCommandEndpoint< In, Out > &f)
Definition grpc.h:181
endpoints::ReadOnlyEndpointFunction grpc_read_only_adapter(const GrpcReadOnlyEndpoint< In, Out > &f)
Definition grpc.h:171
std::function< grpc::GrpcAdapterResponse< Out >(endpoints::CommandEndpointContext &, In &&)> GrpcCommandEndpoint
Definition grpc.h:154
endpoints::CommandEndpointFunction grpc_command_unary_stream_adapter(const GrpcCommandUnaryStreamEndpoint< In, Out > &f)
Definition grpc.h:193
Definition rpc_exception.h:13
Definition endpoint_context.h:24
Definition endpoint_context.h:55
Definition endpoint_context.h:70