public interface PrimitivePacker<T> extends DataPacker<T,T>
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
addToBuffer(java.nio.ByteBuffer byteBuffer,
int index,
T data)
This method should insert to byteBuffer's index.
|
java.nio.ByteBuffer |
addToBuffer(java.nio.ByteBuffer byteBuffer,
T data)
This method should put data to byteBuffer and update the position of buffer
|
default int |
determineLength(T data,
PackerStore store)
Pack the data and return the size of the data in bytes once packed.
|
T |
getFromBuffer(java.nio.ByteBuffer byteBuffer)
Read a value from buffer.
|
T |
getFromBuffer(java.nio.ByteBuffer byteBuffer,
int offset)
Read a value from offset.
|
MessageType<T,T> |
getMessageType() |
default boolean |
isHeaderRequired()
Indicates whether length should be packed before the actual key
|
default byte[] |
packToByteArray(T data) |
default java.nio.ByteBuffer |
packToByteBuffer(java.nio.ByteBuffer byteBuffer,
int index,
T data)
This method puts a value to the
ByteBuffer , starting from specified
index of the buffer. |
default java.nio.ByteBuffer |
packToByteBuffer(java.nio.ByteBuffer byteBuffer,
T data)
This method puts a value to the
ByteBuffer . |
default int |
readDataFromBuffer(ObjectBuilder objectBuilder,
int currentBufferLocation,
DataBuffer dataBuffer)
Read the buffer and build the actual object.
|
default T |
unpackFromBuffer(java.nio.ByteBuffer byteBuffer,
int byteLength)
This method will extract a value from buffer starting from buffer's current position.
|
default T |
unpackFromBuffer(java.nio.ByteBuffer byteBuffer,
int bufferOffset,
int byteLength)
This method will extract a value from buffer starting from the position specified.
|
default T |
wrapperForByteLength(int byteLength)
Returns an empty wrapper to hold byteLength amount of type T
|
default void |
writeDataToBuffer(T data,
PackerStore packerStore,
int alreadyCopied,
int leftToCopy,
int spaceLeft,
java.nio.ByteBuffer targetBuffer)
Transfer the data to the buffer.
|
unpackFromByteArray
MessageType<T,T> getMessageType()
java.nio.ByteBuffer addToBuffer(java.nio.ByteBuffer byteBuffer, T data)
java.nio.ByteBuffer addToBuffer(java.nio.ByteBuffer byteBuffer, int index, T data)
T getFromBuffer(java.nio.ByteBuffer byteBuffer, int offset)
T getFromBuffer(java.nio.ByteBuffer byteBuffer)
default void writeDataToBuffer(T 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<T,T>
default int determineLength(T 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<T,T>
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.default int readDataFromBuffer(ObjectBuilder objectBuilder, int currentBufferLocation, DataBuffer dataBuffer)
DataPacker
ObjectBuilder.setFinalObject(Object)
to set and mark the end of the current objectreadDataFromBuffer
in interface DataPacker<T,T>
default byte[] packToByteArray(T data)
packToByteArray
in interface DataPacker<T,T>
default java.nio.ByteBuffer packToByteBuffer(java.nio.ByteBuffer byteBuffer, T data)
DataPacker
ByteBuffer
.
The position of byteBuffer should be updated.packToByteBuffer
in interface DataPacker<T,T>
default java.nio.ByteBuffer packToByteBuffer(java.nio.ByteBuffer byteBuffer, int index, T data)
DataPacker
ByteBuffer
, starting from specified
index of the buffer.
The position of the buffer shouldn't be affectedpackToByteBuffer
in interface DataPacker<T,T>
default T wrapperForByteLength(int byteLength)
DataPacker
wrapperForByteLength
in interface DataPacker<T,T>
default boolean isHeaderRequired()
DataPacker
isHeaderRequired
in interface DataPacker<T,T>
default T unpackFromBuffer(java.nio.ByteBuffer byteBuffer, int bufferOffset, int byteLength)
DataPacker
unpackFromBuffer
in interface DataPacker<T,T>
byteBuffer
- ByteBuffer
instancebufferOffset
- position to start reading from bufferbyteLength
- amount of data to readdefault T unpackFromBuffer(java.nio.ByteBuffer byteBuffer, int byteLength)
DataPacker
unpackFromBuffer
in interface DataPacker<T,T>