Skip to content

Commit 2f4ad9a

Browse files
committed
Change some name spaces
Signed-off-by: Wayne Zhang <[email protected]>
1 parent 8285079 commit 2f4ad9a

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

src/request_message_translator.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include "grpc_transcoding/prefix_writer.h"
2525
#include "grpc_transcoding/request_weaver.h"
2626

27-
namespace pb = ::google::protobuf;
28-
namespace pbutil = ::google::protobuf::util;
2927
namespace pbconv = ::google::protobuf::util::converter;
3028

3129
namespace google {

src/type_helper.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <string>
2626
#include <unordered_map>
2727

28-
namespace pb = ::google::protobuf;
2928
namespace pbutil = ::google::protobuf::util;
3029
namespace pbconv = ::google::protobuf::util::converter;
3130
namespace pberr = ::google::protobuf::util::error;
@@ -41,21 +40,22 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
4140
public:
4241
SimpleTypeResolver() : url_prefix_(DEFAULT_URL_PREFIX) {}
4342

44-
void AddType(const pb::Type& t) {
43+
void AddType(const google::protobuf::Type& t) {
4544
type_map_.emplace(url_prefix_ + t.name(), &t);
4645
// A temporary workaround for service configs that use
4746
// "proto2.MessageOptions.*" options.
48-
ReplaceProto2WithGoogleProtobufInOptionNames(const_cast<pb::Type*>(&t));
47+
ReplaceProto2WithGoogleProtobufInOptionNames(
48+
const_cast<google::protobuf::Type*>(&t));
4949
}
5050

51-
void AddEnum(const pb::Enum& e) {
51+
void AddEnum(const google::protobuf::Enum& e) {
5252
enum_map_.emplace(url_prefix_ + e.name(), &e);
5353
}
5454

5555
// TypeResolver implementation
5656
// 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 {
5959
auto i = type_map_.find(type_url);
6060
if (end(type_map_) != i) {
6161
if (nullptr != type) {
@@ -69,8 +69,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
6969
}
7070

7171
// 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 {
7474
auto i = enum_map_.find(type_url);
7575
if (end(enum_map_) != i) {
7676
if (nullptr != enum_type) {
@@ -84,7 +84,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
8484
}
8585

8686
private:
87-
void ReplaceProto2WithGoogleProtobufInOptionNames(pb::Type* type) {
87+
void ReplaceProto2WithGoogleProtobufInOptionNames(
88+
google::protobuf::Type* type) {
8889
// As a temporary workaround for service configs that use
8990
// "proto2.MessageOptions.*" options instead of
9091
// "google.protobuf.MessageOptions.*", we replace the option names to make
@@ -101,8 +102,8 @@ class SimpleTypeResolver : public pbutil::TypeResolver {
101102
}
102103

103104
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_;
106107

107108
SimpleTypeResolver(const SimpleTypeResolver&) = delete;
108109
SimpleTypeResolver& operator=(const SimpleTypeResolver&) = delete;
@@ -126,32 +127,33 @@ void TypeHelper::Initialize() {
126127
type_info_.reset(pbconv::TypeInfo::NewTypeInfo(type_resolver_));
127128
}
128129

129-
void TypeHelper::AddType(const pb::Type& t) {
130+
void TypeHelper::AddType(const google::protobuf::Type& t) {
130131
reinterpret_cast<SimpleTypeResolver*>(type_resolver_)->AddType(t);
131132
}
132133

133-
void TypeHelper::AddEnum(const pb::Enum& e) {
134+
void TypeHelper::AddEnum(const google::protobuf::Enum& e) {
134135
reinterpret_cast<SimpleTypeResolver*>(type_resolver_)->AddEnum(e);
135136
}
136137

137138
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 {
140141
// Split the field names & call ResolveFieldPath()
141142
const std::vector<std::string> field_names =
142143
absl::StrSplit(field_path_str, '.', absl::SkipEmpty());
143144
return ResolveFieldPath(type, field_names, field_path_out);
144145
}
145146

146147
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 {
149151
// The type of the current message being processed (initially the type of the
150152
// top level message)
151153
auto current_type = &type;
152154

153155
// The resulting field path
154-
std::vector<const pb::Field*> field_path;
156+
std::vector<const google::protobuf::Field*> field_path;
155157

156158
for (size_t i = 0; i < field_names.size(); ++i) {
157159
// Find the field by name in the current type
@@ -166,7 +168,7 @@ pbutil::Status TypeHelper::ResolveFieldPath(
166168

167169
if (i < field_names.size() - 1) {
168170
// 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()) {
170172
return pbutil::Status(
171173
pberr::INVALID_ARGUMENT,
172174
"Encountered a non-leaf field \"" + field->name() +

test/type_helper_test.cc

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include "gtest/gtest.h"
2828
#include "test_common.h"
2929

30-
namespace pb = ::google::protobuf;
31-
3230
namespace google {
3331
namespace grpc {
3432

@@ -42,30 +40,30 @@ class TypeHelperTest : public ::testing::Test {
4240
TypeHelperTest() : types_(), enums_() {}
4341

4442
void AddType(const std::string& n) {
45-
pb::Type t;
43+
google::protobuf::Type t;
4644
t.set_name(n);
4745
types_.emplace_back(std::move(t));
4846
}
4947

5048
void AddEnum(const std::string& n) {
51-
pb::Enum e;
49+
google::protobuf::Enum e;
5250
e.set_name(n);
5351
enums_.emplace_back(std::move(e));
5452
}
5553

5654
void Build() { helper_.reset(new TypeHelper(types_, enums_)); }
5755

58-
const pb::Type* GetType(const std::string& url) {
56+
const google::protobuf::Type* GetType(const std::string& url) {
5957
return helper_->Info()->GetTypeByTypeUrl(url);
6058
}
6159

62-
const pb::Enum* GetEnum(const std::string& url) {
60+
const google::protobuf::Enum* GetEnum(const std::string& url) {
6361
return helper_->Info()->GetEnumByTypeUrl(url);
6462
}
6563

6664
private:
67-
std::vector<pb::Type> types_;
68-
std::vector<pb::Enum> enums_;
65+
std::vector<google::protobuf::Type> types_;
66+
std::vector<google::protobuf::Enum> enums_;
6967
std::unique_ptr<TypeHelper> helper_;
7068
};
7169

@@ -136,26 +134,26 @@ class ServiceConfigBasedTypeHelperTest : public ::testing::Test {
136134
return true;
137135
}
138136

139-
const pb::Type* GetType(const std::string& url) {
137+
const google::protobuf::Type* GetType(const std::string& url) {
140138
return helper_->Info()->GetTypeByTypeUrl(url);
141139
}
142140

143-
const pb::Enum* GetEnum(const std::string& url) {
141+
const google::protobuf::Enum* GetEnum(const std::string& url) {
144142
return helper_->Info()->GetEnumByTypeUrl(url);
145143
}
146144

147-
const pb::Field* GetField(const std::string& type_url,
148-
const std::string& field_name) {
145+
const google::protobuf::Field* GetField(const std::string& type_url,
146+
const std::string& field_name) {
149147
auto t = GetType(type_url);
150148
if (nullptr == t) {
151149
return nullptr;
152150
}
153151
return helper_->Info()->FindField(t, field_name);
154152
}
155153

156-
bool ResolveFieldPath(const std::string& type_name,
157-
const std::string& field_path_str,
158-
std::vector<const pb::Field*>* field_path) {
154+
bool ResolveFieldPath(
155+
const std::string& type_name, const std::string& field_path_str,
156+
std::vector<const google::protobuf::Field*>* field_path) {
159157
auto type = GetType("type.googleapis.com/" + type_name);
160158
if (nullptr == type) {
161159
ADD_FAILURE() << "Could not find top level type \"" + type_name + "\""
@@ -186,8 +184,9 @@ TEST_F(ServiceConfigBasedTypeHelperTest, FullTypeTests) {
186184
ASSERT_NE(nullptr, t);
187185
EXPECT_EQ("CreateShelfRequest", t->name());
188186
EXPECT_EQ(1, t->fields_size());
189-
EXPECT_EQ(pb::Field::TYPE_MESSAGE, t->fields(0).kind());
190-
EXPECT_EQ(pb::Field::CARDINALITY_OPTIONAL, t->fields(0).cardinality());
187+
EXPECT_EQ(google::protobuf::Field::TYPE_MESSAGE, t->fields(0).kind());
188+
EXPECT_EQ(google::protobuf::Field::CARDINALITY_OPTIONAL,
189+
t->fields(0).cardinality());
191190
EXPECT_EQ(1, t->fields(0).number());
192191
EXPECT_EQ("shelf", t->fields(0).name());
193192
EXPECT_EQ("type.googleapis.com/Shelf", t->fields(0).type_url());
@@ -197,12 +196,14 @@ TEST_F(ServiceConfigBasedTypeHelperTest, FullTypeTests) {
197196
ASSERT_NE(nullptr, t);
198197
EXPECT_EQ("Shelf", t->name());
199198
EXPECT_EQ(2, t->fields_size());
200-
EXPECT_EQ(pb::Field::TYPE_STRING, t->fields(0).kind());
201-
EXPECT_EQ(pb::Field::CARDINALITY_OPTIONAL, t->fields(0).cardinality());
199+
EXPECT_EQ(google::protobuf::Field::TYPE_STRING, t->fields(0).kind());
200+
EXPECT_EQ(google::protobuf::Field::CARDINALITY_OPTIONAL,
201+
t->fields(0).cardinality());
202202
EXPECT_EQ(1, t->fields(0).number());
203203
EXPECT_EQ("name", t->fields(0).name());
204-
EXPECT_EQ(pb::Field::TYPE_STRING, t->fields(1).kind());
205-
EXPECT_EQ(pb::Field::CARDINALITY_OPTIONAL, t->fields(1).cardinality());
204+
EXPECT_EQ(google::protobuf::Field::TYPE_STRING, t->fields(1).kind());
205+
EXPECT_EQ(google::protobuf::Field::CARDINALITY_OPTIONAL,
206+
t->fields(1).cardinality());
206207
EXPECT_EQ(2, t->fields(1).number());
207208
EXPECT_EQ("theme", t->fields(1).name());
208209
}
@@ -293,7 +294,7 @@ TEST_F(ServiceConfigBasedTypeHelperTest, FindFieldCamelCaseTests) {
293294
TEST_F(ServiceConfigBasedTypeHelperTest, ResolveFieldPathTests) {
294295
ASSERT_TRUE(LoadService("bookstore_service.pb.txt"));
295296

296-
std::vector<const pb::Field*> field_path;
297+
std::vector<const google::protobuf::Field*> field_path;
297298

298299
// empty
299300
EXPECT_TRUE(ResolveFieldPath("Shelf", "", &field_path));

0 commit comments

Comments
 (0)