19 #ifndef GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_HELPERS_H
20 #define GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_HELPERS_H
49 typedef vector<const Descriptor*> DescriptorVector;
50 typedef vector<std::string> StringVector;
54 const std::vector<std::string>& prefixes_to_filter) {
55 for (
const auto&
prefix : prefixes_to_filter) {
56 if (raw_module_name.rfind(
prefix, 0) == 0) {
57 return raw_module_name.substr(
prefix.size(),
58 raw_module_name.size() -
prefix.size());
61 return raw_module_name;
69 const std::vector<std::string>& prefixes_to_filter) {
73 return StripModulePrefixes(import_prefix + basename +
"_pb2",
82 const std::vector<std::string>& prefixes_to_filter) {
93 bool GetModuleAndMessagePath(
96 const std::vector<std::string>& prefixes_to_filter) {
98 DescriptorVector message_path;
100 message_path.push_back(path_elem_type);
101 path_elem_type = path_elem_type->containing_type();
102 }
while (path_elem_type);
104 static const int proto_suffix_length = strlen(
".proto");
105 if (!(file_name.size() >
static_cast<size_t>(proto_suffix_length) &&
106 file_name.find_last_of(
".proto") == file_name.size() - 1)) {
112 module = ModuleAlias(file_name, import_prefix, prefixes_to_filter) +
".";
117 for (DescriptorVector::reverse_iterator path_iter = message_path.rbegin();
118 path_iter != message_path.rend(); ++path_iter) {
127 template <
typename DescriptorType>
128 StringVector get_all_comments(
const DescriptorType*
descriptor) {
129 StringVector comments;
140 std::vector<std::string>* append_to) {
143 append_to->emplace_back();
145 auto current =
s.begin();
146 while (current <
s.end()) {
148 append_to->emplace_back(current,
next);
150 if (current !=
s.end()) {
162 #endif // GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_HELPERS_H