Binary serialization API

    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:

    Following this is the actual packet contents, which varies for each type of packet:

    1:

    OffsetLenTypeDescription
    44Integer0 for False, 1 for True

    2: int

    OffsetLenTypeDescription
    44IntegerSigned, 32-Bit Integer

    3: /real

    OffsetLenTypeDescription
    44FloatIEE 754 32-Bits Float

    4: String

    OffsetLenTypeDescription
    44IntegerString Length (in Bytes)
    8XBytesUTF-8 Encoded String

    This field is padded to 4 bytes.

    5:

    OffsetLenTypeDescription
    44FloatX Coordinate
    84FloatY Coordinate

    6: Rect2

    OffsetLenTypeDescription
    44FloatX Coordinate
    84FloatY Coordinate
    124FloatX Size
    164FloatY Size

    7:

    OffsetLenTypeDescription
    44FloatX Coordinate
    84FloatY Coordinate
    124FloatZ Coordinate

    8: Transform2D

    OffsetLenTypeDescription
    44Float[0][0]
    84Float[0][1]
    124Float[1][0]
    164Float[1][1]
    204Float[2][0]
    244Float[2][1]

    10:

    OffsetLenTypeDescription
    44FloatImaginary X
    84FloatImaginary Y
    124FloatImaginary Z
    164FloatReal W

    11: AABB

    OffsetLenTypeDescription
    44FloatX Coordinate
    84FloatY Coordinate
    124FloatZ Coordinate
    164FloatX Size
    204FloatY Size
    244FloatZ Size

    12:

    OffsetLenTypeDescription
    44Float[0][0]
    84Float[0][1]
    124Float[0][2]
    164Float[1][0]
    204Float[1][1]
    244Float[1][2]
    284Float[2][0]
    324Float[2][1]
    364Float[2][2]

    13: Transform

    OffsetLenTypeDescription
    44Float[0][0]
    84Float[0][1]
    124Float[0][2]
    164Float[1][0]
    204Float[1][1]
    244Float[1][2]
    284Float[2][0]
    324Float[2][1]
    364Float[2][2]
    404Float[3][0]
    444Float[3][1]
    484Float[3][2]

    14:

    OffsetLenTypeDescription
    44FloatRed (0..1)
    84FloatGreen (0..1)
    124FloatBlue (0..1)
    164FloatAlpha (0..1)

    15: NodePath

    OffsetLenTypeDescription
    44IntegerString Length, or New Format (val&0x80000000!=0 and NameCount=val&0x7FFFFFFF)

    For old format:

    OffsetLenTypeDescription
    8XBytesUTF-8 Encoded String

    For new format:

    OffsetLenTypeDescription
    44IntegerSub-Name Count
    84IntegerFlags (absolute: val&1 != 0 )

    For each Name and Sub-Name

    Every name string is padded to 4 bytes.

    16: (unsupported)

    17: Object (unsupported)

    OffsetLenTypeDescription
    44Integerval&0x7FFFFFFF = elements, val&0x80000000 = shared (bool)

    Then what follows is, for amount of “elements”, pairs of key and value, one after the other, using this same format.

    19:

    OffsetLenTypeDescription
    44Integerval&0x7FFFFFFF = elements, val&0x80000000 = shared (bool)

    20: PoolByteArray

    OffsetLenTypeDescription
    44IntegerArray Length (Bytes)
    8..8+length1ByteByte (0..255)

    The array data is padded to 4 bytes.

    21:

    OffsetLenTypeDescription
    44IntegerArray Length (Integers)
    8..8+length*44Integer32 Bits Signed Integer

    22: PoolRealArray

    OffsetLenTypeDescription
    44IntegerArray Length (Floats)
    8..8+length*44Integer32 Bits IEE 754 Float

    23:

    OffsetLenTypeDescription
    44IntegerArray Length (Strings)

    For each String:

    OffsetLenTypeDescription
    X+04IntegerString Length
    X+4XBytesUTF-8 Encoded String

    Every string is padded to 4 bytes.

    24: PoolVector2Array

    OffsetLenTypeDescription
    44IntegerArray Length
    8..8+length84FloatX Coordinate
    8..12+length84FloatY Coordinate

    25:

    26: PoolColorArray

    OffsetLenTypeDescription
    44IntegerArray Length
    8..8+length164FloatRed (0..1)
    8..12+length164FloatGreen (0..1)
    8..16+length164FloatBlue (0..1)
    8..20+length164FloatAlpha (0..1)