public class CollectionSerializer extends Serializer
Collection
interface.
With the default constructor, a collection requires a 1-3 byte header and an extra 2-3 bytes is written for each element in the collection. The alternate constructor can be used to improve efficiency to match that of using an array instead of a collection.
Constructor and Description |
---|
CollectionSerializer(Kryo kryo) |
Modifier and Type | Method and Description |
---|---|
<T> T |
readObjectData(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
Reads an object from the buffer.
|
void |
setElementClass(java.lang.Class elementClass) |
void |
setElementClass(java.lang.Class elementClass,
Serializer serializer) |
void |
setElementsCanBeNull(boolean elementsCanBeNull) |
void |
setLength(int length)
Sets the number of objects in the collection.
|
void |
writeObjectData(java.nio.ByteBuffer buffer,
java.lang.Object object)
Writes the object to the buffer.
|
isFinal, newInstance, readObject, setCanBeNull, writeObject
public CollectionSerializer(Kryo kryo)
public void setElementsCanBeNull(boolean elementsCanBeNull)
elementsCanBeNull
- False if all elements are not null. This saves 1 byte per element if elementClass is set. True if
it is not known (default).public void setElementClass(java.lang.Class elementClass)
elementClass
- The concrete class of each element. This saves 1-2 bytes per element. The serializer registered for the
specified class will be used. Set to null if the class is not known or varies per element (default).public void setLength(int length)
public void setElementClass(java.lang.Class elementClass, Serializer serializer)
elementClass
- The concrete class of each element. This saves 1-2 bytes per element. Set to null if the class is not
known or varies per element (default).serializer
- The serializer to use for each element.public void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object object)
Serializer
writeObjectData
in class Serializer
object
- Cannot be null.public <T> T readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
Serializer
readObjectData
in class Serializer