Use stream rpc to ensure all related requests go to a single server.

pull/6729/head
Yuchen Zeng 9 years ago
parent c84ed6813e
commit 0333a49afa
  1. 579
      extensions/include/grpc++/impl/reflection.grpc.pb.h
  2. 1830
      extensions/include/grpc++/impl/reflection.pb.h
  3. 89
      extensions/reflection/proto_server_reflection.cc
  4. 35
      extensions/reflection/proto_server_reflection.h
  5. 256
      extensions/reflection/reflection.grpc.pb.cc
  6. 3719
      extensions/reflection/reflection.pb.cc
  7. 141
      src/proto/grpc/reflection/v1alpha/reflection.proto
  8. 250
      test/cpp/util/proto_reflection_descriptor_database.cc
  9. 11
      test/cpp/util/proto_reflection_descriptor_database.h
  10. 45
      test/cpp/util/reflection_debug/reflection_client.cc
  11. 42
      tools/codegen/extensions/gen_reflection_proto.sh

@ -1,6 +1,72 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// Generated by the gRPC protobuf plugin.
// If you make any local change, they will be lost.
// source: reflection.proto
// Original file comments:
// Copyright 2016, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Service exported by server reflection
//
#ifndef GRPC_reflection_2eproto__INCLUDED
#define GRPC_reflection_2eproto__INCLUDED
@ -32,516 +98,78 @@ class ServerReflection GRPC_FINAL {
class StubInterface {
public:
virtual ~StubInterface() {}
virtual ::grpc::Status ListService(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::reflection::v1alpha::ListServiceResponse* response) = 0;
std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::ListServiceResponse>>
AsyncListService(::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::ListServiceResponse>>(
AsyncListServiceRaw(context, request, cq));
}
virtual ::grpc::Status GetFileByName(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) = 0;
std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>
AsyncGetFileByName(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>(
AsyncGetFileByNameRaw(context, request, cq));
}
virtual ::grpc::Status GetFileContainingSymbol(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) = 0;
std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>
AsyncGetFileContainingSymbol(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>(
AsyncGetFileContainingSymbolRaw(context, request, cq));
// The reflection service is structured as a bidirectional stream, ensuring
// all related requests go to a single server.
std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>> DescriptorDatabaseInfo(::grpc::ClientContext* context) {
return std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>>(DescriptorDatabaseInfoRaw(context));
}
virtual ::grpc::Status GetFileContainingExtension(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) = 0;
std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>
AsyncGetFileContainingExtension(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>(
AsyncGetFileContainingExtensionRaw(context, request, cq));
std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>> AsyncDescriptorDatabaseInfo(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>>(AsyncDescriptorDatabaseInfoRaw(context, cq, tag));
}
virtual ::grpc::Status GetAllExtensionNumbers(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response) = 0;
std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::ExtensionNumberResponse>>
AsyncGetAllExtensionNumbers(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::ExtensionNumberResponse>>(
AsyncGetAllExtensionNumbersRaw(context, request, cq));
}
private:
virtual ::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::ListServiceResponse>*
AsyncListServiceRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
AsyncGetFileByNameRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
AsyncGetFileContainingSymbolRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
AsyncGetFileContainingExtensionRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientAsyncResponseReaderInterface<
::grpc::reflection::v1alpha::ExtensionNumberResponse>*
AsyncGetAllExtensionNumbersRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::CompletionQueue* cq) = 0;
private:
virtual ::grpc::ClientReaderWriterInterface< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>* DescriptorDatabaseInfoRaw(::grpc::ClientContext* context) = 0;
virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>* AsyncDescriptorDatabaseInfoRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0;
};
class Stub GRPC_FINAL : public StubInterface {
public:
Stub(const std::shared_ptr<::grpc::ChannelInterface>& channel);
::grpc::Status ListService(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::reflection::v1alpha::ListServiceResponse* response)
GRPC_OVERRIDE;
std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ListServiceResponse>>
AsyncListService(::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ListServiceResponse>>(
AsyncListServiceRaw(context, request, cq));
Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel);
std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>> DescriptorDatabaseInfo(::grpc::ClientContext* context) {
return std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>>(DescriptorDatabaseInfoRaw(context));
}
::grpc::Status GetFileByName(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_OVERRIDE;
std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>
AsyncGetFileByName(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>(
AsyncGetFileByNameRaw(context, request, cq));
}
::grpc::Status GetFileContainingSymbol(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_OVERRIDE;
std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>
AsyncGetFileContainingSymbol(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>(
AsyncGetFileContainingSymbolRaw(context, request, cq));
}
::grpc::Status GetFileContainingExtension(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_OVERRIDE;
std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>
AsyncGetFileContainingExtension(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>>(
AsyncGetFileContainingExtensionRaw(context, request, cq));
}
::grpc::Status GetAllExtensionNumbers(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response)
GRPC_OVERRIDE;
std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ExtensionNumberResponse>>
AsyncGetAllExtensionNumbers(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::CompletionQueue* cq) {
return std::unique_ptr<::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ExtensionNumberResponse>>(
AsyncGetAllExtensionNumbersRaw(context, request, cq));
std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>> AsyncDescriptorDatabaseInfo(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>>(AsyncDescriptorDatabaseInfoRaw(context, cq, tag));
}
private:
std::shared_ptr<::grpc::ChannelInterface> channel_;
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ListServiceResponse>*
AsyncListServiceRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::CompletionQueue* cq) GRPC_OVERRIDE;
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
AsyncGetFileByNameRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::CompletionQueue* cq) GRPC_OVERRIDE;
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
AsyncGetFileContainingSymbolRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::CompletionQueue* cq) GRPC_OVERRIDE;
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
AsyncGetFileContainingExtensionRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::CompletionQueue* cq) GRPC_OVERRIDE;
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ExtensionNumberResponse>*
AsyncGetAllExtensionNumbersRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::CompletionQueue* cq) GRPC_OVERRIDE;
const ::grpc::RpcMethod rpcmethod_ListService_;
const ::grpc::RpcMethod rpcmethod_GetFileByName_;
const ::grpc::RpcMethod rpcmethod_GetFileContainingSymbol_;
const ::grpc::RpcMethod rpcmethod_GetFileContainingExtension_;
const ::grpc::RpcMethod rpcmethod_GetAllExtensionNumbers_;
std::shared_ptr< ::grpc::ChannelInterface> channel_;
::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>* DescriptorDatabaseInfoRaw(::grpc::ClientContext* context) GRPC_OVERRIDE;
::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>* AsyncDescriptorDatabaseInfoRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;
const ::grpc::RpcMethod rpcmethod_DescriptorDatabaseInfo_;
};
static std::unique_ptr<Stub> NewStub(
const std::shared_ptr<::grpc::ChannelInterface>& channel,
const ::grpc::StubOptions& options = ::grpc::StubOptions());
static std::unique_ptr<Stub> NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions());
class Service : public ::grpc::Service {
public:
Service();
virtual ~Service();
virtual ::grpc::Status ListService(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest* request,
::grpc::reflection::v1alpha::ListServiceResponse* response);
virtual ::grpc::Status GetFileByName(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response);
virtual ::grpc::Status GetFileContainingSymbol(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response);
virtual ::grpc::Status GetFileContainingExtension(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response);
virtual ::grpc::Status GetAllExtensionNumbers(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::TypeRequest* request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response);
// The reflection service is structured as a bidirectional stream, ensuring
// all related requests go to a single server.
virtual ::grpc::Status DescriptorDatabaseInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseResponse, ::grpc::reflection::v1alpha::DescriptorDatabaseRequest>* stream);
};
template <class BaseClass>
class WithAsyncMethod_ListService : public BaseClass {
class WithAsyncMethod_DescriptorDatabaseInfo : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
void BaseClassMustBeDerivedFromService(const Service *service) {}
public:
WithAsyncMethod_ListService() { ::grpc::Service::MarkMethodAsync(0); }
~WithAsyncMethod_ListService() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status ListService(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest* request,
::grpc::reflection::v1alpha::ListServiceResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
WithAsyncMethod_DescriptorDatabaseInfo() {
::grpc::Service::MarkMethodAsync(0);
}
void RequestListService(
::grpc::ServerContext* context,
::grpc::reflection::v1alpha::EmptyRequest* request,
::grpc::ServerAsyncResponseWriter<
::grpc::reflection::v1alpha::ListServiceResponse>* response,
::grpc::CompletionQueue* new_call_cq,
::grpc::ServerCompletionQueue* notification_cq, void* tag) {
::grpc::Service::RequestAsyncUnary(0, context, request, response,
new_call_cq, notification_cq, tag);
}
};
template <class BaseClass>
class WithAsyncMethod_GetFileByName : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithAsyncMethod_GetFileByName() { ::grpc::Service::MarkMethodAsync(1); }
~WithAsyncMethod_GetFileByName() GRPC_OVERRIDE {
~WithAsyncMethod_DescriptorDatabaseInfo() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetFileByName(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
::grpc::Status DescriptorDatabaseInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseResponse, ::grpc::reflection::v1alpha::DescriptorDatabaseRequest>* stream) GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
void RequestGetFileByName(
::grpc::ServerContext* context,
::grpc::reflection::v1alpha::FileNameRequest* request,
::grpc::ServerAsyncResponseWriter<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>* response,
::grpc::CompletionQueue* new_call_cq,
::grpc::ServerCompletionQueue* notification_cq, void* tag) {
::grpc::Service::RequestAsyncUnary(1, context, request, response,
new_call_cq, notification_cq, tag);
void RequestDescriptorDatabaseInfo(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseResponse, ::grpc::reflection::v1alpha::DescriptorDatabaseRequest>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
::grpc::Service::RequestAsyncBidiStreaming(0, context, stream, new_call_cq, notification_cq, tag);
}
};
typedef WithAsyncMethod_DescriptorDatabaseInfo<Service > AsyncService;
template <class BaseClass>
class WithAsyncMethod_GetFileContainingSymbol : public BaseClass {
class WithGenericMethod_DescriptorDatabaseInfo : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
void BaseClassMustBeDerivedFromService(const Service *service) {}
public:
WithAsyncMethod_GetFileContainingSymbol() {
::grpc::Service::MarkMethodAsync(2);
WithGenericMethod_DescriptorDatabaseInfo() {
::grpc::Service::MarkMethodGeneric(0);
}
~WithAsyncMethod_GetFileContainingSymbol() GRPC_OVERRIDE {
~WithGenericMethod_DescriptorDatabaseInfo() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetFileContainingSymbol(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
void RequestGetFileContainingSymbol(
::grpc::ServerContext* context,
::grpc::reflection::v1alpha::SymbolRequest* request,
::grpc::ServerAsyncResponseWriter<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>* response,
::grpc::CompletionQueue* new_call_cq,
::grpc::ServerCompletionQueue* notification_cq, void* tag) {
::grpc::Service::RequestAsyncUnary(2, context, request, response,
new_call_cq, notification_cq, tag);
}
};
template <class BaseClass>
class WithAsyncMethod_GetFileContainingExtension : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithAsyncMethod_GetFileContainingExtension() {
::grpc::Service::MarkMethodAsync(3);
}
~WithAsyncMethod_GetFileContainingExtension() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetFileContainingExtension(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
void RequestGetFileContainingExtension(
::grpc::ServerContext* context,
::grpc::reflection::v1alpha::ExtensionRequest* request,
::grpc::ServerAsyncResponseWriter<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>* response,
::grpc::CompletionQueue* new_call_cq,
::grpc::ServerCompletionQueue* notification_cq, void* tag) {
::grpc::Service::RequestAsyncUnary(3, context, request, response,
new_call_cq, notification_cq, tag);
}
};
template <class BaseClass>
class WithAsyncMethod_GetAllExtensionNumbers : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithAsyncMethod_GetAllExtensionNumbers() {
::grpc::Service::MarkMethodAsync(4);
}
~WithAsyncMethod_GetAllExtensionNumbers() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetAllExtensionNumbers(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::TypeRequest* request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
void RequestGetAllExtensionNumbers(
::grpc::ServerContext* context,
::grpc::reflection::v1alpha::TypeRequest* request,
::grpc::ServerAsyncResponseWriter<
::grpc::reflection::v1alpha::ExtensionNumberResponse>* response,
::grpc::CompletionQueue* new_call_cq,
::grpc::ServerCompletionQueue* notification_cq, void* tag) {
::grpc::Service::RequestAsyncUnary(4, context, request, response,
new_call_cq, notification_cq, tag);
}
};
typedef WithAsyncMethod_ListService<
WithAsyncMethod_GetFileByName<WithAsyncMethod_GetFileContainingSymbol<
WithAsyncMethod_GetFileContainingExtension<
WithAsyncMethod_GetAllExtensionNumbers<Service>>>>>
AsyncService;
template <class BaseClass>
class WithGenericMethod_ListService : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithGenericMethod_ListService() { ::grpc::Service::MarkMethodGeneric(0); }
~WithGenericMethod_ListService() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status ListService(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest* request,
::grpc::reflection::v1alpha::ListServiceResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
};
template <class BaseClass>
class WithGenericMethod_GetFileByName : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithGenericMethod_GetFileByName() { ::grpc::Service::MarkMethodGeneric(1); }
~WithGenericMethod_GetFileByName() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetFileByName(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
};
template <class BaseClass>
class WithGenericMethod_GetFileContainingSymbol : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithGenericMethod_GetFileContainingSymbol() {
::grpc::Service::MarkMethodGeneric(2);
}
~WithGenericMethod_GetFileContainingSymbol() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetFileContainingSymbol(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
};
template <class BaseClass>
class WithGenericMethod_GetFileContainingExtension : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithGenericMethod_GetFileContainingExtension() {
::grpc::Service::MarkMethodGeneric(3);
}
~WithGenericMethod_GetFileContainingExtension() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetFileContainingExtension(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
};
template <class BaseClass>
class WithGenericMethod_GetAllExtensionNumbers : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(Service* service) {}
public:
WithGenericMethod_GetAllExtensionNumbers() {
::grpc::Service::MarkMethodGeneric(4);
}
~WithGenericMethod_GetAllExtensionNumbers() GRPC_OVERRIDE {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status GetAllExtensionNumbers(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::TypeRequest* request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response)
GRPC_FINAL GRPC_OVERRIDE {
::grpc::Status DescriptorDatabaseInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseResponse, ::grpc::reflection::v1alpha::DescriptorDatabaseRequest>* stream) GRPC_FINAL GRPC_OVERRIDE {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
@ -552,4 +180,5 @@ class ServerReflection GRPC_FINAL {
} // namespace reflection
} // namespace grpc
#endif // GRPC_reflection_2eproto__INCLUDED

File diff suppressed because it is too large Load Diff

@ -51,14 +51,12 @@ using google::protobuf::FileDescriptor;
using google::protobuf::FieldDescriptor;
using google::protobuf::DescriptorPool;
using google::protobuf::FileDescriptorProto;
using grpc::reflection::v1alpha::EmptyRequest;
using grpc::reflection::v1alpha::ListServiceResponse;
using grpc::reflection::v1alpha::FileNameRequest;
using grpc::reflection::v1alpha::SymbolRequest;
using grpc::reflection::v1alpha::DescriptorDatabaseRequest;
using grpc::reflection::v1alpha::ExtensionRequest;
using grpc::reflection::v1alpha::TypeRequest;
using grpc::reflection::v1alpha::FileDescriptorProtoResponse;
using grpc::reflection::v1alpha::DescriptorDatabaseResponse;
using grpc::reflection::v1alpha::ListServiceResponse;
using grpc::reflection::v1alpha::ExtensionNumberResponse;
using grpc::reflection::v1alpha::ErrorResponse;
namespace grpc {
@ -70,55 +68,101 @@ void ProtoServerReflection::SetServiceList(
services_ = services;
}
Status ProtoServerReflection::DescriptorDatabaseInfo(
ServerContext* context,
ServerReaderWriter<DescriptorDatabaseResponse, DescriptorDatabaseRequest>*
stream) {
DescriptorDatabaseRequest request;
DescriptorDatabaseResponse response;
Status status;
while (stream->Read(&request)) {
switch (request.message_request_case()) {
case DescriptorDatabaseRequest::MessageRequestCase::kFileByFilename:
status = GetFileByName(context, request.file_by_filename(), &response);
break;
case DescriptorDatabaseRequest::MessageRequestCase::kFileContainingSymbol:
status = GetFileContainingSymbol(
context, request.file_containing_symbol(), &response);
break;
case DescriptorDatabaseRequest::MessageRequestCase::
kFileContainingExtension:
status = GetFileContainingExtension(
context, &request.file_containing_extension(), &response);
break;
case DescriptorDatabaseRequest::MessageRequestCase::
kAllExtensionNumbersOfType:
status = GetAllExtensionNumbers(
context, request.all_extension_numbers_of_type(),
response.mutable_all_extension_numbers_response());
break;
case DescriptorDatabaseRequest::MessageRequestCase::kListServices:
status =
ListService(context, response.mutable_list_services_response());
break;
default:
status = Status(StatusCode::UNIMPLEMENTED, "");
}
response.set_valid_host(request.host());
response.set_allocated_original_request(
new DescriptorDatabaseRequest(request));
stream->Write(response);
}
return Status::OK;
}
void ProtoServerReflection::FillErrorResponse(Status* status,
ErrorResponse* error_response) {
error_response->set_error_code(status->error_code());
error_response->set_error_message(status->error_message());
}
Status ProtoServerReflection::ListService(ServerContext* context,
const EmptyRequest* request,
ListServiceResponse* response) {
if (services_ == nullptr) {
return Status(StatusCode::NOT_FOUND, "Services not found.");
}
for (auto it = services_->begin(); it != services_->end(); ++it) {
response->add_services(*it);
response->add_service(*it);
}
return Status::OK;
}
Status ProtoServerReflection::GetFileByName(
ServerContext* context, const FileNameRequest* request,
FileDescriptorProtoResponse* response) {
ServerContext* context, const grpc::string& filename,
DescriptorDatabaseResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
const FileDescriptor* file_desc =
descriptor_pool_->FindFileByName(request->filename());
const FileDescriptor* file_desc = descriptor_pool_->FindFileByName(filename);
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "File not found.");
}
FillFileDescriptorProtoResponse(file_desc, response);
// file_desc->CopyTo(response->mutable_file_descriptor_proto());
return Status::OK;
}
Status ProtoServerReflection::GetFileContainingSymbol(
ServerContext* context, const SymbolRequest* request,
FileDescriptorProtoResponse* response) {
ServerContext* context, const grpc::string& symbol,
DescriptorDatabaseResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
const FileDescriptor* file_desc =
descriptor_pool_->FindFileContainingSymbol(request->symbol());
descriptor_pool_->FindFileContainingSymbol(symbol);
if (file_desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Symbol not found.");
}
FillFileDescriptorProtoResponse(file_desc, response);
// file_desc->CopyTo(response->mutable_file_descriptor_proto());
return Status::OK;
}
Status ProtoServerReflection::GetFileContainingExtension(
ServerContext* context, const ExtensionRequest* request,
FileDescriptorProtoResponse* response) {
DescriptorDatabaseResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
@ -135,19 +179,17 @@ Status ProtoServerReflection::GetFileContainingExtension(
return Status(StatusCode::NOT_FOUND, "Extension not found.");
}
FillFileDescriptorProtoResponse(field_desc->file(), response);
// field_desc->file()->CopyTo(response->mutable_file_descriptor_proto());
return Status::OK;
}
Status ProtoServerReflection::GetAllExtensionNumbers(
ServerContext* context, const TypeRequest* request,
ServerContext* context, const grpc::string& type,
ExtensionNumberResponse* response) {
if (descriptor_pool_ == nullptr) {
return Status::CANCELLED;
}
const Descriptor* desc =
descriptor_pool_->FindMessageTypeByName(request->type());
const Descriptor* desc = descriptor_pool_->FindMessageTypeByName(type);
if (desc == nullptr) {
return Status(StatusCode::NOT_FOUND, "Type not found.");
}
@ -157,11 +199,12 @@ Status ProtoServerReflection::GetAllExtensionNumbers(
for (auto extension : extensions) {
response->add_extension_number(extension->number());
}
response->set_base_type_name(type);
return Status::OK;
}
void ProtoServerReflection::FillFileDescriptorProtoResponse(
const FileDescriptor* file_desc, FileDescriptorProtoResponse* response) {
const FileDescriptor* file_desc, DescriptorDatabaseResponse* response) {
FileDescriptorProto file_desc_proto;
grpc::string data;
file_desc->CopyTo(&file_desc_proto);

@ -52,36 +52,41 @@ class ProtoServerReflection GRPC_FINAL
public:
ProtoServerReflection();
ProtoServerReflection(const Server* server);
void SetServiceList(const std::vector<grpc::string>* services);
Status ListService(
ServerContext* context, const reflection::v1alpha::EmptyRequest* request,
reflection::v1alpha::ListServiceResponse* response) GRPC_OVERRIDE;
Status DescriptorDatabaseInfo(
ServerContext* context,
ServerReaderWriter<reflection::v1alpha::DescriptorDatabaseResponse,
reflection::v1alpha::DescriptorDatabaseRequest>*
stream) GRPC_OVERRIDE;
private:
Status ListService(ServerContext* context,
reflection::v1alpha::ListServiceResponse* response);
Status GetFileByName(
ServerContext* context,
const reflection::v1alpha::FileNameRequest* request,
reflection::v1alpha::FileDescriptorProtoResponse* response) GRPC_OVERRIDE;
ServerContext* context, const grpc::string& file_name,
reflection::v1alpha::DescriptorDatabaseResponse* response);
Status GetFileContainingSymbol(
ServerContext* context, const reflection::v1alpha::SymbolRequest* request,
reflection::v1alpha::FileDescriptorProtoResponse* response) GRPC_OVERRIDE;
ServerContext* context, const grpc::string& symbol,
reflection::v1alpha::DescriptorDatabaseResponse* response);
Status GetFileContainingExtension(
ServerContext* context,
const reflection::v1alpha::ExtensionRequest* request,
reflection::v1alpha::FileDescriptorProtoResponse* response) GRPC_OVERRIDE;
reflection::v1alpha::DescriptorDatabaseResponse* response);
Status GetAllExtensionNumbers(
ServerContext* context, const reflection::v1alpha::TypeRequest* request,
reflection::v1alpha::ExtensionNumberResponse* response) GRPC_OVERRIDE;
ServerContext* context, const grpc::string& type,
reflection::v1alpha::ExtensionNumberResponse* response);
private:
void FillFileDescriptorProtoResponse(
const google::protobuf::FileDescriptor* file_desc,
reflection::v1alpha::FileDescriptorProtoResponse* response);
reflection::v1alpha::DescriptorDatabaseResponse* response);
void FillErrorResponse(Status* status,
reflection::v1alpha::ErrorResponse* error_response);
const google::protobuf::DescriptorPool* descriptor_pool_;
const std::vector<string>* services_;

@ -1,9 +1,43 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// Generated by the gRPC protobuf plugin.
// If you make any local change, they will be lost.
// source: reflection.proto
#include <grpc++/impl/reflection.grpc.pb.h>
#include <grpc++/impl/reflection.pb.h>
#include <grpc++/impl/reflection.grpc.pb.h>
#include <grpc++/impl/codegen/async_stream.h>
#include <grpc++/impl/codegen/async_unary_call.h>
@ -18,228 +52,46 @@ namespace reflection {
namespace v1alpha {
static const char* ServerReflection_method_names[] = {
"/grpc.reflection.v1alpha.ServerReflection/ListService",
"/grpc.reflection.v1alpha.ServerReflection/GetFileByName",
"/grpc.reflection.v1alpha.ServerReflection/GetFileContainingSymbol",
"/grpc.reflection.v1alpha.ServerReflection/GetFileContainingExtension",
"/grpc.reflection.v1alpha.ServerReflection/GetAllExtensionNumbers",
"/grpc.reflection.v1alpha.ServerReflection/DescriptorDatabaseInfo",
};
std::unique_ptr<ServerReflection::Stub> ServerReflection::NewStub(
const std::shared_ptr< ::grpc::ChannelInterface>& channel,
const ::grpc::StubOptions& options) {
std::unique_ptr<ServerReflection::Stub> stub(
new ServerReflection::Stub(channel));
std::unique_ptr< ServerReflection::Stub> ServerReflection::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) {
std::unique_ptr< ServerReflection::Stub> stub(new ServerReflection::Stub(channel));
return stub;
}
ServerReflection::Stub::Stub(
const std::shared_ptr< ::grpc::ChannelInterface>& channel)
: channel_(channel),
rpcmethod_ListService_(ServerReflection_method_names[0],
::grpc::RpcMethod::NORMAL_RPC, channel),
rpcmethod_GetFileByName_(ServerReflection_method_names[1],
::grpc::RpcMethod::NORMAL_RPC, channel),
rpcmethod_GetFileContainingSymbol_(ServerReflection_method_names[2],
::grpc::RpcMethod::NORMAL_RPC,
channel),
rpcmethod_GetFileContainingExtension_(ServerReflection_method_names[3],
::grpc::RpcMethod::NORMAL_RPC,
channel),
rpcmethod_GetAllExtensionNumbers_(ServerReflection_method_names[4],
::grpc::RpcMethod::NORMAL_RPC,
channel) {}
::grpc::Status ServerReflection::Stub::ListService(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::reflection::v1alpha::ListServiceResponse* response) {
return ::grpc::BlockingUnaryCall(channel_.get(), rpcmethod_ListService_,
context, request, response);
}
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ListServiceResponse>*
ServerReflection::Stub::AsyncListServiceRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest& request,
::grpc::CompletionQueue* cq) {
return new ::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ListServiceResponse>(
channel_.get(), cq, rpcmethod_ListService_, context, request);
}
::grpc::Status ServerReflection::Stub::GetFileByName(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) {
return ::grpc::BlockingUnaryCall(channel_.get(), rpcmethod_GetFileByName_,
context, request, response);
}
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
ServerReflection::Stub::AsyncGetFileByNameRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest& request,
::grpc::CompletionQueue* cq) {
return new ::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>(
channel_.get(), cq, rpcmethod_GetFileByName_, context, request);
}
::grpc::Status ServerReflection::Stub::GetFileContainingSymbol(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) {
return ::grpc::BlockingUnaryCall(channel_.get(),
rpcmethod_GetFileContainingSymbol_, context,
request, response);
}
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
ServerReflection::Stub::AsyncGetFileContainingSymbolRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest& request,
::grpc::CompletionQueue* cq) {
return new ::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>(
channel_.get(), cq, rpcmethod_GetFileContainingSymbol_, context, request);
}
::grpc::Status ServerReflection::Stub::GetFileContainingExtension(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) {
return ::grpc::BlockingUnaryCall(channel_.get(),
rpcmethod_GetFileContainingExtension_,
context, request, response);
}
ServerReflection::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel)
: channel_(channel), rpcmethod_DescriptorDatabaseInfo_(ServerReflection_method_names[0], ::grpc::RpcMethod::BIDI_STREAMING, channel)
{}
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>*
ServerReflection::Stub::AsyncGetFileContainingExtensionRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest& request,
::grpc::CompletionQueue* cq) {
return new ::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>(
channel_.get(), cq, rpcmethod_GetFileContainingExtension_, context,
request);
::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>* ServerReflection::Stub::DescriptorDatabaseInfoRaw(::grpc::ClientContext* context) {
return new ::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>(channel_.get(), rpcmethod_DescriptorDatabaseInfo_, context);
}
::grpc::Status ServerReflection::Stub::GetAllExtensionNumbers(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response) {
return ::grpc::BlockingUnaryCall(channel_.get(),
rpcmethod_GetAllExtensionNumbers_, context,
request, response);
}
::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ExtensionNumberResponse>*
ServerReflection::Stub::AsyncGetAllExtensionNumbersRaw(
::grpc::ClientContext* context,
const ::grpc::reflection::v1alpha::TypeRequest& request,
::grpc::CompletionQueue* cq) {
return new ::grpc::ClientAsyncResponseReader<
::grpc::reflection::v1alpha::ExtensionNumberResponse>(
channel_.get(), cq, rpcmethod_GetAllExtensionNumbers_, context, request);
::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>* ServerReflection::Stub::AsyncDescriptorDatabaseInfoRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
return new ::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>(channel_.get(), cq, rpcmethod_DescriptorDatabaseInfo_, context, tag);
}
ServerReflection::Service::Service() {
(void)ServerReflection_method_names;
AddMethod(new ::grpc::RpcServiceMethod(
ServerReflection_method_names[0], ::grpc::RpcMethod::NORMAL_RPC,
new ::grpc::RpcMethodHandler<
ServerReflection::Service, ::grpc::reflection::v1alpha::EmptyRequest,
::grpc::reflection::v1alpha::ListServiceResponse>(
std::mem_fn(&ServerReflection::Service::ListService), this)));
AddMethod(new ::grpc::RpcServiceMethod(
ServerReflection_method_names[1], ::grpc::RpcMethod::NORMAL_RPC,
new ::grpc::RpcMethodHandler<
ServerReflection::Service,
::grpc::reflection::v1alpha::FileNameRequest,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>(
std::mem_fn(&ServerReflection::Service::GetFileByName), this)));
AddMethod(new ::grpc::RpcServiceMethod(
ServerReflection_method_names[2], ::grpc::RpcMethod::NORMAL_RPC,
new ::grpc::RpcMethodHandler<
ServerReflection::Service, ::grpc::reflection::v1alpha::SymbolRequest,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>(
std::mem_fn(&ServerReflection::Service::GetFileContainingSymbol),
this)));
AddMethod(new ::grpc::RpcServiceMethod(
ServerReflection_method_names[3], ::grpc::RpcMethod::NORMAL_RPC,
new ::grpc::RpcMethodHandler<
ServerReflection::Service,
::grpc::reflection::v1alpha::ExtensionRequest,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse>(
std::mem_fn(&ServerReflection::Service::GetFileContainingExtension),
this)));
AddMethod(new ::grpc::RpcServiceMethod(
ServerReflection_method_names[4], ::grpc::RpcMethod::NORMAL_RPC,
new ::grpc::RpcMethodHandler<
ServerReflection::Service, ::grpc::reflection::v1alpha::TypeRequest,
::grpc::reflection::v1alpha::ExtensionNumberResponse>(
std::mem_fn(&ServerReflection::Service::GetAllExtensionNumbers),
this)));
ServerReflection_method_names[0],
::grpc::RpcMethod::BIDI_STREAMING,
new ::grpc::BidiStreamingHandler< ServerReflection::Service, ::grpc::reflection::v1alpha::DescriptorDatabaseRequest, ::grpc::reflection::v1alpha::DescriptorDatabaseResponse>(
std::mem_fn(&ServerReflection::Service::DescriptorDatabaseInfo), this)));
}
ServerReflection::Service::~Service() {}
::grpc::Status ServerReflection::Service::ListService(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::EmptyRequest* request,
::grpc::reflection::v1alpha::ListServiceResponse* response) {
(void)context;
(void)request;
(void)response;
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
ServerReflection::Service::~Service() {
}
::grpc::Status ServerReflection::Service::GetFileByName(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::FileNameRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) {
(void)context;
(void)request;
(void)response;
::grpc::Status ServerReflection::Service::DescriptorDatabaseInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::DescriptorDatabaseResponse, ::grpc::reflection::v1alpha::DescriptorDatabaseRequest>* stream) {
(void) context;
(void) stream;
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
::grpc::Status ServerReflection::Service::GetFileContainingSymbol(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::SymbolRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) {
(void)context;
(void)request;
(void)response;
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
::grpc::Status ServerReflection::Service::GetFileContainingExtension(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::ExtensionRequest* request,
::grpc::reflection::v1alpha::FileDescriptorProtoResponse* response) {
(void)context;
(void)request;
(void)response;
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
::grpc::Status ServerReflection::Service::GetAllExtensionNumbers(
::grpc::ServerContext* context,
const ::grpc::reflection::v1alpha::TypeRequest* request,
::grpc::reflection::v1alpha::ExtensionNumberResponse* response) {
(void)context;
(void)request;
(void)response;
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
} // namespace grpc
} // namespace reflection
} // namespace v1alpha

File diff suppressed because it is too large Load Diff

@ -34,85 +34,98 @@ syntax = "proto3";
package grpc.reflection.v1alpha;
service ServerReflection {
// List the full names of registered services.
rpc ListService(EmptyRequest) returns (ListServiceResponse) {
}
// Find a proto file by file name.
rpc GetFileByName(FileNameRequest) returns (FileDescriptorProtoResponse) {
}
// Find the proto file that declares the given fully-qualified symbol name.
rpc GetFileContainingSymbol(SymbolRequest)
returns (FileDescriptorProtoResponse) {
}
// Find the proto file which defines an extension extending the given message
// type with the given field number.
rpc GetFileContainingExtension(ExtensionRequest)
returns (FileDescriptorProtoResponse) {
}
// Finds the tag numbers used by all known extensions of extendee_type, and
// appends them to ExtensionNumberResponse in an undefined order.
// This method is best-effort: it's not guaranteed that the reflection service
// will implement this method, and it's not guaranteed that this method will
// provide all extensions. Returns StatusCode::UNIMPLEMENTED if it's not
// implemented.
rpc GetAllExtensionNumbers(TypeRequest) returns (ExtensionNumberResponse) {
}
}
// An empty message sent by the client when calling ListService method.
message EmptyRequest {
}
// The filename sent by the client when calling GetFileByName method.
message FileNameRequest {
// Name of the proto file.
string filename = 1;
// The reflection service is structured as a bidirectional stream, ensuring
// all related requests go to a single server.
rpc DescriptorDatabaseInfo(stream DescriptorDatabaseRequest)
returns (stream DescriptorDatabaseResponse);
}
// The symbol name sent by the client when calling GetFileContainingSymbol
// method.
message SymbolRequest {
// Fully-qualified symbol name (e.g. <package>.<service>[.<method>] or
// <package>.<type>).
string symbol = 1;
// The message sent by the client when calling DescriptorDatabaseInfo method.
message DescriptorDatabaseRequest {
string host = 1;
// To use reflection service, the client should set one of the following
// fields in message_request. The server distinguishes requests by their
// defined field and then handles them using corresponding methods.
oneof message_request {
// Find a proto file by the file name.
string file_by_filename = 3;
// Find the proto file that declares the given fully-qualified symbol name.
// This field should be a fully-qualified symbol name
// (e.g. <package>.<service>[.<method>] or <package>.<type>).
string file_containing_symbol = 4;
// Find the proto file which defines an extension extending the given
// message type with the given field number.
ExtensionRequest file_containing_extension = 5;
// Finds the tag numbers used by all known extensions of extendee_type, and
// appends them to ExtensionNumberResponse in an undefined order.
// Its corresponding method is best-effort: it's not guaranteed that the
// reflection service will implement this method, and it's not guaranteed
// that this method will provide all extensions. Returns
// StatusCode::UNIMPLEMENTED if it's not implemented.
// This field should be a fully-qualified type name. The format is
// <package>.<type>
string all_extension_numbers_of_type = 6;
// List the full names of registered services. The content will not be
// checked.
string list_services = 7;
}
}
// The type name and extension number sent by the client when calling
// GetFileContainingExtension method.
// The type name and extension number sent by the client when requesting
// file_containing_extension.
message ExtensionRequest {
// Fully-qualified type name. The format should be <package>.<type>
string containing_type = 1;
int32 extension_number = 2;
}
// The type name sent by the client when calling GetAllExtensionNumbers method.
message TypeRequest {
// Fully-qualified type name. The format should be <package>.<type>
string type = 1;
// The message sent by the server to answer DescriptorDatabaseInfo method.
message DescriptorDatabaseResponse {
string valid_host = 1;
DescriptorDatabaseRequest original_request = 2;
// The server set one of the following fields accroding to the message_request
// in the request.
oneof message_response {
// A serialized FileDescriptorProto message. We avoid taking a dependency on
// descriptor.proto, which uses proto2 only features, by making them opaque
// bytes instead. This message is used to answer file_by_filename,
// file_containing_symbol, file_containing_extension requests.
bytes file_descriptor_proto = 4;
// This message is used to answer all_extension_numbers_of_type requst.
ExtensionNumberResponse all_extension_numbers_response = 5;
// This message is used to answer list_services request.
ListServiceResponse list_services_response = 6;
// This message is used when an error occurs.
ErrorResponse error_response = 7;
}
}
// A list of extension numbers sent by the server answering
// all_extension_numbers_of_type request.
message ExtensionNumberResponse {
// Full name of the base type, including the package name. The format
// is <package>.<type>
string base_type_name = 1;
repeated int32 extension_number = 2;
}
// A list of service names sent by the server answering ListService method.
// A list of service names sent by the server answering list_services request.
message ListServiceResponse {
// Full names of registered services, including package names. The format
// is <package>.<service>
repeated string services = 1;
}
// A serialized FileDescriptorProto sent by the server answering
// GetFileByName, GetFileContainingSymbol, GetFileContainingExtension methods.
message FileDescriptorProtoResponse {
// Serialized FileDescriptorProto message. Some languages have limited support
// for working with descriptors. The can only obtain an opaque binary blob
// that contains serialized FileDescriptorProto message.
bytes file_descriptor_proto = 1;
repeated string service = 1;
}
// A list of extension numbers sent by the server answering
// GetAllExtensionNumbers method.
message ExtensionNumberResponse {
repeated int32 extension_number = 1;
// The error code and error message sent by the server when an error occurs.
message ErrorResponse {
// This field uses the error codes defined in grpc::StatusCode.
int32 error_code = 1;
string error_message = 2;
}

@ -37,15 +37,21 @@
#include <grpc/support/log.h>
using grpc::reflection::v1alpha::ServerReflection;
using grpc::reflection::v1alpha::DescriptorDatabaseRequest;
using grpc::reflection::v1alpha::DescriptorDatabaseResponse;
using grpc::reflection::v1alpha::ListServiceResponse;
using grpc::reflection::v1alpha::ErrorResponse;
namespace grpc {
ProtoReflectionDescriptorDatabase::ProtoReflectionDescriptorDatabase(
std::unique_ptr<reflection::v1alpha::ServerReflection::Stub> stub)
std::unique_ptr<ServerReflection::Stub> stub)
: stub_(std::move(stub)) {}
ProtoReflectionDescriptorDatabase::ProtoReflectionDescriptorDatabase(
std::shared_ptr<grpc::Channel> channel)
: stub_(reflection::v1alpha::ServerReflection::NewStub(channel)) {}
: stub_(ServerReflection::NewStub(channel)) {}
ProtoReflectionDescriptorDatabase::~ProtoReflectionDescriptorDatabase() {}
@ -59,28 +65,40 @@ bool ProtoReflectionDescriptorDatabase::FindFileByName(
return false;
}
ClientContext ctx;
reflection::v1alpha::FileNameRequest request;
request.set_filename(filename);
reflection::v1alpha::FileDescriptorProtoResponse response;
DescriptorDatabaseRequest request;
request.set_file_by_filename(filename);
DescriptorDatabaseResponse response;
GetStream()->Write(request);
GetStream()->Read(&response);
Status status = stub_->GetFileByName(&ctx, request, &response);
if (status.ok()) {
// const google::protobuf::FileDescriptorProto* file_proto =
// response.mutable_file_descriptor_proto();
if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kFileDescriptorProto) {
const google::protobuf::FileDescriptorProto file_proto =
ParseFileDescriptorProtoResponse(&response);
ParseFileDescriptorProtoResponse(response.file_descriptor_proto());
known_files_.insert(file_proto.name());
cached_db_.Add(file_proto);
} else if (status.error_code() == StatusCode::NOT_FOUND) {
gpr_log(GPR_INFO, "NOT_FOUND from server for FindFileByName(%s)",
filename.c_str());
} else if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kErrorResponse) {
const ErrorResponse error = response.error_response();
if (error.error_code() == StatusCode::NOT_FOUND) {
gpr_log(GPR_INFO, "NOT_FOUND from server for FindFileByName(%s)",
filename.c_str());
} else {
gpr_log(GPR_INFO,
"Error on FindFileByName(%s)\n\tError code: %d\n"
"\tError Message: %s",
filename.c_str(), error.error_code(),
error.error_message().c_str());
}
} else {
gpr_log(GPR_INFO,
"Error on FindFileByName(%s)\n\tError code: %d\n"
"\tError Message: %s",
filename.c_str(), status.error_code(),
status.error_message().c_str());
gpr_log(
GPR_INFO,
"Error on FindFileByName(%s) response type\n"
"\tExpecting: %d\n\tReceived: %d",
filename.c_str(),
DescriptorDatabaseResponse::MessageResponseCase::kFileDescriptorProto,
response.message_response_case());
}
return cached_db_.FindFileByName(filename, output);
@ -96,31 +114,46 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingSymbol(
return false;
}
ClientContext ctx;
reflection::v1alpha::SymbolRequest request;
request.set_symbol(symbol_name);
reflection::v1alpha::FileDescriptorProtoResponse response;
DescriptorDatabaseRequest request;
request.set_file_containing_symbol(symbol_name);
DescriptorDatabaseResponse response;
GetStream()->Write(request);
GetStream()->Read(&response);
Status status = stub_->GetFileContainingSymbol(&ctx, request, &response);
if (status.ok()) {
// Status status = stub_->GetFileContainingSymbol(&ctx, request, &response);
if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kFileDescriptorProto) {
const google::protobuf::FileDescriptorProto file_proto =
ParseFileDescriptorProtoResponse(&response);
ParseFileDescriptorProtoResponse(response.file_descriptor_proto());
if (known_files_.find(file_proto.name()) == known_files_.end()) {
known_files_.insert(file_proto.name());
cached_db_.Add(file_proto);
}
} else if (status.error_code() == StatusCode::NOT_FOUND) {
missing_symbols_.insert(symbol_name);
gpr_log(GPR_INFO, "NOT_FOUND from server for FindFileContainingSymbol(%s)",
symbol_name.c_str());
} else if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kErrorResponse) {
const ErrorResponse error = response.error_response();
if (error.error_code() == StatusCode::NOT_FOUND) {
missing_symbols_.insert(symbol_name);
gpr_log(GPR_INFO,
"NOT_FOUND from server for FindFileContainingSymbol(%s)",
symbol_name.c_str());
} else {
gpr_log(GPR_INFO,
"Error on FindFileContainingSymbol(%s)\n"
"\tError code: %d\n\tError Message: %s",
symbol_name.c_str(), error.error_code(),
error.error_message().c_str());
}
} else {
gpr_log(GPR_INFO,
"Error on FindFileContainingSymbol(%s)\n"
"\tError code: %d\n\tError Message: %s",
symbol_name.c_str(), status.error_code(),
status.error_message().c_str());
gpr_log(
GPR_INFO,
"Error on FindFileContainingSymbol(%s) response type\n"
"\tExpecting: %d\n\tReceived: %d",
symbol_name.c_str(),
DescriptorDatabaseResponse::MessageResponseCase::kFileDescriptorProto,
response.message_response_case());
}
return cached_db_.FindFileContainingSymbol(symbol_name, output);
}
@ -139,35 +172,53 @@ bool ProtoReflectionDescriptorDatabase::FindFileContainingExtension(
return false;
}
ClientContext ctx;
reflection::v1alpha::ExtensionRequest request;
request.set_containing_type(containing_type);
request.set_extension_number(field_number);
reflection::v1alpha::FileDescriptorProtoResponse response;
DescriptorDatabaseRequest request;
request.mutable_file_containing_extension()->set_containing_type(
containing_type);
request.mutable_file_containing_extension()->set_extension_number(
field_number);
DescriptorDatabaseResponse response;
Status status = stub_->GetFileContainingExtension(&ctx, request, &response);
if (status.ok()) {
GetStream()->Write(request);
GetStream()->Read(&response);
// Status status = stub_->GetFileContainingExtension(&ctx, request,
// &response);
if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kFileDescriptorProto) {
const google::protobuf::FileDescriptorProto file_proto =
ParseFileDescriptorProtoResponse(&response);
ParseFileDescriptorProtoResponse(response.file_descriptor_proto());
if (known_files_.find(file_proto.name()) == known_files_.end()) {
known_files_.insert(file_proto.name());
cached_db_.Add(file_proto);
}
} else if (status.error_code() == StatusCode::NOT_FOUND) {
if (missing_extensions_.find(containing_type) ==
missing_extensions_.end()) {
missing_extensions_[containing_type] = {};
} else if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kErrorResponse) {
const ErrorResponse error = response.error_response();
if (error.error_code() == StatusCode::NOT_FOUND) {
if (missing_extensions_.find(containing_type) ==
missing_extensions_.end()) {
missing_extensions_[containing_type] = {};
}
missing_extensions_[containing_type].insert(field_number);
gpr_log(GPR_INFO,
"NOT_FOUND from server for FindFileContainingExtension(%s, %d)",
containing_type.c_str(), field_number);
} else {
gpr_log(GPR_INFO,
"Error on FindFileContainingExtension(%s, %d)\n"
"\tError code: %d\n\tError Message: %s",
containing_type.c_str(), field_number, error.error_code(),
error.error_message().c_str());
}
missing_extensions_[containing_type].insert(field_number);
gpr_log(GPR_INFO,
"NOT_FOUND from server for FindFileContainingExtension(%s, %d)",
containing_type.c_str(), field_number);
} else {
gpr_log(GPR_INFO,
"Error on FindFileContainingExtension(%s, %d)\n"
"\tError code: %d\n\tError Message: %s",
containing_type.c_str(), field_number, status.error_code(),
status.error_message().c_str());
gpr_log(
GPR_INFO,
"Error on FindFileContainingExtension(%s, %d) response type\n"
"\tExpecting: %d\n\tReceived: %d",
containing_type.c_str(), field_number,
DescriptorDatabaseResponse::MessageResponseCase::kFileDescriptorProto,
response.message_response_case());
}
return cached_db_.FindFileContainingExtension(containing_type, field_number,
@ -182,57 +233,86 @@ bool ProtoReflectionDescriptorDatabase::FindAllExtensionNumbers(
return true;
}
ClientContext ctx;
reflection::v1alpha::TypeRequest request;
request.set_type(extendee_type);
reflection::v1alpha::ExtensionNumberResponse response;
DescriptorDatabaseRequest request;
request.set_all_extension_numbers_of_type(extendee_type);
DescriptorDatabaseResponse response;
GetStream()->Write(request);
GetStream()->Read(&response);
Status status = stub_->GetAllExtensionNumbers(&ctx, request, &response);
if (status.ok()) {
auto number = response.extension_number();
// Status status = stub_->GetAllExtensionNumbers(&ctx, request, &response);
if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::
kAllExtensionNumbersResponse) {
auto number = response.all_extension_numbers_response().extension_number();
*output = std::vector<int>(number.begin(), number.end());
cached_extension_numbers_[extendee_type] = *output;
return true;
} else if (status.error_code() == StatusCode::NOT_FOUND) {
gpr_log(GPR_INFO, "NOT_FOUND from server for FindAllExtensionNumbers(%s)",
extendee_type.c_str());
} else {
gpr_log(GPR_INFO,
"Error on FindAllExtensionNumbersExtension(%s)\n"
"\tError code: %d\n\tError Message: %s",
extendee_type.c_str(), status.error_code(),
status.error_message().c_str());
} else if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kErrorResponse) {
const ErrorResponse error = response.error_response();
if (error.error_code() == StatusCode::NOT_FOUND) {
gpr_log(GPR_INFO, "NOT_FOUND from server for FindAllExtensionNumbers(%s)",
extendee_type.c_str());
} else {
gpr_log(GPR_INFO,
"Error on FindAllExtensionNumbersExtension(%s)\n"
"\tError code: %d\n\tError Message: %s",
extendee_type.c_str(), error.error_code(),
error.error_message().c_str());
}
}
return false;
}
bool ProtoReflectionDescriptorDatabase::GetServices(
std::vector<std::string>* output) {
ClientContext ctx;
reflection::v1alpha::EmptyRequest request;
reflection::v1alpha::ListServiceResponse response;
Status status = stub_->ListService(&ctx, request, &response);
if (status.ok()) {
for (int i = 0; i < response.services_size(); ++i) {
(*output).push_back(response.services(i));
DescriptorDatabaseRequest request;
request.set_list_services("");
DescriptorDatabaseResponse response;
GetStream()->Write(request);
GetStream()->Read(&response);
// Status status = stub_->ListService(&ctx, request, &response);
if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kListServicesResponse) {
const ListServiceResponse ls_response = response.list_services_response();
for (int i = 0; i < ls_response.service_size(); ++i) {
(*output).push_back(ls_response.service(i));
}
return true;
} else {
} else if (response.message_response_case() ==
DescriptorDatabaseResponse::MessageResponseCase::kErrorResponse) {
const ErrorResponse error = response.error_response();
gpr_log(GPR_INFO,
"Error on GetServices()\n\tError code: %d\n"
"\tError Message: %s",
status.error_code(), status.error_message().c_str());
error.error_code(), error.error_message().c_str());
} else {
gpr_log(
GPR_INFO,
"Error on GetServices() response type\n\tExpecting: %d\n\tReceived: %d",
DescriptorDatabaseResponse::MessageResponseCase::kListServicesResponse,
response.message_response_case());
}
return false;
}
const google::protobuf::FileDescriptorProto
ProtoReflectionDescriptorDatabase::ParseFileDescriptorProtoResponse(
reflection::v1alpha::FileDescriptorProtoResponse* response) {
const std::string& byte_fd_proto) {
google::protobuf::FileDescriptorProto file_desc_proto;
file_desc_proto.ParseFromString(response->file_descriptor_proto());
file_desc_proto.ParseFromString(byte_fd_proto);
return file_desc_proto;
}
const std::shared_ptr<ProtoReflectionDescriptorDatabase::ClientStream>
ProtoReflectionDescriptorDatabase::GetStream() {
if (stream_ == nullptr) {
stream_ = stub_->DescriptorDatabaseInfo(&ctx_);
// stream_.reset(std::move(stub_->DescriptorDatabaseInfo(&ctx_)));
}
return stream_;
}
} // namespace grpc

