godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.87k stars 3.16k forks source link

Outdated or incorrect binary serialization API #4945

Open Aurora2500 opened 3 years ago

Aurora2500 commented 3 years ago

Your Godot version: 3.3 Stable

Issue description: In the documentation, it is stated that

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.

Because of this, I'd expect 4 bytes being taken up as a header, indicating which type it is and some other flag information. And then following that I'd get the data for the type, if any.

So when doing store_var(null), I'd expect there to be 4 bytes all filled with 0:

00000000 00000000 00000000 00000000

Or when doing store_var(42), I'd expect to get a file with the following binary data:

00000010 00000000 00000000 00000000
00101010 00000000 00000000 00000000

But instead, there seems to be an extra 4 bytes in front of the header for each data packet. When I store null, I get:

00000100 00000000 00000000 00000000
00000000 00000000 00000000 00000000

Or when I store 42:

00001000 00000000 00000000 00000000
00000010 00000000 00000000 00000000
00101010 00000000 00000000 00000000

The documentation does not indicate what these extra bytes mean, or mention that they should exist at all.

URL to the documentation page: https://docs.godotengine.org/en/stable/tutorials/misc/binary_serialization_api.html

Calinou commented 3 years ago

See also https://github.com/godotengine/godot-docs/issues/4887 and https://github.com/godotengine/godot-docs/pull/4893.

BLNJ commented 7 months ago

This problem is much bigger, there are actually 38 different packet types which you only discover when directly looking at the source code (for instance Vector2I, Rect2I, Vector3I and so on) or when you implement the types by following the documentation but notice that everything after vector2 (ID 5) is off. It is also said that all packets have a 4 byte header, but nowhere is mentioned that packets have a size in the header, while packets inside others (like in dictionary) dont have that size component in the header.

Im currently slowly working my way through all possible types. Generating the files by the engine, looking at them in a hex editor and incorporating that into my own library. Im going to update the documentation when Im done