Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
二进制序列化 API¶
前言¶
Godot has a serialization API based on Variant. It's used for
converting data types to an array of bytes efficiently. This API is exposed
via the global bytes_to_var()
and var_to_bytes() functions,
but it is also used in the get_var
and store_var
methods of
FileAccess as well as the packet APIs for PacketPeer.
This format is not used for binary scenes and resources.
完整对象 vs 对象实例 ID¶
如果序列化变量时使用了 full_objects = true
,则该变量中所包含的 Object 都会进行序列化、包含在结果中。这个过程是递归的。
如果 full_objects = false
,则只会对该变量中所包含的 Object 的实例 ID 进行序列化。
数据包规格¶
根据设计,数据包总是会被填充到 4 个字节。所有的值都是小端编码的。所有数据包都有一个 4 字节的头,代表一个整数,指定数据的类型。
两个低字节用于确定类型,而两个高字节则包含标志:
base_type =