diff --git a/WORKSPACE b/WORKSPACE index 51ee7836a..c72bdb7de 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -26,7 +26,7 @@ # # A Bazel (http://bazel.io) workspace for the Google Cloud Endpoints runtime. -ISTIO_PROXY = "557d0c6a7f1136e98ca1a05494df0b51c5bad7d2" +ISTIO_PROXY = "987223f6ce6998a8af0f3524545bed7f0d0a1ebb" git_repository( name = "nginx", @@ -158,7 +158,7 @@ git_repository( # git_repository( name = "io_bazel_rules_go", - commit = "76c63b5cd0d47c1f2b47ab4953db96c574af1c1d", + commit = "2d9f328a9723baf2d037ba9db28d9d0e30683938", # Apr 6, 2017 (buildifier fix) remote = "https://github.com/bazelbuild/rules_go.git", ) diff --git a/src/grpc/BUILD b/src/grpc/BUILD index c51aa23c6..f6a850b10 100644 --- a/src/grpc/BUILD +++ b/src/grpc/BUILD @@ -58,6 +58,7 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ + "@istio_proxy_git//contrib/endpoints/src/grpc/transcoding:transcoder_input_stream", "//external:grpc", "//external:grpc++", "//external:protobuf", diff --git a/src/grpc/zero_copy_stream.cc b/src/grpc/zero_copy_stream.cc index dd76a3d23..3a037ea4c 100644 --- a/src/grpc/zero_copy_stream.cc +++ b/src/grpc/zero_copy_stream.cc @@ -68,7 +68,7 @@ void GrpcZeroCopyInputStream::BackUp(int count) { } } -::google::protobuf::int64 GrpcZeroCopyInputStream::ByteCount() const { +int64_t GrpcZeroCopyInputStream::BytesAvailable() const { return (current_buffer_size_ - position_) + serializer_.ByteCount(); } diff --git a/src/grpc/zero_copy_stream.h b/src/grpc/zero_copy_stream.h index b6a215bfe..c0de9e278 100644 --- a/src/grpc/zero_copy_stream.h +++ b/src/grpc/zero_copy_stream.h @@ -28,6 +28,7 @@ #include +#include "contrib/endpoints/src/grpc/transcoding/transcoder_input_stream.h" #include "google/protobuf/io/zero_copy_stream.h" #include "grpc++/support/byte_buffer.h" #include "src/grpc/message_serializer.h" @@ -38,7 +39,7 @@ namespace grpc { // ZeroCopyInputStream implementation over a stream of gRPC messages. class GrpcZeroCopyInputStream - : public ::google::protobuf::io::ZeroCopyInputStream { + : public ::google::api_manager::transcoding::TranscoderInputStream { public: GrpcZeroCopyInputStream(); @@ -53,8 +54,9 @@ class GrpcZeroCopyInputStream bool Next(const void** data, int* size); void BackUp(int count); - bool Skip(int count) { return false; } // not supported - ::google::protobuf::int64 ByteCount() const; + bool Skip(int count) { return false; } // not supported + ::google::protobuf::int64 ByteCount() const { return 0; } // Not implemented + int64_t BytesAvailable() const; private: GrpcMessageSerializer serializer_; diff --git a/src/grpc/zero_copy_stream_test.cc b/src/grpc/zero_copy_stream_test.cc index f21d42296..6b12cde25 100644 --- a/src/grpc/zero_copy_stream_test.cc +++ b/src/grpc/zero_copy_stream_test.cc @@ -86,10 +86,10 @@ TEST_F(GrpcZeroCopyInputStreamTest, SimpleRead) { stream.AddMessage(CreateByteBuffer(SliceData{slice21, slice22}), true); stream.Finish(); - // Test ByteCount() + // Test BytesAvailable() EXPECT_EQ(slice11.size() + slice12.size() + slice21.size() + slice22.size() + 10, // +10 bytes for two delimiters - stream.ByteCount()); + stream.BytesAvailable()); // Test the message1 delimiter ASSERT_TRUE(stream.Next(&data, &size)); @@ -97,28 +97,28 @@ TEST_F(GrpcZeroCopyInputStreamTest, SimpleRead) { EXPECT_EQ(slice11.size() + slice12.size(), DelimiterToSize(reinterpret_cast(data))); - // Test ByteCount() + // Test BytesAvailable() EXPECT_EQ(slice11.size() + slice12.size() + slice21.size() + slice22.size() + 5, // +5 bytes for one delimiter - stream.ByteCount()); + stream.BytesAvailable()); // Test the slices ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice11.size(), size); EXPECT_EQ(slice11, std::string(reinterpret_cast(data), size)); - // Test ByteCount() + // Test BytesAvailable() EXPECT_EQ(slice12.size() + slice21.size() + slice22.size() + 5, // +5 bytes for one delimiter - stream.ByteCount()); + stream.BytesAvailable()); ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice12.size(), size); EXPECT_EQ(slice12, std::string(reinterpret_cast(data), size)); - // Test ByteCount() + // Test BytesAvailable() EXPECT_EQ(slice21.size() + slice22.size() + 5, // +5 bytes for one delimiter - stream.ByteCount()); + stream.BytesAvailable()); // Test the message2 delimiter ASSERT_TRUE(stream.Next(&data, &size)); @@ -126,23 +126,23 @@ TEST_F(GrpcZeroCopyInputStreamTest, SimpleRead) { EXPECT_EQ(slice21.size() + slice22.size(), DelimiterToSize(reinterpret_cast(data))); - // Test ByteCount() - EXPECT_EQ(slice21.size() + slice22.size(), stream.ByteCount()); + // Test BytesAvailable() + EXPECT_EQ(slice21.size() + slice22.size(), stream.BytesAvailable()); // Test the slices ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice21.size(), size); EXPECT_EQ(slice21, std::string(reinterpret_cast(data), size)); - // Test ByteCount() - EXPECT_EQ(slice22.size(), stream.ByteCount()); + // Test BytesAvailable() + EXPECT_EQ(slice22.size(), stream.BytesAvailable()); ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice22.size(), size); EXPECT_EQ(slice22, std::string(reinterpret_cast(data), size)); // Test the end of the stream - EXPECT_EQ(0, stream.ByteCount()); + EXPECT_EQ(0, stream.BytesAvailable()); EXPECT_FALSE(stream.Next(&data, &size)); } @@ -167,9 +167,9 @@ TEST_F(GrpcZeroCopyInputStreamTest, Backups) { // Back up stream.BackUp(5); - // Test the ByteCount() + // Test the BytesAvailable() EXPECT_EQ(slice1.size() + slice2.size() + 5, // +5 bytes for the delimiter - stream.ByteCount()); + stream.BytesAvailable()); // Test the slice again ASSERT_TRUE(stream.Next(&data, &size)); @@ -184,14 +184,14 @@ TEST_F(GrpcZeroCopyInputStreamTest, Backups) { // Back up & test again stream.BackUp(size); - EXPECT_EQ(slice1.size() + slice2.size(), stream.ByteCount()); + EXPECT_EQ(slice1.size() + slice2.size(), stream.BytesAvailable()); ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice1.size(), size); EXPECT_EQ(slice1, std::string(reinterpret_cast(data), size)); // Now Back up 10 bytes & test again stream.BackUp(10); - EXPECT_EQ(10 + slice2.size(), stream.ByteCount()); + EXPECT_EQ(10 + slice2.size(), stream.BytesAvailable()); ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(10, size); EXPECT_EQ(slice1.substr(slice1.size() - 10), @@ -204,14 +204,14 @@ TEST_F(GrpcZeroCopyInputStreamTest, Backups) { // Back up and test again stream.BackUp(size); - EXPECT_EQ(slice2.size(), stream.ByteCount()); + EXPECT_EQ(slice2.size(), stream.BytesAvailable()); ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice2.size(), size); EXPECT_EQ(slice2, std::string(reinterpret_cast(data), size)); // Now Back up size - 1 bytes (all but 1) and check again stream.BackUp(size - 1); - EXPECT_EQ(slice2.size() - 1, stream.ByteCount()); + EXPECT_EQ(slice2.size() - 1, stream.BytesAvailable()); ASSERT_TRUE(stream.Next(&data, &size)); ASSERT_EQ(slice2.size() - 1, size); EXPECT_EQ(slice2.substr(1), diff --git a/third_party/BUILD.golang_protobuf b/third_party/BUILD.golang_protobuf index e9b0c65f5..24f0b8930 100644 --- a/third_party/BUILD.golang_protobuf +++ b/third_party/BUILD.golang_protobuf @@ -15,6 +15,7 @@ go_library( "proto/lib.go", "proto/message_set.go", "proto/pointer_reflect.go", + "proto/pointer_unsafe.go", "proto/properties.go", "proto/text.go", "proto/text_parser.go",