public class ArraySerializer extends Serializer
With the default constructor, an array requires a header of 2-4 bytes plus 2 bytes for each dimension beyond the first. If the array type is not final then an extra byte is written for each element.
Kryo.register(Class, Serializer)
Constructor and Description |
---|
ArraySerializer(Kryo kryo) |
Modifier and Type | Method and Description |
---|---|
static int |
getDimensionCount(java.lang.Class arrayClass) |
static int[] |
getDimensions(java.lang.Object array) |
static java.lang.Class |
getElementClass(java.lang.Class arrayClass) |
<T> T |
readObjectData(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
Reads an object from the buffer.
|
void |
setDimensionCount(java.lang.Integer dimensions) |
void |
setElementsAreSameType(boolean elementsAreSameType) |
void |
setElementsCanBeNull(boolean elementsCanBeNull) |
void |
setLength(int length)
Identical to calling
setLengths(int[]) with: new int[] {length} |
void |
setLengths(int[] lengths)
Sets both the number of dimensions and the lengths of each.
|
void |
writeObjectData(java.nio.ByteBuffer buffer,
java.lang.Object array)
Writes the object to the buffer.
|
isFinal, newInstance, readObject, setCanBeNull, writeObject
public ArraySerializer(Kryo kryo)
public void setDimensionCount(java.lang.Integer dimensions)
dimensions
- The number of dimensions. Saves 1 byte. Set to null to determine the number of dimensions (default).public void setLength(int length)
setLengths(int[])
with: new int[] {length}public void setLengths(int[] lengths)
public void setElementsCanBeNull(boolean elementsCanBeNull)
elementsCanBeNull
- False if all elements are not null. This saves 1 byte per element if the array type is final or
elementsAreSameClassAsType is true. True if it is not known (default).public void setElementsAreSameType(boolean elementsAreSameType)
elementsAreSameType
- True if all elements are the same type as the array (ie they don't extend the array type). This
saves 1 byte per element if the array type is not final. Set to false if the array type is final or elements
extend the array type (default).public void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object array)
Serializer
writeObjectData
in class Serializer
array
- Cannot be null.public <T> T readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
Serializer
readObjectData
in class Serializer
public static int getDimensionCount(java.lang.Class arrayClass)
public static int[] getDimensions(java.lang.Object array)
public static java.lang.Class getElementClass(java.lang.Class arrayClass)