@ -80,9 +80,18 @@ class ProtoReflectionDescriptorDatabase
}
private:
typedef ClientReaderWriter<
grpc::reflection::v1alpha::DescriptorDatabaseRequest,
grpc::reflection::v1alpha::DescriptorDatabaseResponse>
ClientStream;
const google::protobuf::FileDescriptorProto ParseFileDescriptorProtoResponse(
reflection::v1alpha::FileDescriptorProtoResponse* response);
const std::string& byte_fd_proto);
const std::shared_ptr<ClientStream> GetStream();
std::shared_ptr<ClientStream> stream_;
grpc::ClientContext ctx_;
std::unique_ptr<grpc::reflection::v1alpha::ServerReflection::Stub> stub_;
std::unordered_set<string> known_files_;
std::unordered_set<string> missing_symbols_;

@ -48,8 +48,8 @@ using grpc::ClientContext;
using grpc::Status;
using grpc::ProtoReflectionDescriptorDatabase;
using grpc::reflection::v1alpha::ServerReflection;
using grpc::reflection::v1alpha::EmptyRequest;
using grpc::reflection::v1alpha::ListServiceResponse;
// using grpc::reflection::v1alpha::EmptyRequest;
// using grpc::reflection::v1alpha::ListServiceResponse;
using google::protobuf::FileDescriptorProto;
using google::protobuf::DescriptorPool;
using google::protobuf::ServiceDescriptor;
@ -65,28 +65,22 @@ class ReflectionClient {
desc_pool_(new DescriptorPool(db_.get())) {}
void PrintInfo() {
EmptyRequest request;
ListServiceResponse response;
ClientContext context;
Status status = db_->stub()->ListService(&context, request, &response);
if (status.ok()) {
std::vector<std::string> services;
bool found_services = db_->GetServices(&services);
if (found_services) {
std::string padding = "";
std::cout << "Service amount:" << response.services_size() << std::endl;
for (int i = 0; i < response.services_size(); ++i) {
if (i != response.services_size() - 1) {
std::cout << "Service amount:" << services.size() << std::endl;
for (auto it = services.begin(); it != services.end(); ++it) {
if (it != services.end() - 1) {
std::cout << padding << "" << std::endl;
std::cout << padding << "├─" << response.services(i) << std::endl;
PrintService(desc_pool_->FindServiceByName(response.services(i)),
padding + "");
std::cout << padding << "├─" << *it << std::endl;
PrintService(desc_pool_->FindServiceByName(*it), padding + "");
} else {
std::cout << padding << "" << std::endl;
std::cout << padding << "└─" << response.services(i) << std::endl;
PrintService(desc_pool_->FindServiceByName(response.services(i)),
padding + " ");
std::cout << padding << "└─" << *it << std::endl;
PrintService(desc_pool_->FindServiceByName(*it), padding + " ");
}
}
} else {
std::cout << status.error_message();
}
}
@ -157,6 +151,15 @@ class ReflectionClient {
}
void Test() {
{
std::vector<std::string> services;
bool found = db_->GetServices(&services);
if (found) {
for (auto it : services) {
std::cout << it << std::endl;
}
}
}
{
FileDescriptorProto output;
bool found = db_->FindFileByName("helloworld.proto", &output);
@ -176,9 +179,9 @@ class ReflectionClient {
"helloworld.Greeter.HelloRequest", 1, &output);
if (found) std::cout << output.name() << std::endl;
}
DescriptorPool pool(db_.get());
std::cout << pool.FindServiceByName("helloworld.Greeter")->name()
<< std::endl;
// DescriptorPool pool(db_.get());
// std::cout << pool.FindServiceByName("helloworld.Greeter")->name()
// << std::endl;
}
private:

@ -1,4 +1,34 @@
#!/bin/bash
# Copyright 2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PROTO_DIR="src/proto/grpc/reflection/v1alpha"
PROTO_FILE="reflection"
HEADER_DIR="extensions/include/grpc++/impl"
@ -22,9 +52,19 @@ $PROTOC -I$PROTO_DIR --cpp_out=$TMP_DIR ${PROTO_DIR}/${PROTO_FILE}.proto
$PROTOC -I$PROTO_DIR --grpc_out=$TMP_DIR --plugin=protoc-gen-grpc=${GRPC_PLUGIN} ${PROTO_DIR}/${PROTO_FILE}.proto
sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.pb.cc
sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.h
sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc
sed -i "s/\"${PROTO_FILE}.grpc.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.grpc.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.cc
sed -i "s/\"${PROTO_FILE}.pb.h\"/<${INCLUDE_DIR/\//\\\/}\/${PROTO_FILE}.pb.h>/g" ${TMP_DIR}/${PROTO_FILE}.grpc.pb.h
/bin/cp LICENSE ${TMP_DIR}/TMP_LICENSE
sed -i -e "s/./ &/" -e "s/.*/ \*&/" ${TMP_DIR}/TMP_LICENSE
sed -i -r "\$a\ *\n *\/\n\n" ${TMP_DIR}/TMP_LICENSE
sed -i -e "1s/^/ *\n/" -e "1s/^/\/*\n/" ${TMP_DIR}/*.pb.h
sed -i -e "1s/^/ *\n/" -e "1s/^/\/*\n/" ${TMP_DIR}/*.pb.cc
sed -i "2r ${TMP_DIR}/TMP_LICENSE" ${TMP_DIR}/*.pb.h
sed -i "2r ${TMP_DIR}/TMP_LICENSE" ${TMP_DIR}/*.pb.cc
/bin/mv ${TMP_DIR}/${PROTO_FILE}.pb.h ${HEADER_DIR}
/bin/mv ${TMP_DIR}/${PROTO_FILE}.grpc.pb.h ${HEADER_DIR}

Loading…
Cancel
Save