# Class ArrayOfItemsSerDe<T>

java.lang.Object
org.apache.datasketches.common.ArrayOfItemsSerDe<T>

Type Parameters:
  `T` - Type of item

Direct Known Subclasses:
  `ArrayOfBooleansSerDe, ArrayOfDoublesSerDe, ArrayOfLongsSerDe, ArrayOfNumbersSerDe, ArrayOfStringsSerDe, ArrayOfUtf16StringsSerDe`

public abstract class ArrayOfItemsSerDe<T> extends Object
Base class for serializing and deserializing custom types.

Author:
  Alexander Saydakov

## Constructor Summary

Constructors
Constructor
Description
`ArrayOfItemsSerDe()`
No argument constructor.

## Method Summary

Modifier and Type
Method
Description
`T[]`
`deserializeFromMemorySegment(MemorySegment seg, int numItems)`
Deserialize a contiguous sequence of serialized items from the given MemorySegment starting at a MemorySegment offset of zero and extending numItems.
`abstract T[]`
`deserializeFromMemorySegment(MemorySegment seg, long offsetBytes, int numItems)`
Deserialize a contiguous sequence of serialized items from the given MemorySegment starting at the given MemorySegment offsetBytes and extending numItems.
`abstract Class<T>`
`getClassOfT()`
Returns the concrete class of type T
`abstract byte[]`
`serializeToByteArray(T item)`
Serialize a single unserialized item to a byte array.
`abstract byte[]`
`serializeToByteArray(T[] items)`
Serialize an array of unserialized items to a byte array of contiguous serialized items.
`abstract int`
`sizeOf(MemorySegment seg, long offsetBytes, int numItems)`
Returns the serialized size in bytes of the number of contiguous serialized items in MemorySegment.
`abstract int`
`sizeOf(T item)`
Returns the serialized size in bytes of a single unserialized item.
`int`
`sizeOf(T[] items)`
Returns the serialized size in bytes of the array of items.
`abstract String`
`toString(T item)`
Returns a human readable string of an item.

### Methods inherited from class Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ArrayOfItemsSerDe

public ArrayOfItemsSerDe()
No argument constructor.

## Method Details

### serializeToByteArray

public abstract byte[] serializeToByteArray(T item)
Serialize a single unserialized item to a byte array.

Parameters:
  `item` - the item to be serialized
Returns:
  serialized representation of the given item

### serializeToByteArray

public abstract byte[] serializeToByteArray(T[] items)
Serialize an array of unserialized items to a byte array of contiguous serialized items.

Parameters:
  `items` - array of items to be serialized
Returns:
  contiguous, serialized representation of the given array of unserialized items

### deserializeFromMemorySegment

public T[] deserializeFromMemorySegment(MemorySegment seg, int numItems)
Deserialize a contiguous sequence of serialized items from the given MemorySegment starting at a MemorySegment offset of zero and extending numItems.

Parameters:
  `seg` - MemorySegment containing a contiguous sequence of serialized items
  `numItems` - number of items in the contiguous serialized sequence.
Returns:
  array of deserialized items
See Also:
  - `deserializeFromMemorySegment(MemorySegment, long, int)`

### deserializeFromMemorySegment

public abstract T[] deserializeFromMemorySegment(MemorySegment seg, long offsetBytes, int numItems)
Deserialize a contiguous sequence of serialized items from the given MemorySegment starting at the given MemorySegment offsetBytes and extending numItems.

Parameters:
  `seg` - MemorySegment containing a contiguous sequence of serialized items
  `offsetBytes` - the starting offset in the given MemorySegment.
  `numItems` - number of items in the contiguous serialized sequence.
Returns:
  array of deserialized items

### sizeOf

public abstract int sizeOf(T item)
Returns the serialized size in bytes of a single unserialized item.

Parameters:
  `item` - a specific item
Returns:
  the serialized size in bytes of a single unserialized item.

### sizeOf

public int sizeOf(T[] items)
Returns the serialized size in bytes of the array of items.

Parameters:
  `items` - an array of items.
Returns:
  the serialized size in bytes of the array of items.

### sizeOf

public abstract int sizeOf(MemorySegment seg, long offsetBytes, int numItems)
Returns the serialized size in bytes of the number of contiguous serialized items in MemorySegment. The capacity of the given MemorySegment can be much larger that the required size of the items.

Parameters:
  `seg` - the given MemorySegment.
  `offsetBytes` - the starting offset in the given MemorySegment.
  `numItems` - the number of serialized items contained in the MemorySegment
Returns:
  the serialized size in bytes of the given number of items.

### toString

public abstract String toString(T item)
Returns a human readable string of an item.

Parameters:
  `item` - a specific item
Returns:
  a human readable string of an item.

### getClassOfT

public abstract Class<T> getClassOfT()
Returns the concrete class of type T

Returns:
  the concrete class of type T