Purpose
The purpose of this document to describe serialization of a various data type which Geode understands.
Data Types
Geode supports all the Java primitive data types. Custom Java object can be serialized through Geode PdxSerializable and DataSerializable interfaces. The Application can attach its own data serializer through Geode DataSerializer and Geode PdxSerializer interface. Using Geode, the application can also serialize arrays of primitive java types and java collections. It also understands the Java Serializable.
In Geode, every supported data type is associated with type Id. Type Id is represented by one byte. To serialize any date type Geode first writes the typeId. Then it writes the length of serialized byte for variable types. For fixed data types it just write those bytes in the Big Indian byte order.
Data Type | Type Id | Value | Serialized Bytes | Description | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Null | 41 = 0x29 | null |
| |||||||
Boolean | 53 = 0x35 | true |
| |||||||
Character | 54 = 0x36 | 'a' |
| |||||||
Byte | 55 = 0x37 | 1 |
| |||||||
Short | 56 = 0x38 | 1000 |
| |||||||
Integer | 57 = 0x39 | 1000 |
| |||||||
Long | 58 = 0x3A | 1000 |
| |||||||
Float | 59 = 0x3B | 1000f |
| |||||||
Double | 60 = 0x3C | 1000d |
| |||||||
String | 87 = 0x57 | "hello" |
| |||||||
UTF_STRING | 42 = 0x2A | |||||||||
HUGE_STRING | 88 = 0x58 | |||||||||
HUGE_UTF_STRING | 89 = 0x59 | |||||||||
byte[] | 46 = 0x2E |
| ||||||||
short[] | 47 = 0x2F |
| ||||||||
int[] | 48 = 0x30 |
| ||||||||
long[] | 49 = 0x31 |
| ||||||||
float[] | 50 = 0x32 |
| ||||||||
double[] | 51 = 0x33 |
| ||||||||
string[] | 64 = 0x40 |
| ||||||||
Map | 67 = 0x43 |
| ||||||||
Set | 66 = 0x42 |
| ||||||||
List | ||||||||||
ArrayList | ||||||||||
PDX_SERIALIZATION | ||||||||||
PDX_SERIALIZER | ||||||||||
DATA_SERIALIZATION | ||||||||||
USER_SERIALIZATION |
Null (41 = 0x29): Null object will be represented by single byte.
0x41 (typeid) |
Boolean (53 = 0x35) : Boolean object will be represented by typeId and value byte. Following demonstrate the serialize representation boolean value true.
0x52 (typeid) | 0x01 |
Character (54 = 0x36) : Character object will be represented by typeId and two bytes. Following demonstrate the serialize representation of character ‘a’.
0x54 (typeid) | 0x00 | 0x61 |
Byte (55 = 0x37) : Byte object will represted by typeId and value byte. Following demonstrate the serialize representation of 1’.
0x55 (typeid) | 0x01 |
Short (56 = 0x38): Following will be serialized representation of 1000(0x3E8)
0x38 (typeid) | 0x03 | 0xE8 |
Integer (57 = 0x39): Following will be serialized representation of 1000(0x3E8)
0x39 | 0x00 | 0x00 | 0x03 | 0xE8 |
Long (58 = 0x3A): Following will be serialized representation of 1000(0x3E8)
0x58 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x03 | 0xE8 |
Float (59 = 0x3B)
float s = 1000f;
[59, 68, 122, 0, 0]
0x3B (typeid) | 0x44 | 0x7A | 0x00 | 0x00 |
Double (60 = 0x3C)
double s = 1000d;
[60, 64, -113, 64, 0, 0, 0, 0, 0]
0x3C | 0x40 | 0xF1 | 0x40 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 |
String (42 = 0x2A)
STRING (87 = 0x57) ASCII; Length is 2 bytes
String s = "hello";
[87, 0, 5, 104, 101, 108, 108, 111]
0x57 | 0x00(len) | 0x05(len) | 0x68 | 0x65 | 0x40 | 0x40 | 0x6F |
HUGE_STRING (88 = 0x58) ASCII Length is 4 bytes
UTF_STRING (42 = 0x2A) UTF; Length is 2 bytes
HUGE_UTF_STRING (89 = 0x59) UTF; Length is 4 bytes
Array (52 = 0x34) ??
BYTE_ARRAY (46 = 0x2E)
byte[] {1,2};
0x2E | 0x02(len) | 0x01 | 0x02 |
SHORT_ARRAY (47 = 0x2F)
short[] {1,2};
0x2F | 0x02(len) | 0x00 | 0x01 | 0x00 | 0x02 |
INTEGER_ARRAY (48 = 0x30)
int[] {1,2};
0x30 | 0x02(len) | 0x00 | 0x00 | 0x00 | 0x01 | 0x00 | 0x00 | 0x00 | 0x02 |
LONG_ARRAY (49 = 0x31)
long[] {1};
0x31 | 0x01(len) | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x01 |
FLOAT_ARRAY (50 = 0x32)
float[] {2.0f};
0x32 | 0x01(len) | 0x40 | 0x00 | 0x00 | 0x00 |
DOUBLE_ARRAY (51 = 0x33)
double[] {2.0d}
0x33 | 0x01(len) | 0x40 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 |
STRING_ARRAY (64 = 0x40)
String[] s = new String[]{"hello", "world"};
[64, 2, 87, 0, 5, 104, 101, 108, 108, 111, 87, 0, 5, 119, 111, 114, 108, 100]
Map (67 = 0x43)
Map s = new HashMap<>();
s.put("hello", "world");
[67, 1, 87, 0, 5, 104, 101, 108, 108, 111, 87, 0, 5, 119, 111, 114, 108, 100]
Set (66 = 0x42)
Set s = new HashSet();
s.add("hello");
s.add("world");
[66, 2, 87, 0, 5, 119, 111, 114, 108, 100, 87, 0, 5, 104, 101, 108, 108, 111]
List
ArrayList
JSON_STRING ??
JSON_BYTE_ARRAY ??
PDX_SERIALIZATION (93 = 0x5D)
DATA_SERIALIZATION (37 = 0x25)
USER_SERIALIZATION (40 = 0x28)