public class BinarySerialiser extends Object
There are two default backing buffer implementations (FastByteBuffer and ByteBuffer),
but can be extended/replaced with any other buffer is also possible provided it implements the IoBuffer interface.
The default serialisable data types are defined in DataType and include definitions for
OTHER sub-type.
N.B. Multi-dimensional arrays are handled through one-dimensional striding arrays with the additional
infos on number of dimensions and size for each individual dimension.
raw-byte level protocol: above data items are stored as follows:
* header info: [ start marker ] +
[ "#file producer : ": String ] +
[ clear text serialiser name: String ] + // e.g. "de.gsi.dataset.serializer.spi.BinarySerialiser"
[ "\n":String ] +
[ 1 byte - major protocol version ] +
[ 1 byte - minor protocol version ] +
[ 1 byte - micro protocol version ] // micro: non API-changing bug fixes in implementation
* start marker: [ String - field name ][ 1 byte - uniqueType (0x00) ]
* String: [ 4 bytes (int) - length (including termination) ][ n bytes based on latin1 encoding ]
* field header: [ String - field name ] + [ 1 byte - uniqueType ]
* primitives: [ field header ] + [ 1-8 bytes depending on DataType ]
* prim. arrays: [ array header ] + [ ]=1-8 bytes x N_i or more - array data depending on variable DataType ]
* boxed arrays: as above but each element cast to corresponding primitive type
* array header: [ field header ] +
[4 bytes - number of bytes to skip until data end (-1: uninitialised) ] +
[4 bytes - number of dimensions N_d ] +
[4 bytes x N_d - vector sizes for each dimension N_i ]
* Collection[E]:
* List[]:
* Queue[E]:
* Set[E]: [ array header (uniqueType= one of the Collection type IDs) ] +
[ 1 byte - uniqueType of E ] + [ n bytes - array of E cast to primitive type and/or string ]
* Map[K,V]: [ array header (uniqueType=0xCB) ] + [ 1 byte - uniqueType of K ] + [ 1 byte - uniqueType of V ] +
[ n bytes - array of K cast to primitive type and/or string ] +
[ n bytes - array of V cast to primitive type and/or string ]
* OTHER [ field header - uniqueByte = 0xFD ] +
[ 4 bytes - number of bytes to skip until data end (-1: uninitialised) ] +
[ 1 byte - uniqueType -- custom definition ]
[ n bytes - custom serialisation definition ]
* end marker: [ String - field name ][ 1 byte - uniqueType (0xFE) ]
* nesting or sub-structures (ie. POJOs with sub-classes) can be achieved via:
[ start marker - field name == nesting context1 ]
[ start marker - field name == nesting context2 ]
...
[ end marker - field name == nesting context2 (optional name) ]
[ end marker - field name == nesting context1 (optional name) ]
with
T: being a generic list parameter outlined in DataType
K: being a generic key parameter outlined in DataType
V: being a generic value parameter outlined in DataType
| Modifier and Type | Class and Description |
|---|---|
class |
BinarySerialiser.HeaderInfo |
| Modifier and Type | Field and Description |
|---|---|
protected static BinarySerialiser |
SELF |
protected static BinarySerialiser.HeaderInfo |
THIS_HEADER |
static byte |
VERSION_MAJOR |
static byte |
VERSION_MICRO |
static byte |
VERSION_MINOR |
| Modifier | Constructor and Description |
|---|---|
protected |
BinarySerialiser() |
| Modifier and Type | Method and Description |
|---|---|
static void |
adjustDataByteSizeBlock(IoBuffer buffer,
long sizeMarkerStart) |
static BinarySerialiser.HeaderInfo |
checkHeaderInfo(IoBuffer readBuffer) |
static int[] |
getArrayDimensions(IoBuffer readBuffer) |
static boolean |
getBoolean(IoBuffer readBuffer) |
static boolean[] |
getBooleanArray(IoBuffer readBuffer) |
static int |
getBufferIncrements() |
static byte |
getByte(IoBuffer readBuffer) |
static byte[] |
getByteArray(IoBuffer readBuffer) |
static char |
getCharacter(IoBuffer readBuffer) |
static char[] |
getCharArray(IoBuffer readBuffer) |
static <E> Collection<E> |
getCollection(IoBuffer readBuffer,
Collection<E> collection) |
static double |
getDouble(IoBuffer readBuffer) |
static double[] |
getDoubleArray(IoBuffer readBuffer) |
static double[] |
getDoubleArray(IoBuffer readBuffer,
DataType dataType) |
static <E extends Enum<E>> |
getEnum(IoBuffer readBuffer,
Enum<E> enumeration) |
static String |
getEnumTypeList(IoBuffer readBuffer) |
static FieldHeader |
getFieldHeader(IoBuffer readBuffer) |
static float |
getFloat(IoBuffer readBuffer) |
static float[] |
getFloatArray(IoBuffer readBuffer) |
protected static Object[] |
getGenericArrayAsBoxedPrimitive(IoBuffer readBuffer,
DataType dataType) |
static int[] |
getIntArray(IoBuffer readBuffer) |
static int |
getInteger(IoBuffer readBuffer) |
static <E> List<E> |
getList(IoBuffer readBuffer,
List<E> collection) |
static long |
getLong(IoBuffer readBuffer) |
static long[] |
getLongArray(IoBuffer readBuffer) |
static <K,V> Map<K,V> |
getMap(IoBuffer readBuffer,
Map<K,V> map) |
protected static int |
getNumberOfElements(int[] dimensions) |
static <E> Queue<E> |
getQueue(IoBuffer readBuffer,
Queue<E> collection) |
static <E> Set<E> |
getSet(IoBuffer readBuffer,
Set<E> collection) |
static short |
getShort(IoBuffer readBuffer) |
static short[] |
getShortArray(IoBuffer readBuffer) |
static String |
getString(IoBuffer readBuffer) |
static String[] |
getStringArray(IoBuffer readBuffer) |
static FieldHeader |
parseIoStream(IoBuffer buffer) |
protected static void |
parseIoStream(IoBuffer buffer,
FieldHeader fieldRoot,
int recursionDepth) |
static void |
put(IoBuffer buffer,
String fieldName,
boolean value) |
static void |
put(IoBuffer buffer,
String fieldName,
boolean[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
boolean[] arrayValue,
int[] dims) |
static void |
put(IoBuffer buffer,
String fieldName,
byte value) |
static void |
put(IoBuffer buffer,
String fieldName,
byte[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
byte[] arrayValue,
int[] dims) |
static void |
put(IoBuffer buffer,
String fieldName,
char value) |
static void |
put(IoBuffer buffer,
String fieldName,
char[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
char[] arrayValue,
int[] dims) |
static <E> void |
put(IoBuffer buffer,
String fieldName,
Collection<E> collection) |
static void |
put(IoBuffer buffer,
String fieldName,
double value) |
static void |
put(IoBuffer buffer,
String fieldName,
double[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
double[] arrayValue,
int[] dims) |
static void |
put(IoBuffer buffer,
String fieldName,
Enum<?> enumeration) |
static void |
put(IoBuffer buffer,
String fieldName,
float value) |
static void |
put(IoBuffer buffer,
String fieldName,
float[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
float[] arrayValue,
int[] dims) |
static void |
put(IoBuffer buffer,
String fieldName,
int value) |
static void |
put(IoBuffer buffer,
String fieldName,
int[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
int[] arrayValue,
int[] dims) |
static void |
put(IoBuffer buffer,
String fieldName,
long value) |
static void |
put(IoBuffer buffer,
String fieldName,
long[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
long[] arrayValue,
int[] dims) |
static <K,V> void |
put(IoBuffer buffer,
String fieldName,
Map<K,V> map) |
static void |
put(IoBuffer buffer,
String fieldName,
short value) |
static void |
put(IoBuffer buffer,
String fieldName,
short[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
short[] arrayValue,
int[] dims) |
static void |
put(IoBuffer buffer,
String fieldName,
String value) |
static void |
put(IoBuffer buffer,
String fieldName,
String[] arrayValue) |
static void |
put(IoBuffer buffer,
String fieldName,
String[] arrayValue,
int[] dims) |
static long |
putArrayHeader(IoBuffer buffer,
String fieldName,
DataType dataType,
int[] dims,
int nElements) |
static void |
putEndMarker(IoBuffer buffer,
String markerName) |
static void |
putFieldHeader(IoBuffer buffer,
String fieldName,
DataType dataType) |
static void |
putFieldHeader(IoBuffer buffer,
String fieldName,
DataType dataType,
int additionalSize) |
static void |
putGenericArrayAsPrimitive(IoBuffer buffer,
DataType dataType,
Object[] data,
int nToCopy) |
static void |
putHeaderInfo(IoBuffer buffer)
Adds header and version information
|
static void |
putStartMarker(IoBuffer buffer,
String markerName) |
static void |
setBufferIncrements(int bufferIncrements) |
protected static void |
swallowRest(IoBuffer readBuffer,
FieldHeader fieldHeader) |
protected static double[] |
toDoubles(boolean[] input)
Deprecated.
|
protected static double[] |
toDoubles(byte[] input)
Deprecated.
|
protected static double[] |
toDoubles(char[] input)
Deprecated.
|
protected static double[] |
toDoubles(float[] input)
Deprecated.
|
protected static double[] |
toDoubles(int[] input)
Deprecated.
|
protected static double[] |
toDoubles(long[] input)
Deprecated.
|
protected static double[] |
toDoubles(short[] input)
Deprecated.
|
protected static double[] |
toDoubles(String[] input)
Deprecated.
|
public static final byte VERSION_MAJOR
public static final byte VERSION_MINOR
public static final byte VERSION_MICRO
protected static final BinarySerialiser SELF
protected static final BinarySerialiser.HeaderInfo THIS_HEADER
public static void adjustDataByteSizeBlock(IoBuffer buffer, long sizeMarkerStart)
public static BinarySerialiser.HeaderInfo checkHeaderInfo(IoBuffer readBuffer)
public static int[] getArrayDimensions(IoBuffer readBuffer)
public static boolean getBoolean(IoBuffer readBuffer)
public static boolean[] getBooleanArray(IoBuffer readBuffer)
public static int getBufferIncrements()
public static byte getByte(IoBuffer readBuffer)
public static byte[] getByteArray(IoBuffer readBuffer)
public static char getCharacter(IoBuffer readBuffer)
public static char[] getCharArray(IoBuffer readBuffer)
public static <E> Collection<E> getCollection(IoBuffer readBuffer, Collection<E> collection)
public static double getDouble(IoBuffer readBuffer)
public static double[] getDoubleArray(IoBuffer readBuffer)
public static FieldHeader getFieldHeader(IoBuffer readBuffer)
public static float getFloat(IoBuffer readBuffer)
public static float[] getFloatArray(IoBuffer readBuffer)
protected static Object[] getGenericArrayAsBoxedPrimitive(IoBuffer readBuffer, DataType dataType)
public static int[] getIntArray(IoBuffer readBuffer)
public static int getInteger(IoBuffer readBuffer)
public static long getLong(IoBuffer readBuffer)
public static long[] getLongArray(IoBuffer readBuffer)
protected static int getNumberOfElements(int[] dimensions)
public static short getShort(IoBuffer readBuffer)
public static short[] getShortArray(IoBuffer readBuffer)
public static FieldHeader parseIoStream(IoBuffer buffer)
protected static void parseIoStream(IoBuffer buffer, FieldHeader fieldRoot, int recursionDepth)
public static <E> void put(IoBuffer buffer, String fieldName, Collection<E> collection)
public static long putArrayHeader(IoBuffer buffer, String fieldName, DataType dataType, int[] dims, int nElements)
public static void putFieldHeader(IoBuffer buffer, String fieldName, DataType dataType)
public static void putFieldHeader(IoBuffer buffer, String fieldName, DataType dataType, int additionalSize)
public static void putGenericArrayAsPrimitive(IoBuffer buffer, DataType dataType, Object[] data, int nToCopy)
public static void putHeaderInfo(IoBuffer buffer)
buffer - to use for serialisationpublic static void setBufferIncrements(int bufferIncrements)
protected static void swallowRest(IoBuffer readBuffer, FieldHeader fieldHeader)
@Deprecated protected static double[] toDoubles(boolean[] input)
@Deprecated protected static double[] toDoubles(byte[] input)
@Deprecated protected static double[] toDoubles(char[] input)
@Deprecated protected static double[] toDoubles(float[] input)
@Deprecated protected static double[] toDoubles(int[] input)
@Deprecated protected static double[] toDoubles(long[] input)
@Deprecated protected static double[] toDoubles(short[] input)
@Deprecated protected static double[] toDoubles(String[] input)
Copyright © 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH. All rights reserved.