From b7044987de77f1dc368fee558636d0b56d7e75e1 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 16 Aug 2024 16:57:47 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 663919912 --- .../com/google/protobuf/CodedInputStream.java | 106 ++++-------------- .../com/google/protobuf/map_lite_test.proto | 3 +- .../proto/com/google/protobuf/map_test.proto | 3 +- .../java/com/google/protobuf/LiteTest.java | 1 + 4 files changed, 29 insertions(+), 84 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index 80e0e2c2c25f8..ff773e248d02e 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -223,13 +223,35 @@ public abstract boolean skipField(final int tag, final CodedOutputStream output) * Reads and discards an entire message. This will read either until EOF or until an endgroup tag, * whichever comes first. */ - public abstract void skipMessage() throws IOException; + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0) { + return; + } + boolean fieldSkipped = skipField(tag); + if (!fieldSkipped) { + return; + } + } + } /** * Reads an entire message and writes it to output in wire format. This will read either until EOF * or until an endgroup tag, whichever comes first. */ - public abstract void skipMessage(CodedOutputStream output) throws IOException; + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0) { + return; + } + boolean fieldSkipped = skipField(tag, output); + if (!fieldSkipped) { + return; + } + } + } // ----------------------------------------------------------------- @@ -699,26 +721,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I } } - @Override - public void skipMessage() throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag)) { - return; - } - } - } - - @Override - public void skipMessage(CodedOutputStream output) throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag, output)) { - return; - } - } - } - // ----------------------------------------------------------------- @Override @@ -1411,26 +1413,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I } } - @Override - public void skipMessage() throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag)) { - return; - } - } - } - - @Override - public void skipMessage(CodedOutputStream output) throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag, output)) { - return; - } - } - } - // ----------------------------------------------------------------- @Override @@ -2176,26 +2158,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I } } - @Override - public void skipMessage() throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag)) { - return; - } - } - } - - @Override - public void skipMessage(CodedOutputStream output) throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag, output)) { - return; - } - } - } - /** Collects the bytes skipped and returns the data in a ByteBuffer. */ private class SkippedDataSink implements RefillCallback { private int lastPos = pos; @@ -3307,26 +3269,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I } } - @Override - public void skipMessage() throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag)) { - return; - } - } - } - - @Override - public void skipMessage(CodedOutputStream output) throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag, output)) { - return; - } - } - } - // ----------------------------------------------------------------- @Override diff --git a/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto b/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto index 8496257654b01..636a5466fa6d9 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_lite_test.proto @@ -99,5 +99,6 @@ message ReservedAsMapFieldWithEnumValue { // https://github.com/protocolbuffers/protobuf/issues/9785 message MapContainer { - map my_map = 1; + map my_map = 1; + map m = 3; } diff --git a/java/core/src/test/proto/com/google/protobuf/map_test.proto b/java/core/src/test/proto/com/google/protobuf/map_test.proto index f9d069bb744fa..7b250a6ef6564 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_test.proto @@ -98,5 +98,6 @@ message ReservedAsMapFieldWithEnumValue { // https://github.com/protocolbuffers/protobuf/issues/9785 message MapContainer { - map my_map = 1; + map my_map = 1; + map m = 3; } diff --git a/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/java/lite/src/test/java/com/google/protobuf/LiteTest.java index 754ed7d5fc7c5..00b22ce5ebd0b 100644 --- a/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -29,6 +29,7 @@ import com.google.protobuf.UnittestLite.TestHugeFieldNumbersLite; import com.google.protobuf.UnittestLite.TestNestedExtensionLite; import com.google.protobuf.testing.Proto3TestingLite.Proto3MessageLite; +import map_lite_test.MapTestProto.MapContainer; import map_lite_test.MapTestProto.TestMap; import map_lite_test.MapTestProto.TestMap.MessageValue; import protobuf_unittest.NestedExtensionLite;