com.esotericsoftware.kryo.serialize
Class ArraySerializer

java.lang.Object
  extended by com.esotericsoftware.kryo.Serializer
      extended by com.esotericsoftware.kryo.serialize.ArraySerializer

public class ArraySerializer
extends Serializer

Serializes arrays.

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.

Author:
Nathan Sweet
See Also:
Kryo.register(Class, Serializer)

Constructor Summary
ArraySerializer(Kryo kryo)
           
 
Method Summary
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.
 
Methods inherited from class com.esotericsoftware.kryo.Serializer
isFinal, newInstance, readObject, setCanBeNull, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArraySerializer

public ArraySerializer(Kryo kryo)
Method Detail

setDimensionCount

public void setDimensionCount(java.lang.Integer dimensions)
Parameters:
dimensions - The number of dimensions. Saves 1 byte. Set to null to determine the number of dimensions (default).

setLength

public void setLength(int length)
Identical to calling setLengths(int[]) with: new int[] {length}


setLengths

public void setLengths(int[] lengths)
Sets both the number of dimensions and the lengths of each. Saves 2-6 bytes plus 1-5 bytes for each dimension beyond the first.


setElementsCanBeNull

public void setElementsCanBeNull(boolean elementsCanBeNull)
Parameters:
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).

setElementsAreSameType

public void setElementsAreSameType(boolean elementsAreSameType)
Parameters:
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).

writeObjectData

public void writeObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Object array)
Description copied from class: Serializer
Writes the object to the buffer.

Specified by:
writeObjectData in class Serializer
array - Cannot be null.

readObjectData

public <T> T readObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Class<T> type)
Description copied from class: Serializer
Reads an object from the buffer.

Specified by:
readObjectData in class Serializer
Returns:
The deserialized object, never null.

getDimensionCount

public static int getDimensionCount(java.lang.Class arrayClass)

getDimensions

public static int[] getDimensions(java.lang.Object array)

getElementClass

public static java.lang.Class getElementClass(java.lang.Class arrayClass)


Copyright © 2011. All Rights Reserved.