Skip to content

Commit e69251e

Browse files
authored
Add a header to alias protobuf internal types (#20)
* Add a header to alias protobuf internal types Signed-off-by: Lizan Zhou <[email protected]> * fix style Signed-off-by: Lizan Zhou <[email protected]>
1 parent 6c54b75 commit e69251e

12 files changed

+155
-115
lines changed

repositories.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def protobuf_repositories(bind=True):
1818
native.git_repository(
1919
name = "protobuf_git",
20-
commit = "593e917c176b5bc5aafa57bf9f6030d749d91cd5", # v3.2.0
20+
commit = "106ffc04be1abf3ff3399f54ccf149815b287dd9", # v3.5.1
2121
remote = "https://github.com/google/protobuf.git",
2222
)
2323

@@ -118,7 +118,7 @@ cc_library(
118118
native.new_git_repository(
119119
name = "googletest_git",
120120
build_file_content = BUILD,
121-
commit = "d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0",
121+
commit = "43863938377a9ea1399c0596269e0890b5c5515a",
122122
remote = "https://github.com/google/googletest.git",
123123
)
124124

@@ -237,7 +237,7 @@ cc_proto_library(
237237

238238
native.new_git_repository(
239239
name = "googleapis_git",
240-
commit = "2fe0050bd2a6d4c6ba798c0311f0b149b8997314",
240+
commit = "5c6df0cd18c6a429eab739fb711c27f6e1393366", # May 14, 2017
241241
remote = "https://github.com/googleapis/googleapis.git",
242242
build_file_content = BUILD,
243243
)

src/BUILD

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
#
1717
package(default_visibility = ["//visibility:public"])
1818

19+
cc_library(
20+
name = "protobuf",
21+
hdrs = [
22+
"include/grpc_transcoding/internal/protobuf_types.h",
23+
],
24+
includes = [
25+
"include/",
26+
],
27+
deps = [
28+
"//external:protobuf",
29+
]
30+
)
31+
1932
cc_library(
2033
name = "prefix_writer",
2134
srcs = [
@@ -28,7 +41,7 @@ cc_library(
2841
"include/"
2942
],
3043
deps = [
31-
"//external:protobuf",
44+
":protobuf",
3245
],
3346
)
3447

@@ -44,7 +57,7 @@ cc_library(
4457
"include/"
4558
],
4659
deps = [
47-
"//external:protobuf",
60+
":protobuf",
4861
],
4962
)
5063

@@ -80,7 +93,7 @@ cc_library(
8093
":message_stream",
8194
":prefix_writer",
8295
":request_weaver",
83-
"//external:protobuf",
96+
":protobuf",
8497
],
8598
)
8699

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Copyright 2016 Google Inc. All Rights Reserved.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
#ifndef GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_
16+
#define GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_
17+
18+
namespace google {
19+
namespace grpc {
20+
namespace transcoding {
21+
namespace internal {
22+
23+
typedef ::google::protobuf::StringPiece string_view;
24+
25+
} // namespace internal
26+
} // namespace transcoding
27+
} // namespace grpc
28+
} // namespace google
29+
30+
#endif // GRPC_TRANSCODING_INTERNAL_PROTOBUF_TYPES_H_

src/include/grpc_transcoding/prefix_writer.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "google/protobuf/stubs/stringpiece.h"
2222
#include "google/protobuf/util/internal/object_writer.h"
23+
#include "grpc_transcoding/internal/protobuf_types.h"
2324

2425
namespace google {
2526
namespace grpc {
@@ -63,30 +64,30 @@ class PrefixWriter : public google::protobuf::util::converter::ObjectWriter {
6364
google::protobuf::util::converter::ObjectWriter* ow);
6465

6566
// ObjectWriter methods.
66-
PrefixWriter* StartObject(google::protobuf::StringPiece name);
67+
PrefixWriter* StartObject(internal::string_view name);
6768
PrefixWriter* EndObject();
68-
PrefixWriter* StartList(google::protobuf::StringPiece name);
69+
PrefixWriter* StartList(internal::string_view name);
6970
PrefixWriter* EndList();
70-
PrefixWriter* RenderBool(google::protobuf::StringPiece name, bool value);
71-
PrefixWriter* RenderInt32(google::protobuf::StringPiece name,
71+
PrefixWriter* RenderBool(internal::string_view name, bool value);
72+
PrefixWriter* RenderInt32(internal::string_view name,
7273
google::protobuf::int32 value);
73-
PrefixWriter* RenderUint32(google::protobuf::StringPiece name,
74+
PrefixWriter* RenderUint32(internal::string_view name,
7475
google::protobuf::uint32 value);
75-
PrefixWriter* RenderInt64(google::protobuf::StringPiece name,
76+
PrefixWriter* RenderInt64(internal::string_view name,
7677
google::protobuf::int64 value);
77-
PrefixWriter* RenderUint64(google::protobuf::StringPiece name,
78+
PrefixWriter* RenderUint64(internal::string_view name,
7879
google::protobuf::uint64 value);
79-
PrefixWriter* RenderDouble(google::protobuf::StringPiece name, double value);
80-
PrefixWriter* RenderFloat(google::protobuf::StringPiece name, float value);
81-
PrefixWriter* RenderString(google::protobuf::StringPiece name,
82-
google::protobuf::StringPiece value);
83-
PrefixWriter* RenderBytes(google::protobuf::StringPiece name,
84-
google::protobuf::StringPiece value);
85-
PrefixWriter* RenderNull(google::protobuf::StringPiece name);
80+
PrefixWriter* RenderDouble(internal::string_view name, double value);
81+
PrefixWriter* RenderFloat(internal::string_view name, float value);
82+
PrefixWriter* RenderString(internal::string_view name,
83+
internal::string_view value);
84+
PrefixWriter* RenderBytes(internal::string_view name,
85+
internal::string_view value);
86+
PrefixWriter* RenderNull(internal::string_view name);
8687

8788
private:
8889
// Helper method to start the prefix and return the name to use for the value.
89-
google::protobuf::StringPiece StartPrefix(google::protobuf::StringPiece name);
90+
internal::string_view StartPrefix(internal::string_view name);
9091

9192
// Helper method to end the prefix.
9293
void EndPrefix();

src/include/grpc_transcoding/request_message_translator.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "google/protobuf/util/internal/error_listener.h"
2424
#include "google/protobuf/util/internal/protostream_objectwriter.h"
2525
#include "google/protobuf/util/type_resolver.h"
26+
#include "grpc_transcoding/internal/protobuf_types.h"
2627
#include "message_stream.h"
2728
#include "prefix_writer.h"
2829
#include "request_weaver.h"
@@ -143,17 +144,15 @@ class RequestMessageTranslator : public MessageStream {
143144
void InvalidName(
144145
const ::google::protobuf::util::converter::LocationTrackerInterface&
145146
loc,
146-
::google::protobuf::StringPiece unknown_name,
147-
::google::protobuf::StringPiece message);
147+
internal::string_view unknown_name, internal::string_view message);
148148
void InvalidValue(
149149
const ::google::protobuf::util::converter::LocationTrackerInterface&
150150
loc,
151-
::google::protobuf::StringPiece type_name,
152-
::google::protobuf::StringPiece value);
151+
internal::string_view type_name, internal::string_view value);
153152
void MissingField(
154153
const ::google::protobuf::util::converter::LocationTrackerInterface&
155154
loc,
156-
::google::protobuf::StringPiece missing_name);
155+
internal::string_view missing_name);
157156

158157
private:
159158
::google::protobuf::util::Status status_;

src/include/grpc_transcoding/request_stream_translator.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "google/protobuf/stubs/stringpiece.h"
2323
#include "google/protobuf/util/internal/object_writer.h"
2424
#include "google/protobuf/util/type_resolver.h"
25+
#include "grpc_transcoding/internal/protobuf_types.h"
2526
#include "message_stream.h"
2627
#include "request_message_translator.h"
2728

@@ -75,29 +76,27 @@ class RequestStreamTranslator
7576

7677
private:
7778
// ObjectWriter methods.
78-
RequestStreamTranslator* StartObject(google::protobuf::StringPiece name);
79+
RequestStreamTranslator* StartObject(internal::string_view name);
7980
RequestStreamTranslator* EndObject();
80-
RequestStreamTranslator* StartList(google::protobuf::StringPiece name);
81+
RequestStreamTranslator* StartList(internal::string_view name);
8182
RequestStreamTranslator* EndList();
82-
RequestStreamTranslator* RenderBool(google::protobuf::StringPiece name,
83-
bool value);
84-
RequestStreamTranslator* RenderInt32(google::protobuf::StringPiece name,
83+
RequestStreamTranslator* RenderBool(internal::string_view name, bool value);
84+
RequestStreamTranslator* RenderInt32(internal::string_view name,
8585
google::protobuf::int32 value);
86-
RequestStreamTranslator* RenderUint32(google::protobuf::StringPiece name,
86+
RequestStreamTranslator* RenderUint32(internal::string_view name,
8787
google::protobuf::uint32 value);
88-
RequestStreamTranslator* RenderInt64(google::protobuf::StringPiece name,
88+
RequestStreamTranslator* RenderInt64(internal::string_view name,
8989
google::protobuf::int64 value);
90-
RequestStreamTranslator* RenderUint64(google::protobuf::StringPiece name,
90+
RequestStreamTranslator* RenderUint64(internal::string_view name,
9191
google::protobuf::uint64 value);
92-
RequestStreamTranslator* RenderDouble(google::protobuf::StringPiece name,
92+
RequestStreamTranslator* RenderDouble(internal::string_view name,
9393
double value);
94-
RequestStreamTranslator* RenderFloat(google::protobuf::StringPiece name,
95-
float value);
96-
RequestStreamTranslator* RenderString(google::protobuf::StringPiece name,
97-
google::protobuf::StringPiece value);
98-
RequestStreamTranslator* RenderBytes(google::protobuf::StringPiece name,
99-
google::protobuf::StringPiece value);
100-
RequestStreamTranslator* RenderNull(google::protobuf::StringPiece name);
94+
RequestStreamTranslator* RenderFloat(internal::string_view name, float value);
95+
RequestStreamTranslator* RenderString(internal::string_view name,
96+
internal::string_view value);
97+
RequestStreamTranslator* RenderBytes(internal::string_view name,
98+
internal::string_view value);
99+
RequestStreamTranslator* RenderNull(internal::string_view name);
101100

102101
// Sets up the ProtoMessageHelper to handle writing data.
103102
void StartMessageTranslator();
@@ -106,8 +105,7 @@ class RequestStreamTranslator
106105
void EndMessageTranslator();
107106

108107
// Helper method to render a single piece of data, to reuse code.
109-
void RenderData(google::protobuf::StringPiece name,
110-
std::function<void()> renderer);
108+
void RenderData(internal::string_view name, std::function<void()> renderer);
111109

112110
// TypeResolver to be passed to the RequestMessageTranslator
113111
google::protobuf::util::TypeResolver& type_resolver_;

src/include/grpc_transcoding/request_weaver.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "google/protobuf/stubs/stringpiece.h"
2424
#include "google/protobuf/type.pb.h"
2525
#include "google/protobuf/util/internal/object_writer.h"
26+
#include "grpc_transcoding/internal/protobuf_types.h"
2627

2728
namespace google {
2829
namespace grpc {
@@ -77,26 +78,26 @@ class RequestWeaver : public google::protobuf::util::converter::ObjectWriter {
7778
google::protobuf::util::converter::ObjectWriter* ow);
7879

7980
// ObjectWriter methods
80-
RequestWeaver* StartObject(google::protobuf::StringPiece name);
81+
RequestWeaver* StartObject(internal::string_view name);
8182
RequestWeaver* EndObject();
82-
RequestWeaver* StartList(google::protobuf::StringPiece name);
83+
RequestWeaver* StartList(internal::string_view name);
8384
RequestWeaver* EndList();
84-
RequestWeaver* RenderBool(google::protobuf::StringPiece name, bool value);
85-
RequestWeaver* RenderInt32(google::protobuf::StringPiece name,
85+
RequestWeaver* RenderBool(internal::string_view name, bool value);
86+
RequestWeaver* RenderInt32(internal::string_view name,
8687
google::protobuf::int32 value);
87-
RequestWeaver* RenderUint32(google::protobuf::StringPiece name,
88+
RequestWeaver* RenderUint32(internal::string_view name,
8889
google::protobuf::uint32 value);
89-
RequestWeaver* RenderInt64(google::protobuf::StringPiece name,
90+
RequestWeaver* RenderInt64(internal::string_view name,
9091
google::protobuf::int64 value);
91-
RequestWeaver* RenderUint64(google::protobuf::StringPiece name,
92+
RequestWeaver* RenderUint64(internal::string_view name,
9293
google::protobuf::uint64 value);
93-
RequestWeaver* RenderDouble(google::protobuf::StringPiece name, double value);
94-
RequestWeaver* RenderFloat(google::protobuf::StringPiece name, float value);
95-
RequestWeaver* RenderString(google::protobuf::StringPiece name,
96-
google::protobuf::StringPiece value);
97-
RequestWeaver* RenderNull(google::protobuf::StringPiece name);
98-
RequestWeaver* RenderBytes(google::protobuf::StringPiece name,
99-
google::protobuf::StringPiece value);
94+
RequestWeaver* RenderDouble(internal::string_view name, double value);
95+
RequestWeaver* RenderFloat(internal::string_view name, float value);
96+
RequestWeaver* RenderString(internal::string_view name,
97+
internal::string_view value);
98+
RequestWeaver* RenderNull(internal::string_view name);
99+
RequestWeaver* RenderBytes(internal::string_view name,
100+
internal::string_view value);
100101

101102
private:
102103
// Container for information to be weaved.
@@ -110,7 +111,7 @@ class RequestWeaver : public google::protobuf::util::converter::ObjectWriter {
110111
std::list<std::pair<const google::protobuf::Field*, std::string>> bindings;
111112

112113
// Find the entry for the speciied field in messages list .
113-
WeaveInfo* FindWeaveMsg(google::protobuf::StringPiece field_name);
114+
WeaveInfo* FindWeaveMsg(internal::string_view field_name);
114115

115116
// Create an entry in messages for the given field. The caller must make
116117
// sure that there is no existing entry for the same field before calling.
@@ -129,7 +130,7 @@ class RequestWeaver : public google::protobuf::util::converter::ObjectWriter {
129130

130131
// Checks if any repeated fields with the same field name are in the current
131132
// node of the weave tree. Output them if there are any.
132-
void CollisionCheck(google::protobuf::StringPiece name);
133+
void CollisionCheck(internal::string_view name);
133134

134135
// All the headers, variable bindings and parameter bindings to be weaved in.
135136
// root_ : root of the tree to be weaved in.

src/json_request_translator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "google/protobuf/stubs/status.h"
2323
#include "google/protobuf/util/internal/json_stream_parser.h"
2424
#include "google/protobuf/util/internal/object_writer.h"
25+
#include "grpc_transcoding/internal/protobuf_types.h"
2526
#include "grpc_transcoding/message_stream.h"
2627
#include "grpc_transcoding/request_message_translator.h"
2728
#include "grpc_transcoding/request_stream_translator.h"
@@ -103,7 +104,7 @@ class LazyRequestTranslator : public MessageStream {
103104

104105
// Feed the chunk to the parser & check the status.
105106
status_ = json_parser_->Parse(
106-
pb::StringPiece(reinterpret_cast<const char*>(data), size));
107+
internal::string_view(reinterpret_cast<const char*>(data), size));
107108
if (!status_.ok()) {
108109
return false;
109110
}

0 commit comments

Comments
 (0)