基本序列化
本指南介绍 Fory Go 的核心 序列化 API。
创建 Fory 实例
在序列化前先创建 Fory 实例并注册类型:
import "github.com/apache/fory/go/fory"
f := fory.New()
// Register struct with a type ID
f.RegisterStruct(User{}, 1)
f.RegisterStruct(Order{}, 2)
// Or register with a name (more flexible, less prone to ID conflicts, but higher serialization cost)
f.RegisterNamedStruct(User{}, "example.User")
// Register enum types
f.RegisterEnum(Color(0), 3)
重要