diff options
author | 2016-09-21 14:10:47 -0700 | |
---|---|---|
committer | 2016-09-21 14:10:47 -0700 | |
commit | 24129f010cb2b9ebccb44b4e0486d89aff7a74ae (patch) | |
tree | 6fe3d15f4b12ad79f96fa022aab6adccf0c16fea /test/cpp/util/grpc_tool.cc | |
parent | 2579bf394175637e44e9696959deac9d3c867c8e (diff) | |
parent | d53957cf4e3924d2abd201fa60ba1e2ae9ba2526 (diff) |
Merge remote-tracking branch 'upstream/master' into cli_list
Diffstat (limited to 'test/cpp/util/grpc_tool.cc')
-rw-r--r-- | test/cpp/util/grpc_tool.cc | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index 25f41912e8..b84a8d6b43 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -80,8 +80,10 @@ class GrpcTool { GrpcToolOutputCallback callback); bool ListServices(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback); + bool PrintType(int argc, const char** argv, const CliCredentials& cred, + GrpcToolOutputCallback callback); // TODO(zyc): implement the following methods - // bool PrintType(int argc, const char** argv, GrpcToolOutputCallback + // bool ListServices(int argc, const char** argv, GrpcToolOutputCallback // callback); // bool PrintTypeId(int argc, const char** argv, GrpcToolOutputCallback // callback); @@ -171,7 +173,7 @@ const Command ops[] = { {"ls", BindWith5Args(&GrpcTool::ListServices), 1, 3}, {"list", BindWith5Args(&GrpcTool::ListServices), 1, 3}, {"call", BindWith5Args(&GrpcTool::CallMethod), 2, 3}, - // {"type", BindWith5Args(&GrpcTool::PrintType), 2, 2}, + {"type", BindWith5Args(&GrpcTool::PrintType), 2, 2}, // {"parse", BindWith5Args(&GrpcTool::ParseMessage), 2, 3}, // {"totext", BindWith5Args(&GrpcTool::ToText), 2, 3}, // {"tobinary", BindWith5Args(&GrpcTool::ToBinary), 2, 3}, @@ -183,7 +185,7 @@ void Usage(const grpc::string& msg) { "%s\n" " grpc_cli ls ... ; List services\n" " grpc_cli call ... ; Call method\n" - // " grpc_cli type ... ; Print type\n" + " grpc_cli type ... ; Print type\n" // " grpc_cli parse ... ; Parse message\n" // " grpc_cli totext ... ; Convert binary message to text\n" // " grpc_cli tobinary ... ; Convert text message to binary\n" @@ -360,6 +362,35 @@ bool GrpcTool::ListServices(int argc, const char** argv, return callback(output); } +bool GrpcTool::PrintType(int argc, const char** argv, + const CliCredentials& cred, + GrpcToolOutputCallback callback) { + CommandUsage( + "Print type\n" + " grpc_cli type <address> <type>\n" + " <address> ; host:port\n" + " <type> ; Protocol buffer type name\n" + + cred.GetCredentialUsage()); + + grpc::string server_address(argv[0]); + std::shared_ptr<grpc::Channel> channel = + grpc::CreateChannel(server_address, cred.GetCredentials()); + grpc::ProtoReflectionDescriptorDatabase desc_db(channel); + grpc::protobuf::DescriptorPool desc_pool(&desc_db); + + grpc::string output; + const grpc::protobuf::Descriptor* descriptor = + desc_pool.FindMessageTypeByName(argv[1]); + if (descriptor != nullptr) { + output = descriptor->DebugString(); + } else { + fprintf(stderr, "Type %s not found.\n", argv[1]); + return false; + } + return callback(output); +} + + bool GrpcTool::CallMethod(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback) { |