Table of Contents |
---|
Purpose
The purpose of this document to describe the native serialization of a various data type types which Geode understandsunderstand.
Data Types
Geode supports all the Java primitive data types and Java arrays and collections.. Custom Java object objects can be serialized through Geode PdxSerializable and DataSerializable interfaces. The Application can attach its own data serializer through Geode the Geode DataSerializer
and Geode and PdxSerializer
interface. Using Geode, the application can also serialize arrays of primitive java types and java collections. It also understands the Java Serializable interfaces. Objects implementing java.io.Serializable
can be serialized with Geode as well.
In Geode, every supported data type is associated with type Id. Type Id is represented by one bytea single-byte type Id. To serialize any date type Geode first writes the typeId. Then For variable sized objects, it then writes the length of serialized byte for variable typesthe serialized object followed by the serialized bytes. For fixed data types it just write those writes the serialized bytes in the Big Indian Endian byte order.
For native serialization, strings are serialized using the Java Modified UTF-8 Format.
Data Type | Geode Region Key Types | Type Id | Value | Serialized Bytes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Null | 41 = 0x29 | null |
| ||||||||||||||||||||||||||
Boolean | YES | 53 = 0x35 | true |
| |||||||||||||||||||||||||
Character | YES | 54 = 0x36 | 'a' |
| |||||||||||||||||||||||||
Byte | YES | 55 = 0x37 | 1 |
| |||||||||||||||||||||||||
Short | YES | 56 = 0x38 | 1000 |
| |||||||||||||||||||||||||
Integer | YES | 57 = 0x39 | 1000 |
| |||||||||||||||||||||||||
Long | YES | 58 = 0x3A | 1000 |
| |||||||||||||||||||||||||
Float | YES | 59 = 0x3B | 1000f |
| |||||||||||||||||||||||||
Double | YES | 60 = 0x3C | 1000d |
| |||||||||||||||||||||||||
ASCII_STRING | YESString | 87 = 0x57 | "hello" |
| This represents ASCII string with maximum length 0xFFFF. Code snippet to serialize and deserialize the string. | ||||||||||||||||||||||||
UTF_STRING | YES | 42 = 0x2A | This represents UTF string with maximum length 0xFFFF. Code snippet to serialize and deserialize the string. | ||||||||||||||||||||||||||
HUGE_ASCII_STRING | YES | 88 = 0x58 | This represents ASCII string with length greater than 0xFFFF. Code snippet to serialize and deserialize the string. | ||||||||||||||||||||||||||
HUGE_UTF_STRING | YES | 89 = 0x59 | This represents UTF string with length greater than 0xFFFF. Code snippet to serialize and deserialize the string. | ||||||||||||||||||||||||||
byte[] | This we plan to support | 46 = 0x2E | byte[] {1,2} |
| |||||||||||||||||||||||||
short[] | 47 = 0x2F | short[] {1,2} |
| ||||||||||||||||||||||||||
int[] | 48 = 0x30 | int[] {1,2} |
| ||||||||||||||||||||||||||
long[] | 49 = 0x31 | long[] {1} |
| ||||||||||||||||||||||||||
float[] | 50 = 0x32 | float[] {2.0f} |
| ||||||||||||||||||||||||||
double[] | 51 = 0x33 | double[] {2.0d} |
| ||||||||||||||||||||||||||
string[] | 64 = 0x40 | String[]{"hello", "world"} |
| Map | 67 = 0x43 |
| |||||||||||||||||||||||
Map | Set | 66 = 0x42 | 67 = 0x43 | Map s = new HashMap<>(); s.put("hello", "world") |
| List |
|
|
|
| ArrayList | ||||||||||||||||||
Set | |||||||||||||||||||||||||||||
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
66 = 0x42 | Set s = new HashSet(); s.add("hello"); s.add("world"); |
| |||||||||||
List | 10 = 0x0a | List s = new LinkedList(); |
| ||||||||||
ArrayList | 65=0x41 | List s = new ArrayList(); |
| ||||||||||
PDX_SERIALIZATION | 93=0x5D | Java Object can implement PdxSerializable interface to serialize data in pdx format | |||||||||||
PDX_SERIALIZER | The application can implement PdxSerializer interface and then install with geode cache to serialize data in pdx format. | ||||||||||||
DATA_SERIALIZATION | Java Object can implement DataSerializable interface to serialize data. | ||||||||||||
USER_SERIALIZATION | The application can implement DataSerializer interface and then install with geode cache to serialize data. | ||||||||||||
JAVA_SERIALIZATIOn | 44= 0x2C |
Calculate Collection/Array Size
Geode calculates the size of collection or Array in following way
Write Array Length function | Read Array Length Function | ||||
---|---|---|---|---|---|
|
|
Write And Read String
The String is serialized in following way. It distinguishes ASCII string and its size.
Write String | Read String | ||||
---|---|---|---|---|---|
|
|
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)
...