values

package
v0.0.0-...-a9529a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

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

func Decode(src any, dst any) error

Decode fills dst from a decoded ValuesDictionary map.

Decode 将已解码的 ValuesDictionary map 填充到带 `values` tag 的结构体。

func Encode

func Encode(src any) (map[string]any, error)

Encode converts src into the decoded MessagePack map shape used by ValuesDictionary.

Encode 将结构体或 map 转成 ValuesDictionary 解码后的 MessagePack map 形状。

func Marshal

func Marshal(src any) ([]byte, error)

Marshal encodes src into a Survivalcraft ValuesDictionary MessagePack payload.

Marshal 先把结构体或 map 编码成 ValuesDictionary map 形状,再打包为 MessagePack。

func Normalize

func Normalize(src any) (any, error)

Normalize converts decoded ValuesDictionary maps into ordinary Go values.

Normalize 把 ValuesDictionary 的 [类型, 值] 节点转换成 mapstructure 更容易读取的普通 Go 值。

func Unmarshal

func Unmarshal(data []byte, dst any) error

Unmarshal decodes a Survivalcraft ValuesDictionary MessagePack payload into dst.

Unmarshal 先把 MessagePack 解包成 ValuesDictionary map 形状,再填充到结构体 dst。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址