com.esotericsoftware.kryo.serialize
Class IntSerializer

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

public class IntSerializer
extends Serializer

Writes a 1-5 byte integer.

Author:
Nathan Sweet

Constructor Summary
IntSerializer()
           
IntSerializer(boolean optimizePositive)
           
 
Method Summary
static boolean canRead(java.nio.ByteBuffer buffer, boolean optimizePositive)
          Reads true if the buffer contains enough data to read an int that was written with put(ByteBuffer, int, boolean).
static int get(java.nio.ByteBuffer buffer, boolean optimizePositive)
          Reads an int from the buffer that was written with put(ByteBuffer, int, boolean).
static int length(int value, boolean optimizePositive)
          Reads true if the buffer contains enough data to read an int that was written with put(ByteBuffer, int, boolean).
static int put(java.nio.ByteBuffer buffer, int value, boolean optimizePositive)
          Writes the specified int to the buffer using 1 to 5 bytes, depending on the size of the number.
 java.lang.Integer 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

IntSerializer

public IntSerializer()

IntSerializer

public IntSerializer(boolean optimizePositive)
Parameters:
optimizePositive - Determines how many bytes are written to serialize various ranges of integers:
Bytes true false
1 0 <= value <= 127 -64 <= value <= 63
2 128 <= value <= 16383 -8192 <= value <= 8191
3 16384 <= value <= 2097151 -1048576 <= value <= 1048575
4 2097152 <= value <= 268435455 -134217728 <= value <= 134217727
5 value < 0 || value > 268435455 value < -134217728 || value > 134217727
Method Detail

readObjectData

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

put

public static int put(java.nio.ByteBuffer buffer,
                      int value,
                      boolean optimizePositive)
Writes the specified int to the buffer using 1 to 5 bytes, depending on the size of the number.

Parameters:
optimizePositive - See IntSerializer(boolean).
Returns:
the number of bytes written.

get

public static int get(java.nio.ByteBuffer buffer,
                      boolean optimizePositive)
Reads an int from the buffer that was written with put(ByteBuffer, int, boolean).


canRead

public static boolean canRead(java.nio.ByteBuffer buffer,
                              boolean optimizePositive)
Reads true if the buffer contains enough data to read an int that was written with put(ByteBuffer, int, boolean).


length

public static int length(int value,
                         boolean optimizePositive)
Reads true if the buffer contains enough data to read an int that was written with put(ByteBuffer, int, boolean).



Copyright © 2011. All Rights Reserved.