-
Notifications
You must be signed in to change notification settings - Fork 245
MinBin
With 2.x fast serialization adds a second layer to provide the foundation to create structured binary streams.
=============================
Serialization Implementation
=============================
Codec
=============================
One of the drawbacks of serialization is interoperability. However I'd like to be able to serialize complex object graphs into e.g. a javascript client. Ofc there is stuff like JSon/XML however IMO its kind of a hassle as even with advanced JSon binding libraries, a lot of manual work is required. With inter-language serialization, a client could directly take an object graph from the server and use it without any parsing or translation stuff. As alternatives like msgpack/bson/google protocol buffers are inconvenient in use (at least from a java perspective) and/or lack features like cycle detection and reference ressolvement, I defined MinBin, a kind of binary JSon (contains metainformation such as field names), which also supports and resolves references inside the serialized object graph. Since it has to accessible from javascript, float/double is represented as string, so floating point numbers are pretty slow compared to "native" serialization. The only source of information should be class definitions to avoid the necessity to explicitely define .iml or similar message description files.
This also opens up the possibility to create distributed actor networks with actors written in different languages.
A MinBin stream consists of primitives, and tags which signal start+end of more complex composed data structures.
Primitives are:
- signed INT_8, INT_16, INT_32, INT_64
- unsigned INT_16
- arrays of the types above (so sequences of int's can be transmitted with low overhead)
- tags
a minbin stream consists of primitives and tags.
the following markers signal the type of the following data in a stream:
public final static byte INT_8 = 0b0001; // 1 (17 = array)
public final static byte INT_16 = 0b0010; // 2 (18 ..)
public final static byte INT_32 = 0b0011; // 3 (19 ..)
public final static byte INT_64 = 0b0100; // 4 (20 ..)
public final static byte TAG = 0b0101; // 5, top 5 bits contains tag id
public final static byte END = 0b0110; // 6, end marker
public final static byte RESERV = 0b0111; // escape for future extension
public final static byte UNSIGN_MASK = 0b01000; // int only
public final static byte ARRAY_MASK = 0b10000;// int only, next item expected to be length
public final static byte CHAR = UNSIGN_MASK|INT_16;
the following tags are built in:
public static final byte NULL = 7;
public static final byte STRING = 0;
public static final byte OBJECT = 5;
public static final byte SEQUENCE = 6;
public static final byte DOUBLE = 2;
public static final byte DOUBLE_ARR = 3;
public static final byte FLOAT = 1;
public static final byte FLOAT_ARR = 4;
public static final byte BOOL = 8;
public static final byte HANDLE = 9;