proto_file_parser.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_TEST_CPP_UTIL_PROTO_FILE_PARSER_H
20 #define GRPC_TEST_CPP_UTIL_PROTO_FILE_PARSER_H
21 
22 #include <memory>
23 
24 #include <grpcpp/channel.h>
25 
28 
29 #if defined(_WIN32) && !defined(__CYGWIN__)
30 #define GRPC_CLI_PATH_SEPARATOR ";"
31 #else
32 #define GRPC_CLI_PATH_SEPARATOR ":"
33 #endif
34 
35 namespace grpc {
36 namespace testing {
37 class ErrorPrinter;
38 
39 // Find method and associated request/response types.
41  public:
42  // The parser will search proto files using the server reflection service
43  // provided on the given channel. The given protofiles in a source tree rooted
44  // from proto_path will also be searched.
45  ProtoFileParser(const std::shared_ptr<grpc::Channel>& channel,
46  const std::string& proto_path, const std::string& protofiles);
47 
49 
50  // The input method name in the following four functions could be a partial
51  // string such as Service.Method or even just Method. It will log an error if
52  // there is ambiguity.
53  // Full method name is in the form of Service.Method, it's good to be used in
54  // descriptor database queries.
56 
57  // Formatted method name is in the form of /Service/Method, it's good to be
58  // used as the argument of Stub::Call()
60 
73  const std::string& formatted_proto,
74  bool is_request,
75  bool is_json_format);
76 
82  const std::string& message_type_name, const std::string& formatted_proto,
83  bool is_json_format);
84 
93  const std::string& serialized_proto,
94  bool is_request,
95  bool is_json_format);
96 
103  const std::string& message_type_name, const std::string& serialized_proto,
104  bool is_json_format);
105 
106  bool IsStreaming(const std::string& method, bool is_request);
107 
108  bool HasError() const { return has_error_; }
109 
110  void LogError(const std::string& error_msg);
111 
112  private:
114  bool is_request);
115 
119  std::unique_ptr<ErrorPrinter> error_printer_;
120  std::unique_ptr<protobuf::compiler::Importer> importer_;
121  std::unique_ptr<grpc::ProtoReflectionDescriptorDatabase> reflection_db_;
122  std::unique_ptr<protobuf::DescriptorPoolDatabase> file_db_;
123  std::unique_ptr<protobuf::DescriptorDatabase> desc_db_;
124  std::unique_ptr<protobuf::DescriptorPool> desc_pool_;
125  std::unique_ptr<protobuf::DynamicMessageFactory> dynamic_factory_;
126  std::unique_ptr<grpc::protobuf::Message> request_prototype_;
127  std::unique_ptr<grpc::protobuf::Message> response_prototype_;
128  std::unordered_map<std::string, std::string> known_methods_;
129  std::vector<const protobuf::ServiceDescriptor*> service_desc_list_;
130 };
131 
132 } // namespace testing
133 } // namespace grpc
134 
135 #endif // GRPC_TEST_CPP_UTIL_PROTO_FILE_PARSER_H
grpc::testing::ProtoFileParser::reflection_db_
std::unique_ptr< grpc::ProtoReflectionDescriptorDatabase > reflection_db_
Definition: proto_file_parser.h:121
testing
Definition: aws_request_signer_test.cc:25
grpc::testing::ProtoFileParser::known_methods_
std::unordered_map< std::string, std::string > known_methods_
Definition: proto_file_parser.h:128
grpc::testing::ProtoFileParser::desc_db_
std::unique_ptr< protobuf::DescriptorDatabase > desc_db_
Definition: proto_file_parser.h:123
grpc::testing::ProtoFileParser::service_desc_list_
std::vector< const protobuf::ServiceDescriptor * > service_desc_list_
Definition: proto_file_parser.h:129
grpc::testing::ProtoFileParser::GetSerializedProtoFromMethod
std::string GetSerializedProtoFromMethod(const std::string &method, const std::string &formatted_proto, bool is_request, bool is_json_format)
Definition: proto_file_parser.cc:226
grpc
Definition: grpcpp/alarm.h:33
grpc::testing::ProtoFileParser::GetFullMethodName
std::string GetFullMethodName(const std::string &method)
Definition: proto_file_parser.cc:138
grpc::testing::ProtoFileParser::request_prototype_
std::unique_ptr< grpc::protobuf::Message > request_prototype_
Definition: proto_file_parser.h:126
grpc::testing::ProtoFileParser::error_printer_
std::unique_ptr< ErrorPrinter > error_printer_
Definition: proto_file_parser.h:119
grpc::testing::ProtoFileParser::HasError
bool HasError() const
Definition: proto_file_parser.h:108
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::testing::ProtoFileParser::GetFormattedStringFromMethod
std::string GetFormattedStringFromMethod(const std::string &method, const std::string &serialized_proto, bool is_request, bool is_json_format)
Definition: proto_file_parser.cc:238
grpc::testing::ProtoFileParser::ProtoFileParser
ProtoFileParser(const std::shared_ptr< grpc::Channel > &channel, const std::string &proto_path, const std::string &protofiles)
Definition: proto_file_parser.cc:69
grpc::testing::ProtoFileParser::GetSerializedProtoFromMessageType
std::string GetSerializedProtoFromMessageType(const std::string &message_type_name, const std::string &formatted_proto, bool is_json_format)
Definition: proto_file_parser.cc:250
grpc::testing::ProtoFileParser::LogError
void LogError(const std::string &error_msg)
Definition: proto_file_parser.cc:324
grpc::protobuf::compiler::DiskSourceTree
GRPC_CUSTOM_DISKSOURCETREE DiskSourceTree
Definition: config_grpc_cli.h:62
grpc::testing::ProtoFileParser::desc_pool_
std::unique_ptr< protobuf::DescriptorPool > desc_pool_
Definition: proto_file_parser.h:124
grpc::testing::ProtoFileParser::file_db_
std::unique_ptr< protobuf::DescriptorPoolDatabase > file_db_
Definition: proto_file_parser.h:122
proto_reflection_descriptor_database.h
grpc::testing::ProtoFileParser::source_tree_
protobuf::compiler::DiskSourceTree source_tree_
Definition: proto_file_parser.h:118
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
grpc::testing::ProtoFileParser::has_error_
bool has_error_
Definition: proto_file_parser.h:116
channel.h
grpc::testing::ProtoFileParser::GetMessageTypeFromMethod
std::string GetMessageTypeFromMethod(const std::string &method, bool is_request)
Definition: proto_file_parser.cc:189
grpc::testing::ProtoFileParser::request_text_
std::string request_text_
Definition: proto_file_parser.h:117
config_grpc_cli.h
grpc::testing::ProtoFileParser::GetFormattedMethodName
std::string GetFormattedMethodName(const std::string &method)
Definition: proto_file_parser.cc:175
grpc::testing::ProtoFileParser::IsStreaming
bool IsStreaming(const std::string &method, bool is_request)
Definition: proto_file_parser.cc:207
grpc::testing::ProtoFileParser
Definition: proto_file_parser.h:40
grpc::testing::ProtoFileParser::importer_
std::unique_ptr< protobuf::compiler::Importer > importer_
Definition: proto_file_parser.h:120
grpc::testing::ProtoFileParser::dynamic_factory_
std::unique_ptr< protobuf::DynamicMessageFactory > dynamic_factory_
Definition: proto_file_parser.h:125
grpc::testing::ProtoFileParser::response_prototype_
std::unique_ptr< grpc::protobuf::Message > response_prototype_
Definition: proto_file_parser.h:127
method
NSString * method
Definition: ProtoMethod.h:28
grpc::testing::ProtoFileParser::GetFormattedStringFromMessageType
std::string GetFormattedStringFromMessageType(const std::string &message_type_name, const std::string &serialized_proto, bool is_json_format)
Definition: proto_file_parser.cc:288
grpc::testing::ProtoFileParser::~ProtoFileParser
~ProtoFileParser()
Definition: proto_file_parser.cc:136


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:56