Package com.google.protobuf
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 theMessage
interface which implements as many methods of that interface as possible in terms of other methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractMessage.Builder<BuilderType extends AbstractMessage.Builder<BuilderType>>
A partial implementation of theMessage.Builder
interface which implements as many methods of that interface as possible in terms of other methods.protected static interface
AbstractMessage.BuilderParent
Interface for the parent of a Builder that allows the builder to communicate invalidations back to the parent for use when using nested builders.-
Nested classes/interfaces inherited from class com.google.protobuf.AbstractMessageLite
AbstractMessageLite.InternalOneOfEnum
-
-
Field Summary
Fields Modifier and Type Field Description protected int
memoizedSize
-
Fields inherited from class com.google.protobuf.AbstractMessageLite
memoizedHashCode
-
-
Constructor Summary
Constructors Constructor Description AbstractMessage()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static boolean
compareBytes(java.lang.Object a, java.lang.Object b)
Compares two bytes fields.(package private) static boolean
compareFields(java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> a, java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> b)
Compares two set of fields.private static boolean
compareMapField(java.lang.Object a, java.lang.Object b)
Compares two map fields.private static java.util.Map
convertMapEntryListToMap(java.util.List list)
Converts a list of MapEntry messages into a Map used for equals() and hashCode().boolean
equals(java.lang.Object other)
Compares the specified object with this message for equality.java.util.List<java.lang.String>
findInitializationErrors()
Returns a list of field paths (e.g.java.lang.String
getInitializationErrorString()
Returns a comma-delimited list of required fields which are not set in this message object.(package private) int
getMemoizedSerializedSize()
Descriptors.FieldDescriptor
getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.int
getSerializedSize()
Get the number of bytes required to encode this message.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.int
hashCode()
Returns the hash code value for this message.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.protected static int
hashEnumList(java.util.List<? extends Internal.EnumLite> list)
Deprecated.from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.protected static int
hashFields(int hash, java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> map)
Get a hash code for given fields and values, using the given seed.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.private static int
hashMapField(java.lang.Object value)
Calculates the hash code of a map field.boolean
hasOneof(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.boolean
isInitialized()
Returns true if all required fields in the message and all embedded messages are set, false otherwise.protected Message.Builder
newBuilderForType(AbstractMessage.BuilderParent parent)
Create a nested builder.(package private) UninitializedMessageException
newUninitializedMessageException()
Package private helper method for AbstractParser to create UninitializedMessageException with missing field information.(package private) void
setMemoizedSerializedSize(int size)
private static ByteString
toByteString(java.lang.Object value)
java.lang.String
toString()
Converts the message to a string in protocol buffer text format.void
writeTo(CodedOutputStream output)
Serializes the message and writes it tooutput
.-
Methods inherited from class com.google.protobuf.AbstractMessageLite
addAll, addAll, checkByteStringIsUtf8, getSerializedSize, toByteArray, toByteString, writeDelimitedTo, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.protobuf.Message
getParserForType, newBuilderForType, toBuilder
-
Methods inherited from interface com.google.protobuf.MessageLite
toByteArray, toByteString, writeDelimitedTo, writeTo
-
Methods inherited from interface com.google.protobuf.MessageOrBuilder
getAllFields, getDefaultInstanceForType, getDescriptorForType, getField, getRepeatedField, getRepeatedFieldCount, getUnknownFields, hasField
-
-
-
-
Method Detail
-
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.- Specified by:
isInitialized
in interfaceMessageLiteOrBuilder
-
newBuilderForType
protected Message.Builder newBuilderForType(AbstractMessage.BuilderParent parent)
Create a nested builder.
-
findInitializationErrors
public java.util.List<java.lang.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 callMessageLiteOrBuilder.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 interfaceMessageOrBuilder
-
getInitializationErrorString
public java.lang.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 callMessageLiteOrBuilder.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 interfaceMessageOrBuilder
-
hasOneof
public boolean hasOneof(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
hasOneof
in interfaceMessageOrBuilder
-
getOneofFieldDescriptor
public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof)
TODO(jieluo): Clear it when all subclasses have implemented this method.- Specified by:
getOneofFieldDescriptor
in interfaceMessageOrBuilder
-
toString
public final java.lang.String toString()
Description copied from interface:Message
Converts the message to a string in protocol buffer text format. This is just a trivial wrapper aroundTextFormat.Printer.printToString(MessageOrBuilder)
.
-
writeTo
public void writeTo(CodedOutputStream output) throws java.io.IOException
Description copied from interface:MessageLite
Serializes the message and writes it tooutput
. This does not flush or close the stream.- Specified by:
writeTo
in interfaceMessageLite
- Throws:
java.io.IOException
-
getMemoizedSerializedSize
int getMemoizedSerializedSize()
- Overrides:
getMemoizedSerializedSize
in classAbstractMessageLite
-
setMemoizedSerializedSize
void setMemoizedSerializedSize(int size)
- Overrides:
setMemoizedSerializedSize
in classAbstractMessageLite
-
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.- Specified by:
getSerializedSize
in interfaceMessageLite
-
equals
public boolean equals(java.lang.Object other)
Description copied from interface:Message
Compares the specified object with this message for equality. Returnstrue
if the given object is a message of the same type (as defined bygetDescriptorForType()
) and has identical values for all of its fields. Subclasses must implement this; inheritingObject.equals()
is incorrect.
-
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; inheritingObject.hashCode()
is incorrect.
-
toByteString
private static ByteString toByteString(java.lang.Object value)
-
compareBytes
private static boolean compareBytes(java.lang.Object a, java.lang.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 java.util.Map convertMapEntryListToMap(java.util.List list)
Converts a list of MapEntry messages into a Map used for equals() and hashCode().
-
compareMapField
private static boolean compareMapField(java.lang.Object a, java.lang.Object b)
Compares two map fields. The parameters must be a list of MapEntry messages.
-
compareFields
static boolean compareFields(java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> a, java.util.Map<Descriptors.FieldDescriptor,java.lang.Object> b)
Compares two set of fields. This method is used to implementequals(Object)
andAbstractMutableMessage#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(java.lang.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, java.util.Map<Descriptors.FieldDescriptor,java.lang.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 classAbstractMessageLite
-
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(java.util.List<? extends Internal.EnumLite> list)
Deprecated.from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
-
-