25
25
#include < string>
26
26
#include < unordered_map>
27
27
28
- namespace pb = ::google::protobuf;
29
28
namespace pbutil = ::google::protobuf::util;
30
29
namespace pbconv = ::google::protobuf::util::converter;
31
30
namespace pberr = ::google::protobuf::util::error;
@@ -41,21 +40,22 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
41
40
public:
42
41
SimpleTypeResolver () : url_prefix_(DEFAULT_URL_PREFIX) {}
43
42
44
- void AddType (const pb ::Type& t) {
43
+ void AddType (const google::protobuf ::Type& t) {
45
44
type_map_.emplace (url_prefix_ + t.name (), &t);
46
45
// A temporary workaround for service configs that use
47
46
// "proto2.MessageOptions.*" options.
48
- ReplaceProto2WithGoogleProtobufInOptionNames (const_cast <pb::Type*>(&t));
47
+ ReplaceProto2WithGoogleProtobufInOptionNames (
48
+ const_cast <google::protobuf::Type*>(&t));
49
49
}
50
50
51
- void AddEnum (const pb ::Enum& e) {
51
+ void AddEnum (const google::protobuf ::Enum& e) {
52
52
enum_map_.emplace (url_prefix_ + e.name (), &e);
53
53
}
54
54
55
55
// TypeResolver implementation
56
56
// Resolves a type url for a message type.
57
- virtual pbutil::Status ResolveMessageType (const std::string& type_url,
58
- pb ::Type* type) override {
57
+ virtual pbutil::Status ResolveMessageType (
58
+ const std::string& type_url, google::protobuf ::Type* type) override {
59
59
auto i = type_map_.find (type_url);
60
60
if (end (type_map_) != i) {
61
61
if (nullptr != type) {
@@ -69,8 +69,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
69
69
}
70
70
71
71
// Resolves a type url for an enum type.
72
- virtual pbutil::Status ResolveEnumType (const std::string& type_url,
73
- pb ::Enum* enum_type) override {
72
+ virtual pbutil::Status ResolveEnumType (
73
+ const std::string& type_url, google::protobuf ::Enum* enum_type) override {
74
74
auto i = enum_map_.find (type_url);
75
75
if (end (enum_map_) != i) {
76
76
if (nullptr != enum_type) {
@@ -84,7 +84,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
84
84
}
85
85
86
86
private:
87
- void ReplaceProto2WithGoogleProtobufInOptionNames (pb::Type* type) {
87
+ void ReplaceProto2WithGoogleProtobufInOptionNames (
88
+ google::protobuf::Type* type) {
88
89
// As a temporary workaround for service configs that use
89
90
// "proto2.MessageOptions.*" options instead of
90
91
// "google.protobuf.MessageOptions.*", we replace the option names to make
@@ -101,8 +102,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
101
102
}
102
103
103
104
std::string url_prefix_;
104
- std::unordered_map<std::string, const pb ::Type*> type_map_;
105
- std::unordered_map<std::string, const pb ::Enum*> enum_map_;
105
+ std::unordered_map<std::string, const google::protobuf ::Type*> type_map_;
106
+ std::unordered_map<std::string, const google::protobuf ::Enum*> enum_map_;
106
107
107
108
SimpleTypeResolver (const SimpleTypeResolver&) = delete ;
108
109
SimpleTypeResolver& operator =(const SimpleTypeResolver&) = delete ;
@@ -126,32 +127,33 @@ void TypeHelper::Initialize() {
126
127
type_info_.reset (pbconv::TypeInfo::NewTypeInfo (type_resolver_));
127
128
}
128
129
129
- void TypeHelper::AddType (const pb ::Type& t) {
130
+ void TypeHelper::AddType (const google::protobuf ::Type& t) {
130
131
reinterpret_cast <SimpleTypeResolver*>(type_resolver_)->AddType (t);
131
132
}
132
133
133
- void TypeHelper::AddEnum (const pb ::Enum& e) {
134
+ void TypeHelper::AddEnum (const google::protobuf ::Enum& e) {
134
135
reinterpret_cast <SimpleTypeResolver*>(type_resolver_)->AddEnum (e);
135
136
}
136
137
137
138
pbutil::Status TypeHelper::ResolveFieldPath (
138
- const pb ::Type& type, const std::string& field_path_str,
139
- std::vector<const pb ::Field*>* field_path_out) const {
139
+ const google::protobuf ::Type& type, const std::string& field_path_str,
140
+ std::vector<const google::protobuf ::Field*>* field_path_out) const {
140
141
// Split the field names & call ResolveFieldPath()
141
142
const std::vector<std::string> field_names =
142
143
absl::StrSplit (field_path_str, ' .' , absl::SkipEmpty ());
143
144
return ResolveFieldPath (type, field_names, field_path_out);
144
145
}
145
146
146
147
pbutil::Status TypeHelper::ResolveFieldPath (
147
- const pb::Type& type, const std::vector<std::string>& field_names,
148
- std::vector<const pb::Field*>* field_path_out) const {
148
+ const google::protobuf::Type& type,
149
+ const std::vector<std::string>& field_names,
150
+ std::vector<const google::protobuf::Field*>* field_path_out) const {
149
151
// The type of the current message being processed (initially the type of the
150
152
// top level message)
151
153
auto current_type = &type;
152
154
153
155
// The resulting field path
154
- std::vector<const pb ::Field*> field_path;
156
+ std::vector<const google::protobuf ::Field*> field_path;
155
157
156
158
for (size_t i = 0 ; i < field_names.size (); ++i) {
157
159
// Find the field by name in the current type
@@ -166,7 +168,7 @@ pbutil::Status TypeHelper::ResolveFieldPath(
166
168
167
169
if (i < field_names.size () - 1 ) {
168
170
// If this is not the last field in the path, it must be a message
169
- if (pb ::Field::TYPE_MESSAGE != field->kind ()) {
171
+ if (google::protobuf ::Field::TYPE_MESSAGE != field->kind ()) {
170
172
return pbutil::Status (
171
173
pberr::INVALID_ARGUMENT,
172
174
" Encountered a non-leaf field \" " + field->name () +
0 commit comments