com.esotericsoftware.kryo.serialize
Class DoubleSerializer

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

public class DoubleSerializer
extends Serializer

Writes a 1-10 byte double.

Author:
Nathan Sweet

Constructor Summary
DoubleSerializer()
          Creates a DoubleSerializer that allows uses 8 bytes to represent a double, with no loss of precision.
DoubleSerializer(double precision, boolean optimizePositive)
          Creates a DoubleSerializer that allows uses 1-10 bytes to represent a double, with a loss of precision.
 
Method Summary
 java.lang.Double readObjectData(java.nio.ByteBuffer buffer, java.lang.Class type)
          Reads an object from the buffer.
 void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object object)
          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

DoubleSerializer

public DoubleSerializer()
Creates a DoubleSerializer that allows uses 8 bytes to represent a double, with no loss of precision.


DoubleSerializer

public DoubleSerializer(double precision,
                        boolean optimizePositive)
Creates a DoubleSerializer that allows uses 1-10 bytes to represent a double, with a loss of precision. The double is multiplied by the specified precision, then cast to a long and serialized with LongSerializer. LongSerializer uses 1-8 bytes from 0 to 7205794037927935 with "optimize positive" and -3602897018963968 to 3602897018963967 without. If a double multiplied by the precision would fall out these values, it will take 9 or 10 bytes to serialize and it may be better to use the other DoubleSerializer constructor.

Method Detail

readObjectData

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

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

writeObjectData

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

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


Copyright © 2011. All Rights Reserved.