From e03fe6a374b2a0103940ae6034235f3aefb03cf7 Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Thu, 4 Jan 2018 14:00:25 -0800 Subject: protobuf-lite: should not have dependency on core_internal --- protobuf-lite/BUILD.bazel | 1 - .../src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java | 10 ++++++++-- .../test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'protobuf-lite') diff --git a/protobuf-lite/BUILD.bazel b/protobuf-lite/BUILD.bazel index f14d44859..6dde2935d 100644 --- a/protobuf-lite/BUILD.bazel +++ b/protobuf-lite/BUILD.bazel @@ -7,7 +7,6 @@ java_library( visibility = ["//protobuf:__pkg__"], deps = [ "//core", - "//core:internal", "@com_google_code_findbugs_jsr305//jar", "@com_google_guava_guava//jar", "@com_google_protobuf_java//:protobuf_java", diff --git a/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java b/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java index fc578b2c2..b385b7fb2 100644 --- a/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java +++ b/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java @@ -18,6 +18,7 @@ package io.grpc.protobuf.lite; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.CodedInputStream; import com.google.protobuf.ExtensionRegistryLite; import com.google.protobuf.InvalidProtocolBufferException; @@ -29,7 +30,6 @@ import io.grpc.Metadata; import io.grpc.MethodDescriptor.Marshaller; import io.grpc.MethodDescriptor.PrototypeMarshaller; import io.grpc.Status; -import io.grpc.internal.GrpcUtil; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -47,6 +47,12 @@ public class ProtoLiteUtils { private static final int BUF_SIZE = 8192; + /** + * The same value as {@link io.grpc.internal.GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE}. + */ + @VisibleForTesting + static final int DEFAULT_MAX_MESSAGE_SIZE = 4 * 1024 * 1024; + /** * Sets the global registry for proto marshalling shared across all servers and clients. * @@ -124,7 +130,7 @@ public class ProtoLiteUtils { try { if (stream instanceof KnownLength) { int size = stream.available(); - if (size > 0 && size <= GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE) { + if (size > 0 && size <= DEFAULT_MAX_MESSAGE_SIZE) { // buf should not be used after this method has returned. byte[] buf = bufs.get().get(); if (buf == null || buf.length < size) { diff --git a/protobuf-lite/src/test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java b/protobuf-lite/src/test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java index 7134a507a..323454e0a 100644 --- a/protobuf-lite/src/test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java +++ b/protobuf-lite/src/test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java @@ -35,6 +35,7 @@ import io.grpc.MethodDescriptor.Marshaller; import io.grpc.MethodDescriptor.PrototypeMarshaller; import io.grpc.Status; import io.grpc.StatusRuntimeException; +import io.grpc.internal.GrpcUtil; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -225,6 +226,11 @@ public class ProtoLiteUtilsTest { assertEquals(expect, result); } + @Test + public void defaultMaxMessageSize() { + assertEquals(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE, ProtoLiteUtils.DEFAULT_MAX_MESSAGE_SIZE); + } + private static class CustomKnownLengthInputStream extends InputStream implements KnownLength { private int position = 0; private byte[] source; -- cgit v1.2.3