Top Description Fields Constructors Methods
com.google.protobuf

public Class LazyFieldLite

extends Object
Class Inheritance
Known Direct Subclasses
com.google.protobuf.LazyField
Imports
java.io.IOException

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(yatin,dweis): 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.

Author
[email protected] (Xiang Li)

Field Summary

Modifier and TypeField and Description
private ByteString
delayedBytes

A delayed-parsed version of the contents of this field.

private static final ExtensionRegistryLite
private ExtensionRegistryLite
extensionRegistry

An ExtensionRegistryLite for parsing bytes.

private volatile ByteString
memoizedBytes

The memoized bytes for value.

protected volatile MessageLite
value

The parsed value.

Constructor Summary

AccessConstructor and Description
public
LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)

Constructs a LazyFieldLite with bytes that will be parsed lazily.

public
LazyFieldLite()

Constructs a LazyFieldLite with no contents, and no ability to parse extensions.

Method Summary

Modifier and TypeMethod and Description
private static void
public void
clear()

Clears the value state of this instance.

public boolean
containsDefaultInstance()

Determines whether this LazyFieldLite instance represents the default instance of this type.

protected void
ensureInitialized(MessageLite defaultInstance)

Might lazily parse the bytes that were previously passed in. Is thread-safe.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public static LazyFieldLite
fromValue(MessageLite value)

Constructs a LazyFieldLite instance with a value.

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.

public MessageLite
getValue(MessageLite
its message's default instance. It's also used to get parser for the message type.
defaultInstance
)

Returns message instance.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public void
merge(LazyFieldLite other)

Merges another instance's contents.

public void
mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)

Merges another instance's contents from a stream.

private static MessageLite
mergeValueAndBytes(MessageLite value, ByteString otherBytes, ExtensionRegistryLite extensionRegistry)

public void
set(LazyFieldLite other)

Overrides the contents of this LazyField.

public void
setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)

Sets this field with bytes to delay-parse.

public MessageLite
setValue(MessageLite value)

Sets the value of the instance and returns the old value without delay parsing anything.

public ByteString
toByteString()

Returns a BytesString for this field in a thread-safe way.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

delayedBytesback to summary
private ByteString delayedBytes

A delayed-parsed version of the contents of this field. When this field is non-null, then the "value" field is allowed to be null until the time that the value needs to be read.

When delayedBytes is non-null then extensionRegistry is required to also be non-null. value and memoizedBytes will be initialized lazily.

EMPTY_REGISTRYback to summary
private static final ExtensionRegistryLite EMPTY_REGISTRY
extensionRegistryback to summary
private ExtensionRegistryLite extensionRegistry

An ExtensionRegistryLite for parsing bytes. It is non-null on a best-effort basis. It is only guaranteed to be non-null if this message was initialized using bytes and an ExtensionRegistry. If it directly had a value set then it will be null, unless it has been merged with another LazyFieldLite that had an ExtensionRegistry.

memoizedBytesback to summary
private volatile ByteString memoizedBytes

The memoized bytes for value. This is an optimization for the toByteString() method to not have to recompute its return-value on each invocation. TODO(yatin): Figure out whether this optimization is actually necessary.

valueback to summary
protected volatile MessageLite value

The parsed value. When this is null and a caller needs access to the MessageLite value, then delayedBytes will be parsed lazily at that time.

Constructor Detail

LazyFieldLiteback to summary
public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)

Constructs a LazyFieldLite with bytes that will be parsed lazily.

LazyFieldLiteback to summary
public LazyFieldLite()

Constructs a LazyFieldLite with no contents, and no ability to parse extensions.

Method Detail

checkArgumentsback to summary
private static void checkArguments(ExtensionRegistryLite extensionRegistry, ByteString bytes)
clearback to summary
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.

containsDefaultInstanceback to summary
public boolean containsDefaultInstance()

Determines whether this LazyFieldLite instance represents the default instance of this type.

ensureInitializedback to summary
protected void ensureInitialized(MessageLite defaultInstance)

Might lazily parse the bytes that were previously passed in. Is thread-safe.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fromValueback to summary
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.

getSerializedSizeback to summary
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.

getValueback to summary
public MessageLite getValue(MessageLite defaultInstance)

Returns message instance. It may do some thread-safe delayed parsing of bytes.

Parameters
defaultInstance:MessageLite

its message's default instance. It's also used to get parser for the message type.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons 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 method, then calling the hashCode method 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 equals method, then calling the hashCode method 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.
Returns:int

a hash code value for this object.

Annotations
@Override
mergeback to summary
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 an ExtensionRegistry but this does not, then this field will copy over that ExtensionRegistry.

LazyField is not thread-safe for write access. Synchronizations are needed under read/write situations.

mergeFromback to summary
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.

mergeValueAndBytesback to summary
private static MessageLite mergeValueAndBytes(MessageLite value, ByteString otherBytes, ExtensionRegistryLite extensionRegistry)
setback to summary
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.

setByteStringback to summary
public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)

Sets this field with bytes to delay-parse.

setValueback to summary
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.

toByteStringback to summary
public ByteString toByteString()

Returns a BytesString for this field in a thread-safe way.