diff options
Diffstat (limited to 'java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java')
-rw-r--r-- | java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java | 107 |
1 files changed, 90 insertions, 17 deletions
diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 4acd8f2f..53af544f 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -38,6 +38,11 @@ import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; +import com.google.protobuf.Internal.BooleanList; +import com.google.protobuf.Internal.DoubleList; +import com.google.protobuf.Internal.FloatList; +import com.google.protobuf.Internal.IntList; +import com.google.protobuf.Internal.LongList; // In opensource protobuf, we have versioned this GeneratedMessageV3 class to GeneratedMessageV3V3 and // in the future may have GeneratedMessageV3V4 etc. This allows us to change some aspects of this // class without breaking binary compatibility with old generated code that still subclasses @@ -293,16 +298,17 @@ public abstract class GeneratedMessageV3 extends AbstractMessage return unknownFields.mergeFieldFrom(tag, input); } + /** + * Delegates to parseUnknownField. This method is obsolete, but we must retain it for + * compatibility with older generated code. + */ protected boolean parseUnknownFieldProto3( CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag) throws IOException { - if (input.shouldDiscardUnknownFieldsProto3()) { - return input.skipField(tag); - } - return unknownFields.mergeFieldFrom(tag, input); + return parseUnknownField(input, unknownFields, extensionRegistry, tag); } protected static <M extends Message> M parseWithIOException(Parser<M> parser, InputStream input) @@ -363,6 +369,76 @@ public abstract class GeneratedMessageV3 extends AbstractMessage return UnsafeUtil.hasUnsafeArrayOperations() && UnsafeUtil.hasUnsafeByteBufferOperations(); } + protected static IntList emptyIntList() { + return IntArrayList.emptyList(); + } + + protected static IntList newIntList() { + return new IntArrayList(); + } + + protected static IntList mutableCopy(IntList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static LongList emptyLongList() { + return LongArrayList.emptyList(); + } + + protected static LongList newLongList() { + return new LongArrayList(); + } + + protected static LongList mutableCopy(LongList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static FloatList emptyFloatList() { + return FloatArrayList.emptyList(); + } + + protected static FloatList newFloatList() { + return new FloatArrayList(); + } + + protected static FloatList mutableCopy(FloatList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static DoubleList emptyDoubleList() { + return DoubleArrayList.emptyList(); + } + + protected static DoubleList newDoubleList() { + return new DoubleArrayList(); + } + + protected static DoubleList mutableCopy(DoubleList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + + protected static BooleanList emptyBooleanList() { + return BooleanArrayList.emptyList(); + } + + protected static BooleanList newBooleanList() { + return new BooleanArrayList(); + } + + protected static BooleanList mutableCopy(BooleanList list) { + int size = list.size(); + return list.mutableCopyWithCapacity( + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2); + } + @Override public void writeTo(final CodedOutputStream output) throws IOException { MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false); @@ -641,13 +717,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage return (BuilderType) this; } + /** + * Delegates to setUnknownFields. This method is obsolete, but we must retain it for + * compatibility with older generated code. + */ protected BuilderType setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { - if (CodedInputStream.getProto3DiscardUnknownFieldsDefault()) { - return (BuilderType) this; - } - this.unknownFields = unknownFields; - onChanged(); - return (BuilderType) this; + return setUnknownFields(unknownFields); } @Override @@ -1009,19 +1084,17 @@ public abstract class GeneratedMessageV3 extends AbstractMessage getDescriptorForType(), new MessageReflection.ExtensionAdapter(extensions), tag); } + /** + * Delegates to parseUnknownField. This method is obsolete, but we must retain it for + * compatibility with older generated code. + */ @Override protected boolean parseUnknownFieldProto3( CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, int tag) throws IOException { - return MessageReflection.mergeFieldFrom( - input, - input.shouldDiscardUnknownFieldsProto3() ? null : unknownFields, - extensionRegistry, - getDescriptorForType(), - new MessageReflection.ExtensionAdapter(extensions), - tag); + return parseUnknownField(input, unknownFields, extensionRegistry, tag); } |