Class AbstractMessage

java.lang.Object
com.google.protobuf.AbstractMessageLite
com.google.protobuf.AbstractMessage
All Implemented Interfaces:
Message, MessageLite, MessageLiteOrBuilder, MessageOrBuilder
Direct Known Subclasses:
DynamicMessage, GeneratedMessage, GeneratedMessageV3, MapEntry

public abstract class AbstractMessage extends AbstractMessageLite implements Message
A partial implementation of the Message interface which implements as many methods of that interface as possible in terms of other methods.
  • Field Details

    • memoizedSize

      protected int memoizedSize
  • Constructor Details

    • AbstractMessage

      public AbstractMessage()
  • Method Details

    • isInitialized

      public boolean isInitialized()
      Description copied from interface: MessageLiteOrBuilder
      Returns true if all required fields in the message and all embedded messages are set, false otherwise.

      See also: MessageOrBuilder.getInitializationErrorString()

      Specified by:
      isInitialized in interface MessageLiteOrBuilder
    • newBuilderForType

      protected Message.Builder newBuilderForType(AbstractMessage.BuilderParent parent)
      Create a nested builder.
    • findInitializationErrors

      public List<String> findInitializationErrors()
      Description copied from interface: MessageOrBuilder
      Returns a list of field paths (e.g. "foo.bar.baz") of required fields which are not set in this message. You should call MessageLiteOrBuilder.isInitialized() first to check if there are any missing fields, as that method is likely to be much faster than this one even when the message is fully-initialized.
      Specified by:
      findInitializationErrors in interface MessageOrBuilder
    • getInitializationErrorString

      public String getInitializationErrorString()
      Description copied from interface: MessageOrBuilder
      Returns a comma-delimited list of required fields which are not set in this message object. You should call MessageLiteOrBuilder.isInitialized() first to check if there are any missing fields, as that method is likely to be much faster than this one even when the message is fully-initialized.
      Specified by:
      getInitializationErrorString in interface MessageOrBuilder
    • hasOneof

      public boolean hasOneof(Descriptors.OneofDescriptor oneof)
      TODO(jieluo): Clear it when all subclasses have implemented this method.
      Specified by:
      hasOneof in interface MessageOrBuilder
    • getOneofFieldDescriptor

      public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
      TODO(jieluo): Clear it when all subclasses have implemented this method.
      Specified by:
      getOneofFieldDescriptor in interface MessageOrBuilder
    • toString

      public final String toString()
      Description copied from interface: Message
      Converts the message to a string in protocol buffer text format. This is just a trivial wrapper around TextFormat.Printer.printToString(MessageOrBuilder).
      Specified by:
      toString in interface Message
      Overrides:
      toString in class Object
    • writeTo

      public void writeTo(CodedOutputStream output) throws IOException
      Description copied from interface: MessageLite
      Serializes the message and writes it to output. This does not flush or close the stream.
      Specified by:
      writeTo in interface MessageLite
      Throws:
      IOException
    • getMemoizedSerializedSize

      int getMemoizedSerializedSize()
      Overrides:
      getMemoizedSerializedSize in class AbstractMessageLite
    • setMemoizedSerializedSize

      void setMemoizedSerializedSize(int size)
      Overrides:
      setMemoizedSerializedSize in class AbstractMessageLite
    • getSerializedSize

      public int getSerializedSize()
      Description copied from interface: MessageLite
      Get the number of bytes required to encode this message. The result is only computed on the first call and memoized after that. If this message requires more than Integer.MAX_VALUE bytes to encode, the return value will be smaller than the actual number of bytes required and might be negative.
      Specified by:
      getSerializedSize in interface MessageLite
    • equals

      public boolean equals(Object other)
      Description copied from interface: Message
      Compares the specified object with this message for equality. Returns true if the given object is a message of the same type (as defined by getDescriptorForType()) and has identical values for all of its fields. Subclasses must implement this; inheriting Object.equals() is incorrect.
      Specified by:
      equals in interface Message
      Overrides:
      equals in class Object
      Parameters:
      other - object to be compared for equality with this message
      Returns:
      true if the specified object is equal to this message
    • hashCode

      public int hashCode()
      Description copied from interface: Message
      Returns the hash code value for this message. The hash code of a message should mix the message's type (object identity of the descriptor) with its contents (known and unknown field values). Subclasses must implement this; inheriting Object.hashCode() is incorrect.
      Specified by:
      hashCode in interface Message
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this message
      See Also:
    • toByteString

      private static ByteString toByteString(Object value)
    • compareBytes

      private static boolean compareBytes(Object a, Object b)
      Compares two bytes fields. The parameters must be either a byte array or a ByteString object. They can be of different type though.
    • convertMapEntryListToMap

      private static Map convertMapEntryListToMap(List list)
      Converts a list of MapEntry messages into a Map used for equals() and hashCode().
    • compareMapField

      private static boolean compareMapField(Object a, Object b)
      Compares two map fields. The parameters must be a list of MapEntry messages.
    • compareFields

      Compares two set of fields. This method is used to implement equals(Object) and
      invalid reference
      AbstractMutableMessage#equals(Object)
      . It takes special care of bytes fields because immutable messages and mutable messages use different Java type to represent a bytes field and this method should be able to compare immutable messages, mutable messages and also an immutable message to a mutable message.
    • hashMapField

      private static int hashMapField(Object value)
      Calculates the hash code of a map field. value must be a list of MapEntry messages.
    • hashFields

      protected static int hashFields(int hash, Map<Descriptors.FieldDescriptor,Object> map)
      Get a hash code for given fields and values, using the given seed.
    • newUninitializedMessageException

      UninitializedMessageException newUninitializedMessageException()
      Package private helper method for AbstractParser to create UninitializedMessageException with missing field information.
      Overrides:
      newUninitializedMessageException in class AbstractMessageLite
    • hashLong

      @Deprecated protected static int hashLong(long n)
      Deprecated.
      from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
    • hashBoolean

      @Deprecated protected static int hashBoolean(boolean b)
      Deprecated.
      from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
    • hashEnum

      @Deprecated protected static int hashEnum(Internal.EnumLite e)
      Deprecated.
      from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
    • hashEnumList

      @Deprecated protected static int hashEnumList(List<? extends Internal.EnumLite> list)
      Deprecated.
      from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.