summaryrefslogtreecommitdiffstats
path: root/contrib/libs/grpc/src/cpp
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2026-04-09 01:21:00 +0300
committerrobot-piglet <[email protected]>2026-04-09 01:51:01 +0300
commit8b606c1cb8b52fceea3389eb37cf6e2bc03dc8f7 (patch)
tree7bc31bbff5b6b97285777da2a14804b5031106a5 /contrib/libs/grpc/src/cpp
parentf1d1502648b4322e2bd8b17d5a0acb3c9c336ccf (diff)
Intermediate changes
commit_hash:76db5b7b9603e9e5fc9ff87d2d98c79b83742b0a
Diffstat (limited to 'contrib/libs/grpc/src/cpp')
-rw-r--r--contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc124
-rw-r--r--contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h107
-rw-r--r--contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc31
3 files changed, 157 insertions, 105 deletions
diff --git a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc
index 8fea1c5b680..15867b38398 100644
--- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc
+++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.cc
@@ -23,58 +23,41 @@
#include <grpcpp/grpcpp.h>
#include <grpcpp/support/interceptor.h>
+#include <grpcpp/support/sync_stream.h>
// IWYU pragma: no_include "google/protobuf/descriptor.h"
// IWYU pragma: no_include <google/protobuf/descriptor.h>
-
-using grpc::reflection::v1alpha::ErrorResponse;
-using grpc::reflection::v1alpha::ExtensionNumberResponse;
-using grpc::reflection::v1alpha::ExtensionRequest;
-using grpc::reflection::v1alpha::ListServiceResponse;
-using grpc::reflection::v1alpha::ServerReflectionRequest;
-using grpc::reflection::v1alpha::ServerReflectionResponse;
-using grpc::reflection::v1alpha::ServiceResponse;
+// IWYU pragma: no_include "src/proto/grpc/reflection/v1/reflection.pb.h"
+// IWYU pragma: no_include "src/proto/grpc/reflection/v1alpha/reflection.pb.h"
namespace grpc {
-ProtoServerReflection::ProtoServerReflection()
- : descriptor_pool_(protobuf::DescriptorPool::generated_pool()) {}
-
-void ProtoServerReflection::SetServiceList(
- const std::vector<TString>* services) {
- services_ = services;
-}
-
-Status ProtoServerReflection::ServerReflectionInfo(
- ServerContext* context,
- ServerReaderWriter<ServerReflectionResponse, ServerReflectionRequest>*
- stream) {
- ServerReflectionRequest request;
- ServerReflectionResponse response;
+template <typename Request, typename Response>
+Status ProtoServerReflectionBackend::ServerReflectionInfo(
+ ServerReaderWriter<Response, Request>* stream) const {
+ Request request;
+ Response response;
Status status;
while (stream->Read(&request)) {
switch (request.message_request_case()) {
- case ServerReflectionRequest::MessageRequestCase::kFileByFilename:
- status = GetFileByName(context, request.file_by_filename(), &response);
+ case Request::MessageRequestCase::kFileByFilename:
+ status = GetFileByName(request.file_by_filename(), &response);
break;
- case ServerReflectionRequest::MessageRequestCase::kFileContainingSymbol:
- status = GetFileContainingSymbol(
- context, request.file_containing_symbol(), &response);
+ case Request::MessageRequestCase::kFileContainingSymbol:
+ status = GetFileContainingSymbol(request.file_containing_symbol(),
+ &response);
break;
- case ServerReflectionRequest::MessageRequestCase::
- kFileContainingExtension:
+ case Request::MessageRequestCase::kFileContainingExtension:
status = GetFileContainingExtension(
- context, &request.file_containing_extension(), &response);
+ &request.file_containing_extension(), &response);
break;
- case ServerReflectionRequest::MessageRequestCase::
- kAllExtensionNumbersOfType:
+ case Request::MessageRequestCase::kAllExtensionNumbersOfType:
status = GetAllExtensionNumbers(
- context, request.all_extension_numbers_of_type(),
+ request.all_extension_numbers_of_type(),
response.mutable_all_extension_numbers_response());
break;
- case ServerReflectionRequest::MessageRequestCase::kListServices:
- status =
- ListService(context, response.mutable_list_services_response());
+ case Request::MessageRequestCase::kListServices:
+ status = ListService(response.mutable_list_services_response());
break;
default:
status = Status(StatusCode::UNIMPLEMENTED, "");
@@ -84,41 +67,40 @@ Status ProtoServerReflection::ServerReflectionInfo(
FillErrorResponse(status, response.mutable_error_response());
}
response.set_valid_host(request.host());
- response.set_allocated_original_request(
- new ServerReflectionRequest(request));
+ response.set_allocated_original_request(new Request(request));
stream->Write(response);
}
-
return Status::OK;
}
-void ProtoServerReflection::FillErrorResponse(const Status& status,
- ErrorResponse* error_response) {
+template <typename Response>
+void ProtoServerReflectionBackend::FillErrorResponse(
+ const Status& status, Response* error_response) const {
error_response->set_error_code(status.error_code());
error_response->set_error_message(status.error_message());
}
-Status ProtoServerReflection::ListService(ServerContext* /*context*/,
- ListServiceResponse* response) {
+template <typename Response>
+Status ProtoServerReflectionBackend::ListService(Response* response) const {
if (services_ == nullptr) {
return Status(StatusCode::NOT_FOUND, "Services not found.");
}
for (const auto& value : *services_) {
- ServiceResponse* service_response = response->add_service();
+ auto* service_response = response->add_service();
service_response->set_name(value);
}
return Status::OK;
}
-Status ProtoServerReflection::GetFileByName(
- ServerContext* /*context*/, const TString& file_name,
- ServerReflectionResponse* response) {
+template <typename Response>
+Status ProtoServerReflectionBackend::GetFileByName(const TString& file_name,
+ Response* response) const {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
const protobuf::FileDescriptor* file_desc =
- descriptor_pool_->FindFileByName(file_name);
+ descriptor_pool_->FindFileByName(TProtoStringType(file_name));
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "File not found.");
}
@@ -127,15 +109,15 @@ Status ProtoServerReflection::GetFileByName(
return Status::OK;
}
-Status ProtoServerReflection::GetFileContainingSymbol(
- ServerContext* /*context*/, const TString& symbol,
- ServerReflectionResponse* response) {
+template <typename Response>
+Status ProtoServerReflectionBackend::GetFileContainingSymbol(
+ const TString& symbol, Response* response) const {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
const protobuf::FileDescriptor* file_desc =
- descriptor_pool_->FindFileContainingSymbol(symbol);
+ descriptor_pool_->FindFileContainingSymbol(TProtoStringType(symbol));
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Symbol not found.");
}
@@ -144,9 +126,9 @@ Status ProtoServerReflection::GetFileContainingSymbol(
return Status::OK;
}
-Status ProtoServerReflection::GetFileContainingExtension(
- ServerContext* /*context*/, const ExtensionRequest* request,
- ServerReflectionResponse* response) {
+template <typename Request, typename Response>
+Status ProtoServerReflectionBackend::GetFileContainingExtension(
+ const Request* request, Response* response) const {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
@@ -168,15 +150,15 @@ Status ProtoServerReflection::GetFileContainingExtension(
return Status::OK;
}
-Status ProtoServerReflection::GetAllExtensionNumbers(
- ServerContext* /*context*/, const TString& type,
- ExtensionNumberResponse* response) {
+template <typename Response>
+Status ProtoServerReflectionBackend::GetAllExtensionNumbers(
+ const TString& type, Response* response) const {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
const protobuf::Descriptor* desc =
- descriptor_pool_->FindMessageTypeByName(type);
+ descriptor_pool_->FindMessageTypeByName(TProtoStringType(type));
if (desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Type not found.");
}
@@ -190,17 +172,17 @@ Status ProtoServerReflection::GetAllExtensionNumbers(
return Status::OK;
}
-void ProtoServerReflection::FillFileDescriptorResponse(
- const protobuf::FileDescriptor* file_desc,
- ServerReflectionResponse* response,
- std::unordered_set<TString>* seen_files) {
+template <typename Response>
+void ProtoServerReflectionBackend::FillFileDescriptorResponse(
+ const protobuf::FileDescriptor* file_desc, Response* response,
+ std::unordered_set<TString>* seen_files) const {
if (seen_files->find(file_desc->name()) != seen_files->end()) {
return;
}
seen_files->insert(file_desc->name());
protobuf::FileDescriptorProto file_desc_proto;
- TString data;
+ TProtoStringType data;
file_desc->CopyTo(&file_desc_proto);
file_desc_proto.SerializeToString(&data);
response->mutable_file_descriptor_response()->add_file_descriptor_proto(data);
@@ -210,4 +192,18 @@ void ProtoServerReflection::FillFileDescriptorResponse(
}
}
+Status ProtoServerReflection::ServerReflectionInfo(
+ ServerContext* /* context */,
+ ServerReaderWriter<reflection::v1alpha::ServerReflectionResponse,
+ reflection::v1alpha::ServerReflectionRequest>* stream) {
+ return backend_->ServerReflectionInfo(stream);
+}
+
+Status ProtoServerReflectionV1::ServerReflectionInfo(
+ ServerContext* /* context */,
+ ServerReaderWriter<reflection::v1::ServerReflectionResponse,
+ reflection::v1::ServerReflectionRequest>* stream) {
+ return backend_->ServerReflectionInfo(stream);
+}
+
} // namespace grpc
diff --git a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h
index a65c174d6d3..0d252c2ca80 100644
--- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h
+++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection.h
@@ -19,8 +19,11 @@
#ifndef GRPC_SRC_CPP_EXT_PROTO_SERVER_REFLECTION_H
#define GRPC_SRC_CPP_EXT_PROTO_SERVER_REFLECTION_H
-#include <string>
+#include <memory>
+#include <util/generic/string.h>
+#include <util/string/cast.h>
#include <unordered_set>
+#include <utility>
#include <vector>
#include <grpcpp/grpcpp.h>
@@ -29,18 +32,72 @@
#include <grpcpp/support/status.h>
#include <grpcpp/support/sync_stream.h>
+#include "src/proto/grpc/reflection/v1/reflection.grpc.pb.h"
+#include "src/proto/grpc/reflection/v1/reflection.pb.h"
#include "src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h"
#include "src/proto/grpc/reflection/v1alpha/reflection.pb.h"
namespace grpc {
+class ProtoServerReflectionBackend {
+ public:
+ ProtoServerReflectionBackend()
+ : descriptor_pool_(protobuf::DescriptorPool::generated_pool()) {}
+
+ void SetServiceList(const std::vector<TString>* services) {
+ services_ = services;
+ }
+
+ template <typename Request, typename Response>
+ Status ServerReflectionInfo(
+ ServerReaderWriter<Response, Request>* stream) const;
+
+ private:
+ template <typename Response>
+ Status ListService(Response* response) const;
+
+ template <typename Response>
+ Status GetFileByName(const TString& file_name, Response* response) const;
+
+ template <typename Response>
+ Status GetFileContainingSymbol(const TString& symbol,
+ Response* response) const;
+
+ template <typename Request, typename Response>
+ Status GetFileContainingExtension(const Request* request,
+ Response* response) const;
+
+ template <typename Response>
+ Status GetAllExtensionNumbers(const TString& type,
+ Response* response) const;
+
+ template <typename Response>
+ void FillFileDescriptorResponse(
+ const protobuf::FileDescriptor* file_desc, Response* response,
+ std::unordered_set<TString>* seen_files) const;
+
+ template <typename Response>
+ void FillErrorResponse(const Status& status, Response* error_response) const;
+
+ const protobuf::DescriptorPool* descriptor_pool_;
+ const std::vector<string>* services_;
+};
+
class ProtoServerReflection final
: public reflection::v1alpha::ServerReflection::Service {
public:
- ProtoServerReflection();
+ ProtoServerReflection()
+ : grpc::ProtoServerReflection(
+ std::make_shared<ProtoServerReflectionBackend>()) {}
+
+ explicit ProtoServerReflection(
+ std::shared_ptr<ProtoServerReflectionBackend> backend)
+ : backend_(std::move(backend)) {}
// Add the full names of registered services
- void SetServiceList(const std::vector<TString>* services);
+ void SetServiceList(const std::vector<TString>* services) {
+ backend_->SetServiceList(services);
+ }
// implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
// in ServerReflection service
@@ -50,36 +107,26 @@ class ProtoServerReflection final
reflection::v1alpha::ServerReflectionRequest>* stream)
override;
- private:
- Status ListService(ServerContext* context,
- reflection::v1alpha::ListServiceResponse* response);
-
- Status GetFileByName(ServerContext* context, const TString& file_name,
- reflection::v1alpha::ServerReflectionResponse* response);
-
- Status GetFileContainingSymbol(
- ServerContext* context, const TString& symbol,
- reflection::v1alpha::ServerReflectionResponse* response);
-
- Status GetFileContainingExtension(
- ServerContext* context,
- const reflection::v1alpha::ExtensionRequest* request,
- reflection::v1alpha::ServerReflectionResponse* response);
-
- Status GetAllExtensionNumbers(
- ServerContext* context, const TString& type,
- reflection::v1alpha::ExtensionNumberResponse* response);
+ std::shared_ptr<ProtoServerReflectionBackend> backend_;
+};
- void FillFileDescriptorResponse(
- const protobuf::FileDescriptor* file_desc,
- reflection::v1alpha::ServerReflectionResponse* response,
- std::unordered_set<TString>* seen_files);
+class ProtoServerReflectionV1 final
+ : public reflection::v1::ServerReflection::Service {
+ public:
+ explicit ProtoServerReflectionV1(
+ std::shared_ptr<ProtoServerReflectionBackend> backend)
+ : backend_(std::move(backend)) {}
- void FillErrorResponse(const Status& status,
- reflection::v1alpha::ErrorResponse* error_response);
+ // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
+ // in ServerReflection service
+ Status ServerReflectionInfo(
+ ServerContext* /* context */,
+ ServerReaderWriter<reflection::v1::ServerReflectionResponse,
+ reflection::v1::ServerReflectionRequest>* stream)
+ override;
- const protobuf::DescriptorPool* descriptor_pool_;
- const std::vector<string>* services_;
+ private:
+ std::shared_ptr<ProtoServerReflectionBackend> backend_;
};
} // namespace grpc
diff --git a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc
index 08c30186a95..c55705ee1c6 100644
--- a/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc
+++ b/contrib/libs/grpc/src/cpp/ext/proto_server_reflection_plugin.cc
@@ -16,6 +16,10 @@
//
//
+#include <memory>
+#include <util/generic/string.h>
+#include <util/string/cast.h>
+
#include <grpcpp/ext/proto_server_reflection_plugin.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/impl/server_initializer.h>
@@ -27,35 +31,40 @@ namespace grpc {
namespace reflection {
ProtoServerReflectionPlugin::ProtoServerReflectionPlugin()
- : reflection_service_(new grpc::ProtoServerReflection()) {}
+ : backend_(std::make_shared<ProtoServerReflectionBackend>()),
+ reflection_service_v1alpha_(
+ std::make_shared<ProtoServerReflection>(backend_)),
+ reflection_service_v1_(
+ std::make_shared<ProtoServerReflectionV1>(backend_)) {}
TString ProtoServerReflectionPlugin::name() {
return "proto_server_reflection";
}
void ProtoServerReflectionPlugin::InitServer(grpc::ServerInitializer* si) {
- si->RegisterService(reflection_service_);
+ si->RegisterService(reflection_service_v1_);
+ si->RegisterService(reflection_service_v1alpha_);
}
void ProtoServerReflectionPlugin::Finish(grpc::ServerInitializer* si) {
- reflection_service_->SetServiceList(si->GetServiceList());
+ backend_->SetServiceList(si->GetServiceList());
}
void ProtoServerReflectionPlugin::ChangeArguments(const TString& /*name*/,
void* /*value*/) {}
bool ProtoServerReflectionPlugin::has_sync_methods() const {
- if (reflection_service_) {
- return reflection_service_->has_synchronous_methods();
- }
- return false;
+ return (reflection_service_v1_ &&
+ reflection_service_v1_->has_synchronous_methods()) ||
+ (reflection_service_v1alpha_ &&
+ reflection_service_v1alpha_->has_synchronous_methods());
}
bool ProtoServerReflectionPlugin::has_async_methods() const {
- if (reflection_service_) {
- return reflection_service_->has_async_methods();
- }
- return false;
+ return (reflection_service_v1_ &&
+ reflection_service_v1_->has_async_methods()) ||
+ (reflection_service_v1alpha_ &&
+ reflection_service_v1alpha_->has_async_methods());
}
static std::unique_ptr<grpc::ServerBuilderPlugin> CreateProtoReflection() {