Skip to content

Commit e03fe6a

Browse files
authored
protobuf-lite: should not have dependency on core_internal
1 parent c4577ec commit e03fe6a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

protobuf-lite/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ java_library(
77
visibility = ["//protobuf:__pkg__"],
88
deps = [
99
"//core",
10-
"//core:internal",
1110
"@com_google_code_findbugs_jsr305//jar",
1211
"@com_google_guava_guava//jar",
1312
"@com_google_protobuf_java//:protobuf_java",

protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

21+
import com.google.common.annotations.VisibleForTesting;
2122
import com.google.protobuf.CodedInputStream;
2223
import com.google.protobuf.ExtensionRegistryLite;
2324
import com.google.protobuf.InvalidProtocolBufferException;
@@ -29,7 +30,6 @@
2930
import io.grpc.MethodDescriptor.Marshaller;
3031
import io.grpc.MethodDescriptor.PrototypeMarshaller;
3132
import io.grpc.Status;
32-
import io.grpc.internal.GrpcUtil;
3333
import java.io.IOException;
3434
import java.io.InputStream;
3535
import java.io.OutputStream;
@@ -47,6 +47,12 @@ public class ProtoLiteUtils {
4747

4848
private static final int BUF_SIZE = 8192;
4949

50+
/**
51+
* The same value as {@link io.grpc.internal.GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE}.
52+
*/
53+
@VisibleForTesting
54+
static final int DEFAULT_MAX_MESSAGE_SIZE = 4 * 1024 * 1024;
55+
5056
/**
5157
* Sets the global registry for proto marshalling shared across all servers and clients.
5258
*
@@ -124,7 +130,7 @@ public T parse(InputStream stream) {
124130
try {
125131
if (stream instanceof KnownLength) {
126132
int size = stream.available();
127-
if (size > 0 && size <= GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE) {
133+
if (size > 0 && size <= DEFAULT_MAX_MESSAGE_SIZE) {
128134
// buf should not be used after this method has returned.
129135
byte[] buf = bufs.get().get();
130136
if (buf == null || buf.length < size) {

protobuf-lite/src/test/java/io/grpc/protobuf/lite/ProtoLiteUtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.grpc.MethodDescriptor.PrototypeMarshaller;
3636
import io.grpc.Status;
3737
import io.grpc.StatusRuntimeException;
38+
import io.grpc.internal.GrpcUtil;
3839
import java.io.ByteArrayInputStream;
3940
import java.io.ByteArrayOutputStream;
4041
import java.io.IOException;
@@ -225,6 +226,11 @@ public void parseFromKnowLengthInputStream() throws Exception {
225226
assertEquals(expect, result);
226227
}
227228

229+
@Test
230+
public void defaultMaxMessageSize() {
231+
assertEquals(GrpcUtil.DEFAULT_MAX_MESSAGE_SIZE, ProtoLiteUtils.DEFAULT_MAX_MESSAGE_SIZE);
232+
}
233+
228234
private static class CustomKnownLengthInputStream extends InputStream implements KnownLength {
229235
private int position = 0;
230236
private byte[] source;

0 commit comments

Comments
 (0)