com.hazelcast.nio.serialization

## Interface Data

- All Known Implementing Classes:
    com.hazelcast.internal.serialization.impl.HeapData, Packet

      public interface Data

  Data is basic unit of serialization. It stores binary form of an object serialized by `SerializationService.toData(Object)`.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `copyTo(byte[] dest, int destPos)` Copies the payload contained in the Data to the destination buffer.
    `int` | `dataSize()` Returns size of internal binary data in bytes
    `int` | `getHeapCost()` Returns approximate heap cost of this Data object in bytes.
    `int` | `getPartitionHash()` Returns partition hash calculated for serialized object.
    `int` | `getType()` Returns serialization type of binary form.
    `long` | `hash64()` Returns 64-bit hash code for this Data object.
    `boolean` | `hasPartitionHash()` Returns true if Data has partition hash, false otherwise.
    `boolean` | `isJson()` Returns true if this Data is created from a `HazelcastJsonValue` object, false otherwise
    `boolean` | `isPortable()` Returns true if this Data is created from a `Portable` object, false otherwise.
    `byte[]` | `toByteArray()` Returns byte array representation of internal binary format.
    `int` | `totalSize()` Returns the total size of Data in bytes.

- - ### Method Detail

    - #### toByteArray

          byte[] toByteArray()

      Returns byte array representation of internal binary format.
      Returns:
        binary data

    - #### getType

          int getType()

      Returns serialization type of binary form. It's defined by `Serializer.getTypeId()`
      Returns:
        serializer type ID

    - #### totalSize

          int totalSize()

      Returns the total size of Data in bytes. The total size is the size of a byte array to contain the full content of this data object. For example in case of an HeapData object, the total size will be the length of the payload.
      Returns:
        total size

    - #### copyTo

          void copyTo(byte[] dest,
                      int destPos)

      Copies the payload contained in the Data to the destination buffer. The dest byte-buffer needs to be large enough to contain the payload. Otherwise an exception is thrown. The reason this method exists instead of relying on the `toByteArray()` is the existence of the NativeMemoryData. With the NativeMemoryData it would lead to a temporary byte-array. This method prevents this temporary byte-array needing to be created.
      Parameters:
        `dest` - to byte-buffer to write to
        `destPos` - the position in the destination buffer.

    - #### dataSize

          int dataSize()

      Returns size of internal binary data in bytes
      Returns:
        internal data size

    - #### getHeapCost

          int getHeapCost()

      Returns approximate heap cost of this Data object in bytes.
      Returns:
        approximate heap cost

    - #### getPartitionHash

          int getPartitionHash()

      Returns partition hash calculated for serialized object. Partition hash is used to determine partition of a Data and is calculated using `PartitioningStrategy` during serialization.

      If partition hash is not set then standard `hashCode()` is used.
      Returns:
        partition hash
      See Also:
        `PartitionAware`, `PartitioningStrategy`, `SerializationService.toData(Object, com.hazelcast.core.PartitioningStrategy)`

    - #### hasPartitionHash

          boolean hasPartitionHash()

      Returns true if Data has partition hash, false otherwise.
      Returns:
        true if Data has partition hash, false otherwise.

    - #### hash64

          long hash64()

      Returns 64-bit hash code for this Data object.
      Returns:
        64-bit hash code

    - #### isPortable

          boolean isPortable()

      Returns true if this Data is created from a `Portable` object, false otherwise.
      Returns:
        true if source object is `Portable`, false otherwise.

    - #### isJson

          boolean isJson()

      Returns true if this Data is created from a `HazelcastJsonValue` object, false otherwise
      Returns:
        true if source object is `HazelcastJsonValue`, false otherwise.

Copyright © 2019. All rights reserved.