Binary serialization API
Introduction
get_var and store_var of File as well as the packet APIs for PacketPeer. This format is not used for binary scenes and resources.
Packet specification
The packet is designed to be always padded to 4 bytes. All values are little-endian-encoded. All packets have a 4-byte header representing an integer, specifying the type of data. The lowest value two bytes are used to determine the type, while the highest value two bytes contain flags:
base_type = val & 0xFFFF;flags = val >> 16;
(offset - 4) * 2 + 4. The “float” type itself always uses double precision.
0: null
bool
int
If no flags are set (flags == 0), the integer is sent as a 32 bit integer:
ENCODE_FLAG_64 is set (flags & 1 == 1), the integer is sent as a 64-bit integer:
float
If no flags are set (flags == 0), the float is sent as a 32 bit single precision:
ENCODE_FLAG_64 is set (flags & 1 == 1), the float is sent as a 64-bit double precision number:
String
This field is padded to 4 bytes.
Vector2
Rect2
Vector3
Transform2D
Plane
Quat
AABB
Basis
Transform
Color
NodePath
For old format:
Padded to 4 bytes.
For new format:
For each Name and Sub-Name Every name string is padded to 4 bytes.
RID (unsupported)
Object (unsupported)
Dictionary
Then what follows is, for amount of “elements”, pairs of key and value, one after the other, using this same format.
Array
Then what follows is, for amount of “elements”, values one after the other, using this same format.
PoolByteArray
The array data is padded to 4 bytes.
PoolIntArray
PoolRealArray
PoolStringArray
For each String: Every string is padded to 4 bytes.
