| Index: third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
| diff --git a/third_party/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
| similarity index 52%
|
| rename from third_party/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
| rename to third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
| index 81e1862c69ae60555dca22dbba59a01cb520dcd6..c5adc5ad02050f93e9e94db97ecc7b9e70f1a37b 100644
|
| --- a/third_party/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
| +++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
| @@ -30,6 +30,8 @@
|
|
|
| package com.google.protobuf;
|
|
|
| +import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream;
|
| +import com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException;
|
| import com.google.protobuf.Internal.BooleanList;
|
| import com.google.protobuf.Internal.DoubleList;
|
| import com.google.protobuf.Internal.FloatList;
|
| @@ -39,6 +41,7 @@ import com.google.protobuf.Internal.ProtobufList;
|
| import com.google.protobuf.WireFormat.FieldType;
|
|
|
| import java.io.IOException;
|
| +import java.io.InputStream;
|
| import java.io.ObjectStreamException;
|
| import java.io.Serializable;
|
| import java.lang.reflect.InvocationTargetException;
|
| @@ -57,32 +60,108 @@ import java.util.Map;
|
| public abstract class GeneratedMessageLite<
|
| MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
|
| BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>>
|
| - extends AbstractMessageLite
|
| - implements Serializable {
|
| -
|
| - private static final long serialVersionUID = 1L;
|
| + extends AbstractMessageLite<MessageType, BuilderType> {
|
|
|
| /** For use by generated code only. Lazily initialized to reduce allocations. */
|
| - protected UnknownFieldSetLite unknownFields = null;
|
| + protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultInstance();
|
|
|
| /** For use by generated code only. */
|
| protected int memoizedSerializedSize = -1;
|
|
|
| + @Override
|
| @SuppressWarnings("unchecked") // Guaranteed by runtime.
|
| public final Parser<MessageType> getParserForType() {
|
| return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER);
|
| }
|
|
|
| + @Override
|
| @SuppressWarnings("unchecked") // Guaranteed by runtime.
|
| public final MessageType getDefaultInstanceForType() {
|
| return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE);
|
| }
|
|
|
| + @Override
|
| @SuppressWarnings("unchecked") // Guaranteed by runtime.
|
| public final BuilderType newBuilderForType() {
|
| return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
|
| }
|
|
|
| + /**
|
| + * A reflective toString function. This is primarily intended as a developer aid, while keeping
|
| + * binary size down. The first line of the {@code toString()} representation includes a commented
|
| + * version of {@code super.toString()} to act as an indicator that this should not be relied on
|
| + * for comparisons.
|
| + * <p>
|
| + * NOTE: This method relies on the field getter methods not being stripped or renamed by proguard.
|
| + * If they are, the fields will not be included in the returned string representation.
|
| + * <p>
|
| + * NOTE: This implementation is liable to change in the future, and should not be relied on in
|
| + * code.
|
| + */
|
| + @Override
|
| + public String toString() {
|
| + return MessageLiteToString.toString(this, super.toString());
|
| + }
|
| +
|
| + @SuppressWarnings("unchecked") // Guaranteed by runtime
|
| + @Override
|
| + public int hashCode() {
|
| + if (memoizedHashCode == 0) {
|
| + HashCodeVisitor visitor = new HashCodeVisitor();
|
| + visit(visitor, (MessageType) this);
|
| + memoizedHashCode = visitor.hashCode;
|
| + }
|
| + return memoizedHashCode;
|
| + }
|
| +
|
| + @SuppressWarnings("unchecked") // Guaranteed by runtime
|
| + int hashCode(HashCodeVisitor visitor) {
|
| + if (memoizedHashCode == 0) {
|
| + int inProgressHashCode = visitor.hashCode;
|
| + visitor.hashCode = 0;
|
| + visit(visitor, (MessageType) this);
|
| + memoizedHashCode = visitor.hashCode;
|
| + visitor.hashCode = inProgressHashCode;
|
| + }
|
| + return memoizedHashCode;
|
| + }
|
| +
|
| + @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
|
| + @Override
|
| + public boolean equals(Object other) {
|
| + if (this == other) {
|
| + return true;
|
| + }
|
| +
|
| + if (!getDefaultInstanceForType().getClass().isInstance(other)) {
|
| + return false;
|
| + }
|
| +
|
| + try {
|
| + visit(EqualsVisitor.INSTANCE, (MessageType) other);
|
| + } catch (NotEqualsException e) {
|
| + return false;
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| + * Same as {@link #equals(Object)} but throws {@code NotEqualsException}.
|
| + */
|
| + @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
|
| + boolean equals(EqualsVisitor visitor, MessageLite other) {
|
| + if (this == other) {
|
| + return true;
|
| + }
|
| +
|
| + if (!getDefaultInstanceForType().getClass().isInstance(other)) {
|
| + return false;
|
| + }
|
| +
|
| + visit(visitor, (MessageType) other);
|
| + return true;
|
| + }
|
| +
|
| // The general strategy for unknown fields is to use an UnknownFieldSetLite that is treated as
|
| // mutable during the parsing constructor and immutable after. This allows us to avoid
|
| // any unnecessary intermediary allocations while reducing the generated code size.
|
| @@ -91,7 +170,7 @@ public abstract class GeneratedMessageLite<
|
| * Lazily initializes unknown fields.
|
| */
|
| private final void ensureUnknownFieldsInitialized() {
|
| - if (unknownFields == null) {
|
| + if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) {
|
| unknownFields = UnknownFieldSetLite.newInstance();
|
| }
|
| }
|
| @@ -130,18 +209,18 @@ public abstract class GeneratedMessageLite<
|
| /**
|
| * Called by subclasses to complete parsing. For use by generated code only.
|
| */
|
| - protected void doneParsing() {
|
| - if (unknownFields == null) {
|
| - unknownFields = UnknownFieldSetLite.getDefaultInstance();
|
| - } else {
|
| - unknownFields.makeImmutable();
|
| - }
|
| + protected void makeImmutable() {
|
| + dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
|
| +
|
| + unknownFields.makeImmutable();
|
| }
|
|
|
| + @Override
|
| public final boolean isInitialized() {
|
| return dynamicMethod(MethodToInvoke.IS_INITIALIZED, Boolean.TRUE) != null;
|
| }
|
|
|
| + @Override
|
| public final BuilderType toBuilder() {
|
| BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
|
| builder.mergeFrom((MessageType) this);
|
| @@ -155,11 +234,14 @@ public abstract class GeneratedMessageLite<
|
| * For use by generated code only.
|
| */
|
| public static enum MethodToInvoke {
|
| + // Rely on/modify instance state
|
| IS_INITIALIZED,
|
| - PARSE_PARTIAL_FROM,
|
| - MERGE_FROM,
|
| + VISIT,
|
| + MERGE_FROM_STREAM,
|
| MAKE_IMMUTABLE,
|
| - NEW_INSTANCE,
|
| +
|
| + // Rely on static state
|
| + NEW_MUTABLE_INSTANCE,
|
| NEW_BUILDER,
|
| GET_DEFAULT_INSTANCE,
|
| GET_PARSER;
|
| @@ -171,17 +253,18 @@ public abstract class GeneratedMessageLite<
|
| * builders in the runtime. This method bundles those operations to reduce the generated methods
|
| * count.
|
| * <ul>
|
| - * <li>{@code PARSE_PARTIAL_FROM} is parameterized with an {@link CodedInputStream} and
|
| + * <li>{@code MERGE_FROM_STREAM} is parameterized with an {@link CodedInputStream} and
|
| * {@link ExtensionRegistryLite}. It consumes the input stream, parsing the contents into the
|
| * returned protocol buffer. If parsing throws an {@link InvalidProtocolBufferException}, the
|
| - * implementation wraps it in a RuntimeException
|
| - * <li>{@code NEW_INSTANCE} returns a new instance of the protocol buffer
|
| + * implementation wraps it in a RuntimeException.
|
| + * <li>{@code NEW_INSTANCE} returns a new instance of the protocol buffer that has not yet been
|
| + * made immutable. See {@code MAKE_IMMUTABLE}.
|
| * <li>{@code IS_INITIALIZED} is parameterized with a {@code Boolean} detailing whether to
|
| * memoize. It returns {@code null} for false and the default instance for true. We optionally
|
| * memoize to support the Builder case, where memoization is not desired.
|
| * <li>{@code NEW_BUILDER} returns a {@code BuilderType} instance.
|
| - * <li>{@code MERGE_FROM} is parameterized with a {@code MessageType} and merges the fields from
|
| - * that instance into this instance.
|
| + * <li>{@code VISIT} is parameterized with a {@code Visitor} and a {@code MessageType} and
|
| + * recursively iterates through the fields side by side between this and the instance.
|
| * <li>{@code MAKE_IMMUTABLE} sets all internal fields to an immutable state.
|
| * </ul>
|
| * This method, plus the implementation of the Builder, enables the Builder class to be proguarded
|
| @@ -205,6 +288,11 @@ public abstract class GeneratedMessageLite<
|
| return dynamicMethod(method, null, null);
|
| }
|
|
|
| + void visit(Visitor visitor, MessageType other) {
|
| + dynamicMethod(MethodToInvoke.VISIT, visitor, other);
|
| + unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownFields);
|
| + }
|
| +
|
| /**
|
| * Merge some unknown fields into the {@link UnknownFieldSetLite} for this
|
| * message.
|
| @@ -219,7 +307,7 @@ public abstract class GeneratedMessageLite<
|
| public abstract static class Builder<
|
| MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
|
| BuilderType extends Builder<MessageType, BuilderType>>
|
| - extends AbstractMessageLite.Builder<BuilderType> {
|
| + extends AbstractMessageLite.Builder<MessageType, BuilderType> {
|
|
|
| private final MessageType defaultInstance;
|
| protected MessageType instance;
|
| @@ -227,7 +315,8 @@ public abstract class GeneratedMessageLite<
|
|
|
| protected Builder(MessageType defaultInstance) {
|
| this.defaultInstance = defaultInstance;
|
| - this.instance = (MessageType) defaultInstance.dynamicMethod(MethodToInvoke.NEW_INSTANCE);
|
| + this.instance =
|
| + (MessageType) defaultInstance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
|
| isBuilt = false;
|
| }
|
|
|
| @@ -237,26 +326,27 @@ public abstract class GeneratedMessageLite<
|
| */
|
| protected void copyOnWrite() {
|
| if (isBuilt) {
|
| - MessageType newInstance = (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_INSTANCE);
|
| - newInstance.dynamicMethod(MethodToInvoke.MERGE_FROM, instance);
|
| + MessageType newInstance =
|
| + (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
|
| + newInstance.visit(MergeFromVisitor.INSTANCE, instance);
|
| instance = newInstance;
|
| isBuilt = false;
|
| }
|
| }
|
|
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public final boolean isInitialized() {
|
| return GeneratedMessageLite.isInitialized(instance, false /* shouldMemoize */);
|
| }
|
|
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public final BuilderType clear() {
|
| // No need to copy on write since we're dropping the instance anyways.
|
| - instance = (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_INSTANCE);
|
| + instance = (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
|
| return (BuilderType) this;
|
| }
|
|
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public BuilderType clone() {
|
| BuilderType builder =
|
| (BuilderType) getDefaultInstanceForType().newBuilderForType();
|
| @@ -264,20 +354,19 @@ public abstract class GeneratedMessageLite<
|
| return builder;
|
| }
|
|
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public MessageType buildPartial() {
|
| if (isBuilt) {
|
| return instance;
|
| }
|
|
|
| - instance.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
|
| - instance.unknownFields.makeImmutable();
|
| + instance.makeImmutable();
|
|
|
| isBuilt = true;
|
| return instance;
|
| }
|
|
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public final MessageType build() {
|
| MessageType result = buildPartial();
|
| if (!result.isInitialized()) {
|
| @@ -286,33 +375,36 @@ public abstract class GeneratedMessageLite<
|
| return result;
|
| }
|
|
|
| + @Override
|
| + protected BuilderType internalMergeFrom(MessageType message) {
|
| + return mergeFrom(message);
|
| + }
|
| +
|
| /** All subclasses implement this. */
|
| public BuilderType mergeFrom(MessageType message) {
|
| copyOnWrite();
|
| - instance.dynamicMethod(MethodToInvoke.MERGE_FROM, message);
|
| + instance.visit(MergeFromVisitor.INSTANCE, message);
|
| return (BuilderType) this;
|
| }
|
|
|
| + @Override
|
| public MessageType getDefaultInstanceForType() {
|
| return defaultInstance;
|
| }
|
|
|
| + @Override
|
| public BuilderType mergeFrom(
|
| com.google.protobuf.CodedInputStream input,
|
| com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
| - throws java.io.IOException {
|
| - MessageType parsedMessage = null;
|
| + throws IOException {
|
| + copyOnWrite();
|
| try {
|
| - parsedMessage =
|
| - (MessageType) getDefaultInstanceForType().getParserForType().parsePartialFrom(
|
| - input, extensionRegistry);
|
| - } catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
| - parsedMessage = (MessageType) e.getUnfinishedMessage();
|
| - throw e;
|
| - } finally {
|
| - if (parsedMessage != null) {
|
| - mergeFrom(parsedMessage);
|
| + instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionRegistry);
|
| + } catch (RuntimeException e) {
|
| + if (e.getCause() instanceof IOException) {
|
| + throw (IOException) e.getCause();
|
| }
|
| + throw e;
|
| }
|
| return (BuilderType) this;
|
| }
|
| @@ -368,6 +460,12 @@ public abstract class GeneratedMessageLite<
|
| }
|
| extensions.mergeFrom(((ExtendableMessage) other).extensions);
|
| }
|
| +
|
| + @Override
|
| + final void visit(Visitor visitor, MessageType other) {
|
| + super.visit(visitor, other);
|
| + extensions = visitor.visitExtensions(extensions, other.extensions);
|
| + }
|
|
|
| /**
|
| * Parse an unknown field or an extension. For use by generated code only.
|
| @@ -505,9 +603,8 @@ public abstract class GeneratedMessageLite<
|
| }
|
|
|
| /** Check if a singular extension is present. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| - public final <Type> boolean hasExtension(
|
| - final ExtensionLite<MessageType, Type> extension) {
|
| + @Override
|
| + public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extension) {
|
| GeneratedExtension<MessageType, Type> extensionLite =
|
| checkIsLite(extension);
|
|
|
| @@ -516,7 +613,7 @@ public abstract class GeneratedMessageLite<
|
| }
|
|
|
| /** Get the number of elements in a repeated extension. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public final <Type> int getExtensionCount(
|
| final ExtensionLite<MessageType, List<Type>> extension) {
|
| GeneratedExtension<MessageType, List<Type>> extensionLite =
|
| @@ -527,10 +624,9 @@ public abstract class GeneratedMessageLite<
|
| }
|
|
|
| /** Get the value of an extension. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| @SuppressWarnings("unchecked")
|
| - public final <Type> Type getExtension(
|
| - final ExtensionLite<MessageType, Type> extension) {
|
| + public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extension) {
|
| GeneratedExtension<MessageType, Type> extensionLite =
|
| checkIsLite(extension);
|
|
|
| @@ -544,11 +640,10 @@ public abstract class GeneratedMessageLite<
|
| }
|
|
|
| /** Get one element of a repeated extension. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| @SuppressWarnings("unchecked")
|
| public final <Type> Type getExtension(
|
| - final ExtensionLite<MessageType, List<Type>> extension,
|
| - final int index) {
|
| + final ExtensionLite<MessageType, List<Type>> extension, final int index) {
|
| GeneratedExtension<MessageType, List<Type>> extensionLite =
|
| checkIsLite(extension);
|
|
|
| @@ -562,10 +657,9 @@ public abstract class GeneratedMessageLite<
|
| return extensions.isInitialized();
|
| }
|
|
|
| -
|
| @Override
|
| - protected final void doneParsing() {
|
| - super.doneParsing();
|
| + protected final void makeImmutable() {
|
| + super.makeImmutable();
|
|
|
| extensions.makeImmutable();
|
| }
|
| @@ -654,7 +748,7 @@ public abstract class GeneratedMessageLite<
|
| instance.extensions = extensions;
|
| }
|
|
|
| - // @Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| protected void copyOnWrite() {
|
| if (!isBuilt) {
|
| return;
|
| @@ -664,7 +758,7 @@ public abstract class GeneratedMessageLite<
|
| instance.extensions = instance.extensions.clone();
|
| }
|
|
|
| - // @Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public final MessageType buildPartial() {
|
| if (isBuilt) {
|
| return instance;
|
| @@ -686,33 +780,30 @@ public abstract class GeneratedMessageLite<
|
| }
|
|
|
| /** Check if a singular extension is present. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| - public final <Type> boolean hasExtension(
|
| - final ExtensionLite<MessageType, Type> extension) {
|
| + @Override
|
| + public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extension) {
|
| return instance.hasExtension(extension);
|
| }
|
|
|
| /** Get the number of elements in a repeated extension. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| public final <Type> int getExtensionCount(
|
| final ExtensionLite<MessageType, List<Type>> extension) {
|
| return instance.getExtensionCount(extension);
|
| }
|
|
|
| /** Get the value of an extension. */
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| + @Override
|
| @SuppressWarnings("unchecked")
|
| - public final <Type> Type getExtension(
|
| - final ExtensionLite<MessageType, Type> extension) {
|
| + public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extension) {
|
| return instance.getExtension(extension);
|
| }
|
|
|
| /** Get one element of a repeated extension. */
|
| + @Override
|
| @SuppressWarnings("unchecked")
|
| - //@Override (Java 1.6 override semantics, but we must support 1.5)
|
| public final <Type> Type getExtension(
|
| - final ExtensionLite<MessageType, List<Type>> extension,
|
| - final int index) {
|
| + final ExtensionLite<MessageType, List<Type>> extension, final int index) {
|
| return instance.getExtension(extension, index);
|
| }
|
|
|
| @@ -844,37 +935,44 @@ public abstract class GeneratedMessageLite<
|
| final boolean isRepeated;
|
| final boolean isPacked;
|
|
|
| + @Override
|
| public int getNumber() {
|
| return number;
|
| }
|
|
|
| + @Override
|
| public WireFormat.FieldType getLiteType() {
|
| return type;
|
| }
|
|
|
| + @Override
|
| public WireFormat.JavaType getLiteJavaType() {
|
| return type.getJavaType();
|
| }
|
|
|
| + @Override
|
| public boolean isRepeated() {
|
| return isRepeated;
|
| }
|
|
|
| + @Override
|
| public boolean isPacked() {
|
| return isPacked;
|
| }
|
|
|
| + @Override
|
| public Internal.EnumLiteMap<?> getEnumType() {
|
| return enumTypeMap;
|
| }
|
|
|
| + @Override
|
| @SuppressWarnings("unchecked")
|
| - public MessageLite.Builder internalMergeFrom(
|
| - MessageLite.Builder to, MessageLite from) {
|
| + public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from) {
|
| return ((Builder) to).mergeFrom((GeneratedMessageLite) from);
|
| }
|
|
|
|
|
| + @Override
|
| public int compareTo(ExtensionDescriptor other) {
|
| return number - other.number;
|
| }
|
| @@ -969,6 +1067,7 @@ public abstract class GeneratedMessageLite<
|
| }
|
|
|
| /** Get the field number. */
|
| + @Override
|
| public int getNumber() {
|
| return descriptor.getNumber();
|
| }
|
| @@ -978,6 +1077,7 @@ public abstract class GeneratedMessageLite<
|
| * If the extension is an embedded message or group, returns the default
|
| * instance of the message.
|
| */
|
| + @Override
|
| public MessageLite getMessageDefaultInstance() {
|
| return messageDefaultInstance;
|
| }
|
| @@ -1032,14 +1132,17 @@ public abstract class GeneratedMessageLite<
|
| }
|
| }
|
|
|
| + @Override
|
| public FieldType getLiteType() {
|
| return descriptor.getLiteType();
|
| }
|
|
|
| + @Override
|
| public boolean isRepeated() {
|
| return descriptor.isRepeated;
|
| }
|
|
|
| + @Override
|
| public Type getDefaultValue() {
|
| return defaultValue;
|
| }
|
| @@ -1049,7 +1152,12 @@ public abstract class GeneratedMessageLite<
|
| * A serialized (serializable) form of the generated message. Stores the
|
| * message as a class name and a byte array.
|
| */
|
| - static final class SerializedForm implements Serializable {
|
| + protected static final class SerializedForm implements Serializable {
|
| +
|
| + public static SerializedForm of(MessageLite message) {
|
| + return new SerializedForm(message);
|
| + }
|
| +
|
| private static final long serialVersionUID = 0L;
|
|
|
| private final String messageClassName;
|
| @@ -1093,16 +1201,6 @@ public abstract class GeneratedMessageLite<
|
| }
|
| }
|
| }
|
| -
|
| - /**
|
| - * Replaces this object in the output stream with a serialized form.
|
| - * Part of Java's serialization magic. Generated sub-classes must override
|
| - * this method by calling {@code return super.writeReplace();}
|
| - * @return a SerializedForm of this message
|
| - */
|
| - protected Object writeReplace() throws ObjectStreamException {
|
| - return new SerializedForm(this);
|
| - }
|
|
|
| /**
|
| * Checks that the {@link Extension} is Lite and returns it as a
|
| @@ -1129,30 +1227,72 @@ public abstract class GeneratedMessageLite<
|
| protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitialized(
|
| T message, boolean shouldMemoize) {
|
| return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) != null;
|
| - }
|
| + }
|
|
|
| protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutable(T message) {
|
| message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
|
| }
|
| +
|
| + protected static IntList emptyIntList() {
|
| + return IntArrayList.emptyList();
|
| + }
|
| +
|
| + 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();
|
| + }
|
|
|
| - /**
|
| - * A static helper method for parsing a partial from input using the extension registry and the
|
| - * instance.
|
| - */
|
| - static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
|
| - T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
|
| - throws InvalidProtocolBufferException {
|
| - try {
|
| - return (T) instance.dynamicMethod(
|
| - MethodToInvoke.PARSE_PARTIAL_FROM, input, extensionRegistry);
|
| - } catch (RuntimeException e) {
|
| - if (e.getCause() instanceof InvalidProtocolBufferException) {
|
| - throw (InvalidProtocolBufferException) e.getCause();
|
| - }
|
| - throw e;
|
| - }
|
| + 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 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 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 mutableCopy(BooleanList list) {
|
| + int size = list.size();
|
| + return list.mutableCopyWithCapacity(
|
| + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
|
| + }
|
| +
|
| + protected static <E> ProtobufList<E> emptyProtobufList() {
|
| + return ProtobufArrayList.emptyList();
|
| }
|
|
|
| + protected static <E> ProtobufList<E> mutableCopy(ProtobufList<E> list) {
|
| + int size = list.size();
|
| + return list.mutableCopyWithCapacity(
|
| + size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
|
| + }
|
| +
|
| /**
|
| * A {@link Parser} implementation that delegates to the default instance.
|
| * <p>
|
| @@ -1174,103 +1314,929 @@ public abstract class GeneratedMessageLite<
|
| }
|
| }
|
|
|
| - protected static IntList newIntList() {
|
| - return new IntArrayList();
|
| - }
|
| -
|
| - protected static IntList newIntListWithCapacity(int capacity) {
|
| - return new IntArrayList(capacity);
|
| + /**
|
| + * A static helper method for parsing a partial from input using the extension registry and the
|
| + * instance.
|
| + */
|
| + // TODO(dweis): Should this verify that the last tag was 0?
|
| + static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
|
| + T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + @SuppressWarnings("unchecked") // Guaranteed by protoc
|
| + T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
|
| + try {
|
| + result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionRegistry);
|
| + result.makeImmutable();
|
| + } catch (RuntimeException e) {
|
| + if (e.getCause() instanceof InvalidProtocolBufferException) {
|
| + throw (InvalidProtocolBufferException) e.getCause();
|
| + }
|
| + throw e;
|
| + }
|
| + return result;
|
| }
|
|
|
| - protected static IntList newIntList(List<Integer> toCopy) {
|
| - return new IntArrayList(toCopy);
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
|
| + T defaultInstance,
|
| + CodedInputStream input)
|
| + throws InvalidProtocolBufferException {
|
| + return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry());
|
| }
|
|
|
| - protected static IntList emptyIntList() {
|
| - return IntArrayList.emptyList();
|
| + /**
|
| + * Helper method to check if message is initialized.
|
| + *
|
| + * @throws InvalidProtocolBufferException if it is not initialized.
|
| + * @return The message to check.
|
| + */
|
| + private static <T extends GeneratedMessageLite<T, ?>> T checkMessageInitialized(T message)
|
| + throws InvalidProtocolBufferException {
|
| + if (message != null && !message.isInitialized()) {
|
| + throw message.newUninitializedMessageException()
|
| + .asInvalidProtocolBufferException()
|
| + .setUnfinishedMessage(message);
|
| + }
|
| + return message;
|
| }
|
|
|
| - protected static LongList newLongList() {
|
| - return new LongArrayList();
|
| + // Validates last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, ByteString data)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()));
|
| }
|
|
|
| - protected static LongList newLongListWithCapacity(int capacity) {
|
| - return new LongArrayList(capacity);
|
| - }
|
| -
|
| - protected static LongList newLongList(List<Long> toCopy) {
|
| - return new LongArrayList(toCopy);
|
| - }
|
| -
|
| - protected static LongList emptyLongList() {
|
| - return LongArrayList.emptyList();
|
| - }
|
| -
|
| - protected static FloatList newFloatList() {
|
| - return new FloatArrayList();
|
| - }
|
| -
|
| - protected static FloatList newFloatListWithCapacity(int capacity) {
|
| - return new FloatArrayList(capacity);
|
| - }
|
| -
|
| - protected static FloatList newFloatList(List<Float> toCopy) {
|
| - return new FloatArrayList(toCopy);
|
| - }
|
| -
|
| - protected static FloatList emptyFloatList() {
|
| - return FloatArrayList.emptyList();
|
| + // Validates last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(parsePartialFrom(defaultInstance, data, extensionRegistry));
|
| }
|
|
|
| - protected static DoubleList newDoubleList() {
|
| - return new DoubleArrayList();
|
| + // This is a special case since we want to verify that the last tag is 0. We assume we exhaust the
|
| + // ByteString.
|
| + private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
|
| + T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + T message;
|
| + try {
|
| + CodedInputStream input = data.newCodedInput();
|
| + message = parsePartialFrom(defaultInstance, input, extensionRegistry);
|
| + try {
|
| + input.checkLastTagWas(0);
|
| + } catch (InvalidProtocolBufferException e) {
|
| + throw e.setUnfinishedMessage(message);
|
| + }
|
| + return message;
|
| + } catch (InvalidProtocolBufferException e) {
|
| + throw e;
|
| + }
|
| }
|
|
|
| - protected static DoubleList newDoubleListWithCapacity(int capacity) {
|
| - return new DoubleArrayList(capacity);
|
| + // This is a special case since we want to verify that the last tag is 0. We assume we exhaust the
|
| + // ByteString.
|
| + private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
|
| + T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + T message;
|
| + try {
|
| + CodedInputStream input = CodedInputStream.newInstance(data);
|
| + message = parsePartialFrom(defaultInstance, input, extensionRegistry);
|
| + try {
|
| + input.checkLastTagWas(0);
|
| + } catch (InvalidProtocolBufferException e) {
|
| + throw e.setUnfinishedMessage(message);
|
| + }
|
| + return message;
|
| + } catch (InvalidProtocolBufferException e) {
|
| + throw e;
|
| + }
|
| }
|
| -
|
| - protected static DoubleList newDoubleList(List<Double> toCopy) {
|
| - return new DoubleArrayList(toCopy);
|
| +
|
| + // Validates last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, byte[] data)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parsePartialFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()));
|
| }
|
| -
|
| - protected static DoubleList emptyDoubleList() {
|
| - return DoubleArrayList.emptyList();
|
| +
|
| + // Validates last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(parsePartialFrom(defaultInstance, data, extensionRegistry));
|
| }
|
| -
|
| - protected static BooleanList newBooleanList() {
|
| - return new BooleanArrayList();
|
| +
|
| + // Does not validate last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, InputStream input)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parsePartialFrom(defaultInstance, CodedInputStream.newInstance(input),
|
| + ExtensionRegistryLite.getEmptyRegistry()));
|
| }
|
| -
|
| - protected static BooleanList newBooleanListWithCapacity(int capacity) {
|
| - return new BooleanArrayList(capacity);
|
| +
|
| + // Does not validate last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parsePartialFrom(defaultInstance, CodedInputStream.newInstance(input), extensionRegistry));
|
| }
|
| -
|
| - protected static BooleanList newBooleanList(List<Boolean> toCopy) {
|
| - return new BooleanArrayList(toCopy);
|
| +
|
| + // Does not validate last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, CodedInputStream input)
|
| + throws InvalidProtocolBufferException {
|
| + return parseFrom(defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry());
|
| }
|
| -
|
| - protected static BooleanList emptyBooleanList() {
|
| - return BooleanArrayList.emptyList();
|
| +
|
| + // Does not validate last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
|
| + T defaultInstance, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parsePartialFrom(defaultInstance, input, extensionRegistry));
|
| }
|
| -
|
| - protected static <E> ProtobufList<E> newProtobufList() {
|
| - return new ProtobufArrayList<E>();
|
| +
|
| + // Validates last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom(
|
| + T defaultInstance, InputStream input)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parsePartialDelimitedFrom(defaultInstance, input,
|
| + ExtensionRegistryLite.getEmptyRegistry()));
|
| }
|
| -
|
| - protected static <E> ProtobufList<E> newProtobufList(List<E> toCopy) {
|
| - return new ProtobufArrayList<E>(toCopy);
|
| +
|
| + // Validates last tag.
|
| + protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom(
|
| + T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + return checkMessageInitialized(
|
| + parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry));
|
| }
|
|
|
| - protected static <E> ProtobufList<E> newProtobufListWithCapacity(int capacity) {
|
| - return new ProtobufArrayList<E>(capacity);
|
| + private static <T extends GeneratedMessageLite<T, ?>> T parsePartialDelimitedFrom(
|
| + T defaultInstance,
|
| + InputStream input,
|
| + ExtensionRegistryLite extensionRegistry)
|
| + throws InvalidProtocolBufferException {
|
| + int size;
|
| + try {
|
| + int firstByte = input.read();
|
| + if (firstByte == -1) {
|
| + return null;
|
| + }
|
| + size = CodedInputStream.readRawVarint32(firstByte, input);
|
| + } catch (IOException e) {
|
| + throw new InvalidProtocolBufferException(e.getMessage());
|
| + }
|
| + InputStream limitedInput = new LimitedInputStream(input, size);
|
| + CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput);
|
| + T message = parsePartialFrom(defaultInstance, codedInput, extensionRegistry);
|
| + try {
|
| + codedInput.checkLastTagWas(0);
|
| + } catch (InvalidProtocolBufferException e) {
|
| + throw e.setUnfinishedMessage(message);
|
| + }
|
| + return message;
|
| }
|
| -
|
| - protected static <E> ProtobufList<E> emptyProtobufList() {
|
| - return ProtobufArrayList.emptyList();
|
| +
|
| + /**
|
| + * An abstract visitor that the generated code calls into that we use to implement various
|
| + * features. Fields that are not members of oneofs are always visited. Members of a oneof are only
|
| + * visited when they are the set oneof case value on the "other" proto. The visitOneofNotSet
|
| + * method is invoked if other's oneof case is not set.
|
| + */
|
| + protected interface Visitor {
|
| + boolean visitBoolean(boolean minePresent, boolean mine, boolean otherPresent, boolean other);
|
| + int visitInt(boolean minePresent, int mine, boolean otherPresent, int other);
|
| + double visitDouble(boolean minePresent, double mine, boolean otherPresent, double other);
|
| + float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other);
|
| + long visitLong(boolean minePresent, long mine, boolean otherPresent, long other);
|
| + String visitString(boolean minePresent, String mine, boolean otherPresent, String other);
|
| + ByteString visitByteString(
|
| + boolean minePresent, ByteString mine, boolean otherPresent, ByteString other);
|
| +
|
| + Object visitOneofBoolean(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofInt(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofDouble(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofFloat(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofLong(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofString(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofByteString(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other);
|
| + Object visitOneofMessage(boolean minePresent, Object mine, Object other);
|
| + void visitOneofNotSet(boolean minePresent);
|
| +
|
| + /**
|
| + * Message fields use null sentinals.
|
| + */
|
| + <T extends MessageLite> T visitMessage(T mine, T other);
|
| + LazyFieldLite visitLazyMessage(
|
| + boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyFieldLite other);
|
| +
|
| + <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other);
|
| + BooleanList visitBooleanList(BooleanList mine, BooleanList other);
|
| + IntList visitIntList(IntList mine, IntList other);
|
| + DoubleList visitDoubleList(DoubleList mine, DoubleList other);
|
| + FloatList visitFloatList(FloatList mine, FloatList other);
|
| + LongList visitLongList(LongList mine, LongList other);
|
| + FieldSet<ExtensionDescriptor> visitExtensions(
|
| + FieldSet<ExtensionDescriptor> mine, FieldSet<ExtensionDescriptor> other);
|
| + UnknownFieldSetLite visitUnknownFields(UnknownFieldSetLite mine, UnknownFieldSetLite other);
|
| + <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other);
|
| }
|
| -
|
| - protected static LazyStringArrayList emptyLazyStringArrayList() {
|
| - return LazyStringArrayList.emptyList();
|
| +
|
| + /**
|
| + * Implements equals. Throws a {@link NotEqualsException} when not equal.
|
| + */
|
| + static class EqualsVisitor implements Visitor {
|
| +
|
| + static final class NotEqualsException extends RuntimeException {}
|
| +
|
| + static final EqualsVisitor INSTANCE = new EqualsVisitor();
|
| +
|
| + static final NotEqualsException NOT_EQUALS = new NotEqualsException();
|
| +
|
| + private EqualsVisitor() {}
|
| +
|
| + @Override
|
| + public boolean visitBoolean(
|
| + boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
|
| + if (minePresent != otherPresent || mine != other) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public int visitInt(boolean minePresent, int mine, boolean otherPresent, int other) {
|
| + if (minePresent != otherPresent || mine != other) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public double visitDouble(
|
| + boolean minePresent, double mine, boolean otherPresent, double other) {
|
| + if (minePresent != otherPresent || mine != other) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other) {
|
| + if (minePresent != otherPresent || mine != other) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public long visitLong(boolean minePresent, long mine, boolean otherPresent, long other) {
|
| + if (minePresent != otherPresent || mine != other) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public String visitString(
|
| + boolean minePresent, String mine, boolean otherPresent, String other) {
|
| + if (minePresent != otherPresent || !mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public ByteString visitByteString(
|
| + boolean minePresent, ByteString mine, boolean otherPresent, ByteString other) {
|
| + if (minePresent != otherPresent || !mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofBoolean(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofDouble(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofFloat(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofString(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofMessage(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (MessageLite) other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public void visitOneofNotSet(boolean minePresent) {
|
| + if (minePresent) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public <T extends MessageLite> T visitMessage(T mine, T other) {
|
| + if (mine == null && other == null) {
|
| + return null;
|
| + }
|
| +
|
| + if (mine == null || other == null) {
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + ((GeneratedMessageLite<?, ?>) mine).equals(this, other);
|
| +
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public LazyFieldLite visitLazyMessage(
|
| + boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyFieldLite other) {
|
| + if (!minePresent && !otherPresent) {
|
| + return mine;
|
| + } else if (minePresent && otherPresent && mine.equals(other)) {
|
| + return mine;
|
| + }
|
| + throw NOT_EQUALS;
|
| + }
|
| +
|
| + @Override
|
| + public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public IntList visitIntList(IntList mine, IntList other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public FloatList visitFloatList(FloatList mine, FloatList other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public LongList visitLongList(LongList mine, LongList other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public FieldSet<ExtensionDescriptor> visitExtensions(
|
| + FieldSet<ExtensionDescriptor> mine,
|
| + FieldSet<ExtensionDescriptor> other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public UnknownFieldSetLite visitUnknownFields(
|
| + UnknownFieldSetLite mine,
|
| + UnknownFieldSetLite other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other) {
|
| + if (!mine.equals(other)) {
|
| + throw NOT_EQUALS;
|
| + }
|
| + return mine;
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Implements hashCode by accumulating state.
|
| + */
|
| + private static class HashCodeVisitor implements Visitor {
|
| +
|
| + // The caller must ensure that the visitor is invoked parameterized with this and this such that
|
| + // other is this. This is required due to how oneof cases are handled. See the class comment
|
| + // on Visitor for more information.
|
| +
|
| + private int hashCode = 0;
|
| +
|
| + @Override
|
| + public boolean visitBoolean(
|
| + boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
|
| + hashCode = (53 * hashCode) + Internal.hashBoolean(mine);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public int visitInt(boolean minePresent, int mine, boolean otherPresent, int other) {
|
| + hashCode = (53 * hashCode) + mine;
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public double visitDouble(
|
| + boolean minePresent, double mine, boolean otherPresent, double other) {
|
| + hashCode = (53 * hashCode) + Internal.hashLong(Double.doubleToLongBits(mine));
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other) {
|
| + hashCode = (53 * hashCode) + Float.floatToIntBits(mine);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public long visitLong(boolean minePresent, long mine, boolean otherPresent, long other) {
|
| + hashCode = (53 * hashCode) + Internal.hashLong(mine);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public String visitString(
|
| + boolean minePresent, String mine, boolean otherPresent, String other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public ByteString visitByteString(
|
| + boolean minePresent, ByteString mine, boolean otherPresent, ByteString other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofBoolean(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + Internal.hashBoolean(((Boolean) mine));
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + (Integer) mine;
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofDouble(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + Internal.hashLong(Double.doubleToLongBits((Double) mine));
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofFloat(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + Float.floatToIntBits((Float) mine);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + Internal.hashLong((Long) mine);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofString(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofMessage(boolean minePresent, Object mine, Object other) {
|
| + return visitMessage((MessageLite) mine, (MessageLite) other);
|
| + }
|
| +
|
| + @Override
|
| + public void visitOneofNotSet(boolean minePresent) {
|
| + if (minePresent) {
|
| + throw new IllegalStateException(); // Can't happen if other == this.
|
| + }
|
| + }
|
| +
|
| + @Override
|
| + public <T extends MessageLite> T visitMessage(T mine, T other) {
|
| + final int protoHash;
|
| + if (mine != null) {
|
| + if (mine instanceof GeneratedMessageLite) {
|
| + protoHash = ((GeneratedMessageLite) mine).hashCode(this);
|
| + } else {
|
| + protoHash = mine.hashCode();
|
| + }
|
| + } else {
|
| + protoHash = 37;
|
| + }
|
| + hashCode = (53 * hashCode) + protoHash;
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public LazyFieldLite visitLazyMessage(
|
| + boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyFieldLite other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public IntList visitIntList(IntList mine, IntList other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public FloatList visitFloatList(FloatList mine, FloatList other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public LongList visitLongList(LongList mine, LongList other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public FieldSet<ExtensionDescriptor> visitExtensions(
|
| + FieldSet<ExtensionDescriptor> mine,
|
| + FieldSet<ExtensionDescriptor> other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public UnknownFieldSetLite visitUnknownFields(
|
| + UnknownFieldSetLite mine,
|
| + UnknownFieldSetLite other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other) {
|
| + hashCode = (53 * hashCode) + mine.hashCode();
|
| + return mine;
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Implements field merging semantics over the visitor interface.
|
| + */
|
| + protected static class MergeFromVisitor implements Visitor {
|
| +
|
| + public static final MergeFromVisitor INSTANCE = new MergeFromVisitor();
|
| +
|
| + private MergeFromVisitor() {}
|
| +
|
| + @Override
|
| + public boolean visitBoolean(
|
| + boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public int visitInt(boolean minePresent, int mine, boolean otherPresent, int other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public double visitDouble(
|
| + boolean minePresent, double mine, boolean otherPresent, double other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public long visitLong(boolean minePresent, long mine, boolean otherPresent, long other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public String visitString(
|
| + boolean minePresent, String mine, boolean otherPresent, String other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public ByteString visitByteString(
|
| + boolean minePresent, ByteString mine, boolean otherPresent, ByteString other) {
|
| + return otherPresent ? other : mine;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofBoolean(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofDouble(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofFloat(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofString(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent) {
|
| + LazyFieldLite lazy = (LazyFieldLite) mine;
|
| + lazy.merge((LazyFieldLite) other);
|
| + return lazy;
|
| + }
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public Object visitOneofMessage(boolean minePresent, Object mine, Object other) {
|
| + if (minePresent) {
|
| + return visitMessage((MessageLite) mine, (MessageLite) other);
|
| + }
|
| + return other;
|
| + }
|
| +
|
| + @Override
|
| + public void visitOneofNotSet(boolean minePresent) {
|
| + return;
|
| + }
|
| +
|
| + @SuppressWarnings("unchecked") // Guaranteed by runtime.
|
| + @Override
|
| + public <T extends MessageLite> T visitMessage(T mine, T other) {
|
| + if (mine != null && other != null) {
|
| + return (T) mine.toBuilder().mergeFrom(other).build();
|
| + }
|
| +
|
| + return mine != null ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public LazyFieldLite visitLazyMessage(
|
| + boolean minePresent, LazyFieldLite mine, boolean otherPresent, LazyFieldLite other) {
|
| + // LazyFieldLite's are never null so we can just copy across. Necessary to avoid leakage
|
| + // from builder into immutable message.
|
| + // TODO(dweis): Change to null sentinels?
|
| + mine.merge(other);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) {
|
| + int size = mine.size();
|
| + int otherSize = other.size();
|
| + if (size > 0 && otherSize > 0) {
|
| + if (!mine.isModifiable()) {
|
| + mine = mine.mutableCopyWithCapacity(size + otherSize);
|
| + }
|
| + mine.addAll(other);
|
| + }
|
| +
|
| + return size > 0 ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
|
| + int size = mine.size();
|
| + int otherSize = other.size();
|
| + if (size > 0 && otherSize > 0) {
|
| + if (!mine.isModifiable()) {
|
| + mine = mine.mutableCopyWithCapacity(size + otherSize);
|
| + }
|
| + mine.addAll(other);
|
| + }
|
| +
|
| + return size > 0 ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public IntList visitIntList(IntList mine, IntList other) {
|
| + int size = mine.size();
|
| + int otherSize = other.size();
|
| + if (size > 0 && otherSize > 0) {
|
| + if (!mine.isModifiable()) {
|
| + mine = mine.mutableCopyWithCapacity(size + otherSize);
|
| + }
|
| + mine.addAll(other);
|
| + }
|
| +
|
| + return size > 0 ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
|
| + int size = mine.size();
|
| + int otherSize = other.size();
|
| + if (size > 0 && otherSize > 0) {
|
| + if (!mine.isModifiable()) {
|
| + mine = mine.mutableCopyWithCapacity(size + otherSize);
|
| + }
|
| + mine.addAll(other);
|
| + }
|
| +
|
| + return size > 0 ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public FloatList visitFloatList(FloatList mine, FloatList other) {
|
| + int size = mine.size();
|
| + int otherSize = other.size();
|
| + if (size > 0 && otherSize > 0) {
|
| + if (!mine.isModifiable()) {
|
| + mine = mine.mutableCopyWithCapacity(size + otherSize);
|
| + }
|
| + mine.addAll(other);
|
| + }
|
| +
|
| + return size > 0 ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public LongList visitLongList(LongList mine, LongList other) {
|
| + int size = mine.size();
|
| + int otherSize = other.size();
|
| + if (size > 0 && otherSize > 0) {
|
| + if (!mine.isModifiable()) {
|
| + mine = mine.mutableCopyWithCapacity(size + otherSize);
|
| + }
|
| + mine.addAll(other);
|
| + }
|
| +
|
| + return size > 0 ? mine : other;
|
| + }
|
| +
|
| + @Override
|
| + public FieldSet<ExtensionDescriptor> visitExtensions(
|
| + FieldSet<ExtensionDescriptor> mine,
|
| + FieldSet<ExtensionDescriptor> other) {
|
| + if (mine.isImmutable()) {
|
| + mine = mine.clone();
|
| + }
|
| + mine.mergeFrom(other);
|
| + return mine;
|
| + }
|
| +
|
| + @Override
|
| + public UnknownFieldSetLite visitUnknownFields(
|
| + UnknownFieldSetLite mine,
|
| + UnknownFieldSetLite other) {
|
| + return other == UnknownFieldSetLite.getDefaultInstance()
|
| + ? mine : UnknownFieldSetLite.mutableCopyOf(mine, other);
|
| + }
|
| +
|
| + @Override
|
| + public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other) {
|
| + mine.mergeFrom(other);
|
| + return mine;
|
| + }
|
| }
|
| }
|
|
|