Documentation
¶
Overview ¶
Package values converts Survivalcraft ValuesDictionary maps to and from Go structs.
Package values 在 Survivalcraft ValuesDictionary 的 MessagePack 解码形状和 Go 强类型结构体之间转换。
A ValuesDictionary map is the decoded MessagePack form used by the game:
ValuesDictionary 在 MessagePack 解码后通常是下面这种形状:
map[string]any{
"Name": []any{"string", "Steve"},
"SpawnPosition": []any{"Vector3", "0, 0, 0"},
"Subsystems": map[string]any{...},
}
Primitive values are encoded as [typeName, value]. Nested dictionaries are encoded as maps.
基础值用 [typeName, value] 保存,嵌套 ValuesDictionary 用 map 保存。
Decode first normalizes typed pairs into natural Go values, then uses mapstructure with the `values` tag. Encode performs the reverse operation for structs and map[string]T.
Decode 会先把 typed pair 规整成普通 Go 值,再通过 mapstructure 和 `values` tag 写入结构体。 Encode 则把结构体或 map[string]T 反向编码成 ValuesDictionary 形状。 Marshal 和 Unmarshal 在 Encode/Decode 外层处理 MessagePack 字节。
Supported special values include System.Guid, Vector2, Vector3, Quaternion, Matrix, Point2, Point3 and Engine.Color. Unknown enum names are intentionally left as strings.
当前特殊支持 System.Guid、Vector2、Vector3、Quaternion、Matrix、Point2、Point3 和 Engine.Color。 未知枚举名会保留为 string,避免把游戏枚举和协议枚举混淆。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode fills dst from a decoded ValuesDictionary map.
Decode 将已解码的 ValuesDictionary map 填充到带 `values` tag 的结构体。
func Encode ¶
Encode converts src into the decoded MessagePack map shape used by ValuesDictionary.
Encode 将结构体或 map 转成 ValuesDictionary 解码后的 MessagePack map 形状。
func Marshal ¶
Marshal encodes src into a Survivalcraft ValuesDictionary MessagePack payload.
Marshal 先把结构体或 map 编码成 ValuesDictionary map 形状,再打包为 MessagePack。
Types ¶
This section is empty.