# Class LazyFieldLite (3.19.4)

    public class LazyFieldLite

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.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> LazyFieldLite

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### fromValue(MessageLite value)

    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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.LazyFieldLite` |   |

## Constructors

### LazyFieldLite()

    public LazyFieldLite()

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

### LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)

    public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes)

Constructs a LazyFieldLite with bytes that will be parsed lazily.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `extensionRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ExtensionRegistryLite` |
| `bytes` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` |

## Fields

### value

    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.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` |   |

## Methods

### 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.

### containsDefaultInstance()

    public boolean containsDefaultInstance()

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### ensureInitialized(MessageLite defaultInstance)

    protected void ensureInitialized(MessageLite defaultInstance)

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `defaultInstance` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` |

### equals(Object o)

    public boolean equals(Object o)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `o` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### 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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### getValue(MessageLite defaultInstance)

    public MessageLite getValue(MessageLite defaultInstance)

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

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `defaultInstance` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` its message's default instance. It's also used to get parser for the message type. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### merge(LazyFieldLite other)

    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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `other` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.LazyFieldLite` |

### mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)

    public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)

Merges another instance's contents from a stream.

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `input` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.CodedInputStream` |
| `extensionRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ExtensionRegistryLite` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### set(LazyFieldLite other)

    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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `other` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.LazyFieldLite` |

### setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)

    public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry)

Sets this field with bytes to delay-parse.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `bytes` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` |
| `extensionRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ExtensionRegistryLite` |

### setValue(MessageLite value)

    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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageLite` |   |

### toByteString()

    public ByteString toByteString()

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.ByteString` |   |