public class EmptyPacker extends java.lang.Object implements DataPacker<java.lang.Object,java.lang.Object>
Constructor and Description |
---|
EmptyPacker() |
Modifier and Type | Method and Description |
---|---|
int |
determineLength(java.lang.Object data,
PackerStore store)
Pack the data and return the size of the data in bytes once packed.
|
static EmptyPacker |
getInstance() |
boolean |
isHeaderRequired()
Indicates whether length should be packed before the actual key
|
byte[] |
packToByteArray(java.lang.Object data) |
java.nio.ByteBuffer |
packToByteBuffer(java.nio.ByteBuffer byteBuffer,
int offset,
java.lang.Object data)
This method puts a value to the
ByteBuffer , starting from specified
index of the buffer. |
java.nio.ByteBuffer |
packToByteBuffer(java.nio.ByteBuffer byteBuffer,
java.lang.Object data)
This method puts a value to the
ByteBuffer . |
int |
readDataFromBuffer(ObjectBuilder<java.lang.Object,java.lang.Object> objectBuilder,
int currentBufferLocation,
DataBuffer dataBuffer)
Read the buffer and build the actual object.
|
java.lang.Object |
unpackFromBuffer(java.nio.ByteBuffer byteBuffer,
int byteLength)
This method will extract a value from buffer starting from buffer's current position.
|
java.lang.Object |
unpackFromBuffer(java.nio.ByteBuffer byteBuffer,
int bufferOffset,
int byteLength)
This method will extract a value from buffer starting from the position specified.
|
java.lang.Object |
wrapperForByteLength(int byteLength)
Returns an empty wrapper to hold byteLength amount of type T
|
void |
writeDataToBuffer(java.lang.Object data,
PackerStore packerStore,
int alreadyCopied,
int leftToCopy,
int spaceLeft,
java.nio.ByteBuffer targetBuffer)
Transfer the data to the buffer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
unpackFromByteArray
public static EmptyPacker getInstance()
public int determineLength(java.lang.Object data, PackerStore store)
DataPacker
DataPacker.writeDataToBuffer(D, edu.iu.dsc.tws.api.comms.packing.PackerStore, int, int, int, java.nio.ByteBuffer)
, you may just
return the byte size of data from this method.determineLength
in interface DataPacker<java.lang.Object,java.lang.Object>
data
- the data (can be Integer, Object etc)store
- A store to temporary store the serialized data,
if you had to serialize data to determine length.public void writeDataToBuffer(java.lang.Object data, PackerStore packerStore, int alreadyCopied, int leftToCopy, int spaceLeft, java.nio.ByteBuffer targetBuffer)
DataPacker
DataPacker.determineLength(Object, PackerStore)
,
you may transfer data from state
* to targetBuffer. If not, you may directly transfer data to the targetBuffer.writeDataToBuffer
in interface DataPacker<java.lang.Object,java.lang.Object>
public int readDataFromBuffer(ObjectBuilder<java.lang.Object,java.lang.Object> objectBuilder, int currentBufferLocation, DataBuffer dataBuffer)
DataPacker
ObjectBuilder.setFinalObject(Object)
to set and mark the end of the current objectreadDataFromBuffer
in interface DataPacker<java.lang.Object,java.lang.Object>
public byte[] packToByteArray(java.lang.Object data)
packToByteArray
in interface DataPacker<java.lang.Object,java.lang.Object>
public java.nio.ByteBuffer packToByteBuffer(java.nio.ByteBuffer byteBuffer, java.lang.Object data)
DataPacker
ByteBuffer
.
The position of byteBuffer should be updated.packToByteBuffer
in interface DataPacker<java.lang.Object,java.lang.Object>
public java.nio.ByteBuffer packToByteBuffer(java.nio.ByteBuffer byteBuffer, int offset, java.lang.Object data)
DataPacker
ByteBuffer
, starting from specified
index of the buffer.
The position of the buffer shouldn't be affectedpackToByteBuffer
in interface DataPacker<java.lang.Object,java.lang.Object>
public java.lang.Object wrapperForByteLength(int byteLength)
DataPacker
wrapperForByteLength
in interface DataPacker<java.lang.Object,java.lang.Object>
public boolean isHeaderRequired()
DataPacker
isHeaderRequired
in interface DataPacker<java.lang.Object,java.lang.Object>
public java.lang.Object unpackFromBuffer(java.nio.ByteBuffer byteBuffer, int bufferOffset, int byteLength)
DataPacker
unpackFromBuffer
in interface DataPacker<java.lang.Object,java.lang.Object>
byteBuffer
- ByteBuffer
instancebufferOffset
- position to start reading from bufferbyteLength
- amount of data to readpublic java.lang.Object unpackFromBuffer(java.nio.ByteBuffer byteBuffer, int byteLength)
DataPacker
unpackFromBuffer
in interface DataPacker<java.lang.Object,java.lang.Object>