com.esotericsoftware.kryo.serialize
Class FloatSerializer

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

public class FloatSerializer
extends Serializer

Writes a 1-5 byte float.

Author:
Nathan Sweet

Constructor Summary
FloatSerializer()
          Creates a FloatSerializer that allows uses 4 bytes to represent a float, with no loss of precision.
FloatSerializer(float precision, boolean optimizePositive)
          Creates a FloatSerializer that allows uses 1-5 bytes to represent a float, with a loss of precision.
 
Method Summary
 java.lang.Float 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

FloatSerializer

public FloatSerializer()
Creates a FloatSerializer that allows uses 4 bytes to represent a float, with no loss of precision.


FloatSerializer

public FloatSerializer(float precision,
                       boolean optimizePositive)
Creates a FloatSerializer that allows uses 1-5 bytes to represent a float, with a loss of precision. The float is multiplied by the specified precision, then cast to an int and serialized with IntSerializer. IntSerializer uses 1-4 bytes from 0 to 268,435,455 with "optimize positive" and -134,217,728 to 134,217,727 without. If a float multiplied by the precision would fall outside these values, it will take 5 bytes to serialize and it may be better to use the other FloatSerializer constructor.

Method Detail

readObjectData

public java.lang.Float 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.