9#include <grpcpp/support/status.h>
11#include <userver/utils/assert.hpp>
13USERVER_NAMESPACE_BEGIN
15namespace ugrpc::server {
24template <
typename Response>
29 : result_{std::move(response)}
34 : result_{std::move(status)}
36 UINVARIANT(!GetErrorStatus().ok(),
"Only error status is allowed, for OK status a response should be provided");
43 UINVARIANT(!GetErrorStatus().ok(),
"Only error status is allowed, for OK status a response should be provided");
47 bool IsSuccess()
const {
return std::holds_alternative<Response>(result_); }
52 UINVARIANT(!IsSuccess(),
"ExtractErrorStatus is only allowed in case of error status");
53 return std::move(std::get<grpc::Status>(result_));
59 UINVARIANT(!IsSuccess(),
"GetErrorStatus is only allowed in case of error status");
60 return std::get<grpc::Status>(result_);
66 UINVARIANT(IsSuccess(),
"ExtractResponse is only allowed in case of OK status");
67 return std::get<Response>(std::move(result_));
73 UINVARIANT(IsSuccess(),
"GetResponse is only allowed in case of OK status");
74 return std::get<Response>(result_);
78 std::variant<Response, grpc::Status> result_;
89template <
typename Response>
90class StreamingResult final {
94 : status_{std::move(status)}
104 : last_response_(std::move(last_response))
114 const grpc::Status&
GetStatus()
const {
return status_; }
122 UINVARIANT(HasLastResponse(),
"There is no last response in the StreamingResult");
123 return std::move(last_response_).value();
129 UINVARIANT(HasLastResponse(),
"There is no last response in the StreamingResult");
130 return last_response_.value();
134 std::optional<Response> last_response_;
135 grpc::Status status_{grpc::Status::OK};