Class LazyFieldLite
- java.lang.Object
-
- com.google.protobuf.LazyFieldLite
-
- Direct Known Subclasses:
LazyField
public class LazyFieldLite extends Object
LazyFieldLite encapsulates the logic of lazily parsing message fields. It stores the message in a ByteString initially and then parses it on-demand.LazyFieldLite is thread-compatible: concurrent reads are safe once the proto that this LazyFieldLite is a part of is no longer being mutated by its Builder. However, explicit synchronization is needed under read/write situations.
When a LazyFieldLite is used in the context of a MessageLite object, its behavior is considered to be immutable and none of the setter methods in its API are expected to be invoked. All of the getters are expected to be thread-safe. When used in the context of a MessageLite.Builder, setters can be invoked, but there is no guarantee of thread safety.
TODO: Consider splitting this class's functionality and put the mutable methods into a separate builder class to allow us to give stronger compile-time guarantees.
This class is internal implementation detail of the protobuf library, so you don't need to use it directly.
-
-
Field Summary
Fields Modifier and Type Field Description protected MessageLitevalueThe parsed value.
-
Constructor Summary
Constructors Constructor Description LazyFieldLite()Constructs a LazyFieldLite with no contents, and no ability to parse extensions.LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)Constructs a LazyFieldLite with bytes that will be parsed lazily.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the value state of this instance.intcomputeMessageSetExtensionSize(int fieldNumber)Compute the number of bytes that would be needed to encode a lazily parsed MessageSet extension field to the stream.intcomputeSize(int fieldNumber)Compute the number of bytes that would be needed to encode an embedded message in lazy field, including tag.intcomputeSizeNoTag()Compute the number of bytes that would be needed to encode an embedded message stored in lazy field.booleancontainsDefaultInstance()Determines whether this LazyFieldLite instance represents the default instance of this type.protected voidensureInitialized(MessageLite defaultInstance)Might lazily parse the bytes that were previously passed in.booleanequals(Object o)Indicates whether some other object is "equal to" this one.static LazyFieldLitefromValue(MessageLite value)Constructs a LazyFieldLite instance with a value.intgetSerializedSize()Due to the optional field can be duplicated at the end of serialized bytes, which will make the serialized size changed after LazyField parsed.MessageLitegetValue()Gets the value of this field by parsing the bytes if necessary.inthashCode()Returns a hash code value for the object.voidmerge(LazyFieldLite other)Merges another instance's contents.voidmergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)Merges another instance's contents from a stream.voidset(LazyFieldLite other)Overrides the contents of this LazyField.voidsetByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)Sets this field with bytes to delay-parse.MessageLitesetValue(MessageLite value)Sets the value of the instance and returns the old value without delay parsing anything.ByteStringtoByteString()Returns a BytesString for this field in a thread-safe way.
-
-
-
Field Detail
-
value
protected volatile MessageLite value
The parsed value. When this is null and a caller needs access to the MessageLite value, thendelayedByteswill be parsed lazily at that time.
-
-
Constructor Detail
-
LazyFieldLite
public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)
Constructs a LazyFieldLite with bytes that will be parsed lazily.
-
LazyFieldLite
public LazyFieldLite()
Constructs a LazyFieldLite with no contents, and no ability to parse extensions.
-
-
Method Detail
-
fromValue
public static LazyFieldLite fromValue(MessageLite value)
Constructs a LazyFieldLite instance with a value. The LazyFieldLite may not be able to parse the extensions in the value as it has no ExtensionRegistry.
-
equals
public boolean equals(Object o)
Description copied from class:ObjectIndicates whether some other object is "equal to" this one.The
equalsmethod implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The
equalsmethod for classObjectimplements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesxandy, this method returnstrueif and only ifxandyrefer to the same object (x == yhas the valuetrue).Note that it is generally necessary to override the
hashCodemethod whenever this method is overridden, so as to maintain the general contract for thehashCodemethod, which states that equal objects must have equal hash codes.- Overrides:
equalsin classObject- Parameters:
o- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
- It is reflexive: for any non-null reference value
-
hashCode
public int hashCode()
Description copied from class:ObjectReturns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap.The general contract of
hashCodeis:- Whenever it is invoked on the same object more than once during an execution of a Java
application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal according to the
Object.equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class
Objectdoes return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
- Whenever it is invoked on the same object more than once during an execution of a Java
application, the
-
containsDefaultInstance
public boolean containsDefaultInstance()
Determines whether this LazyFieldLite instance represents the default instance of this type.
-
clear
public void clear()
Clears the value state of this instance.LazyField is not thread-safe for write access. Synchronizations are needed under read/write situations.
-
set
public void set(LazyFieldLite other)
Overrides the contents of this LazyField.LazyField is not thread-safe for write access. Synchronizations are needed under read/write situations.
-
getValue
public MessageLite getValue()
Gets the value of this field by parsing the bytes if necessary.- Throws:
NullPointerException- if the default instance is null and the field is unparsed.
-
setValue
@CanIgnoreReturnValue public MessageLite setValue(MessageLite value)
Sets the value of the instance and returns the old value without delay parsing anything.LazyField is not thread-safe for write access. Synchronizations are needed under read/write situations.
-
merge
public void merge(LazyFieldLite other)
Merges another instance's contents. In some cases may drop some extensions if both fields contain data. If the other field has anExtensionRegistrybut this does not, then this field will copy over thatExtensionRegistry.LazyField is not thread-safe for write access. Synchronizations are needed under read/write situations.
-
mergeFrom
public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException
Merges another instance's contents from a stream.LazyField is not thread-safe for write access. Synchronizations are needed under read/write situations.
- Throws:
IOException
-
setByteString
public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)
Sets this field with bytes to delay-parse.
-
getSerializedSize
public int getSerializedSize()
Due to the optional field can be duplicated at the end of serialized bytes, which will make the serialized size changed after LazyField parsed. Be careful when using this method.
-
toByteString
public ByteString toByteString()
Returns a BytesString for this field in a thread-safe way.
-
computeSizeNoTag
public int computeSizeNoTag()
Compute the number of bytes that would be needed to encode an embedded message stored in lazy field.
-
computeSize
public int computeSize(int fieldNumber)
Compute the number of bytes that would be needed to encode an embedded message in lazy field, including tag.
-
computeMessageSetExtensionSize
public int computeMessageSetExtensionSize(int fieldNumber)
Compute the number of bytes that would be needed to encode a lazily parsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.
-
ensureInitialized
protected void ensureInitialized(MessageLite defaultInstance)
Might lazily parse the bytes that were previously passed in. Is thread-safe.
-
-