Skip to content

Commit b704498

Browse files
protobuf-github-botzhangskz
authored andcommitted
Internal change
PiperOrigin-RevId: 663919912
1 parent e673479 commit b704498

File tree

4 files changed

+29
-84
lines changed

4 files changed

+29
-84
lines changed

java/core/src/main/java/com/google/protobuf/CodedInputStream.java

Lines changed: 24 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,35 @@ public abstract boolean skipField(final int tag, final CodedOutputStream output)
223223
* Reads and discards an entire message. This will read either until EOF or until an endgroup tag,
224224
* whichever comes first.
225225
*/
226-
public abstract void skipMessage() throws IOException;
226+
public void skipMessage() throws IOException {
227+
while (true) {
228+
final int tag = readTag();
229+
if (tag == 0) {
230+
return;
231+
}
232+
boolean fieldSkipped = skipField(tag);
233+
if (!fieldSkipped) {
234+
return;
235+
}
236+
}
237+
}
227238

228239
/**
229240
* Reads an entire message and writes it to output in wire format. This will read either until EOF
230241
* or until an endgroup tag, whichever comes first.
231242
*/
232-
public abstract void skipMessage(CodedOutputStream output) throws IOException;
243+
public void skipMessage(CodedOutputStream output) throws IOException {
244+
while (true) {
245+
final int tag = readTag();
246+
if (tag == 0) {
247+
return;
248+
}
249+
boolean fieldSkipped = skipField(tag, output);
250+
if (!fieldSkipped) {
251+
return;
252+
}
253+
}
254+
}
233255

234256
// -----------------------------------------------------------------
235257

@@ -699,26 +721,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I
699721
}
700722
}
701723

702-
@Override
703-
public void skipMessage() throws IOException {
704-
while (true) {
705-
final int tag = readTag();
706-
if (tag == 0 || !skipField(tag)) {
707-
return;
708-
}
709-
}
710-
}
711-
712-
@Override
713-
public void skipMessage(CodedOutputStream output) throws IOException {
714-
while (true) {
715-
final int tag = readTag();
716-
if (tag == 0 || !skipField(tag, output)) {
717-
return;
718-
}
719-
}
720-
}
721-
722724
// -----------------------------------------------------------------
723725

724726
@Override
@@ -1411,26 +1413,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I
14111413
}
14121414
}
14131415

1414-
@Override
1415-
public void skipMessage() throws IOException {
1416-
while (true) {
1417-
final int tag = readTag();
1418-
if (tag == 0 || !skipField(tag)) {
1419-
return;
1420-
}
1421-
}
1422-
}
1423-
1424-
@Override
1425-
public void skipMessage(CodedOutputStream output) throws IOException {
1426-
while (true) {
1427-
final int tag = readTag();
1428-
if (tag == 0 || !skipField(tag, output)) {
1429-
return;
1430-
}
1431-
}
1432-
}
1433-
14341416
// -----------------------------------------------------------------
14351417

14361418
@Override
@@ -2176,26 +2158,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I
21762158
}
21772159
}
21782160

2179-
@Override
2180-
public void skipMessage() throws IOException {
2181-
while (true) {
2182-
final int tag = readTag();
2183-
if (tag == 0 || !skipField(tag)) {
2184-
return;
2185-
}
2186-
}
2187-
}
2188-
2189-
@Override
2190-
public void skipMessage(CodedOutputStream output) throws IOException {
2191-
while (true) {
2192-
final int tag = readTag();
2193-
if (tag == 0 || !skipField(tag, output)) {
2194-
return;
2195-
}
2196-
}
2197-
}
2198-
21992161
/** Collects the bytes skipped and returns the data in a ByteBuffer. */
22002162
private class SkippedDataSink implements RefillCallback {
22012163
private int lastPos = pos;
@@ -3307,26 +3269,6 @@ public boolean skipField(final int tag, final CodedOutputStream output) throws I
33073269
}
33083270
}
33093271

3310-
@Override
3311-
public void skipMessage() throws IOException {
3312-
while (true) {
3313-
final int tag = readTag();
3314-
if (tag == 0 || !skipField(tag)) {
3315-
return;
3316-
}
3317-
}
3318-
}
3319-
3320-
@Override
3321-
public void skipMessage(CodedOutputStream output) throws IOException {
3322-
while (true) {
3323-
final int tag = readTag();
3324-
if (tag == 0 || !skipField(tag, output)) {
3325-
return;
3326-
}
3327-
}
3328-
}
3329-
33303272
// -----------------------------------------------------------------
33313273

33323274
@Override

java/core/src/test/proto/com/google/protobuf/map_lite_test.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ message ReservedAsMapFieldWithEnumValue {
9999

100100
// https://github.com/protocolbuffers/protobuf/issues/9785
101101
message MapContainer {
102-
map<string,string> my_map = 1;
102+
map<string, string> my_map = 1;
103+
map<uint32, string> m = 3;
103104
}

java/core/src/test/proto/com/google/protobuf/map_test.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@ message ReservedAsMapFieldWithEnumValue {
9898

9999
// https://github.com/protocolbuffers/protobuf/issues/9785
100100
message MapContainer {
101-
map<string,string> my_map = 1;
101+
map<string, string> my_map = 1;
102+
map<uint32, string> m = 3;
102103
}

java/lite/src/test/java/com/google/protobuf/LiteTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.protobuf.UnittestLite.TestHugeFieldNumbersLite;
3030
import com.google.protobuf.UnittestLite.TestNestedExtensionLite;
3131
import com.google.protobuf.testing.Proto3TestingLite.Proto3MessageLite;
32+
import map_lite_test.MapTestProto.MapContainer;
3233
import map_lite_test.MapTestProto.TestMap;
3334
import map_lite_test.MapTestProto.TestMap.MessageValue;
3435
import protobuf_unittest.NestedExtensionLite;

0 commit comments

Comments
 (0)