English | 中文
最好用的、基于Go实现的、AMF序列化/反序列化开源库。
- 用法与json标准库类似
- 灵活的自定义选项
- 更好的兼容性,同时支持AMF0和AMF3
go get github.com/gnolizuh/gamf
in := 1
bs, _ := Marshal(&in)
var out int
Unmarshal(bs, &out)
var bs []byte
buf := bytes.NewBuffer(bs)
in := 1
NewEncoder().WithWriter(buf).Encode(&in)
var out int
NewDecoder().WithReader(buf).Decode(&out)
in := 1.0
bs, _ := Marshal(&in)
var out float64
Unmarshal(bs, &out)
var bs []byte
buf := bytes.NewBuffer(bs)
in := 1
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)
var out int
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)
in := "1"
bs, _ := Marshal(&in)
var out string
Unmarshal(bs, &out)
var bs []byte
buf := bytes.NewBuffer(bs)
in := "1"
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)
var out string
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)
in := "1"
bs, _ := Marshal(&in)
var out string
Unmarshal(bs, &out)
var bs []byte
buf := bytes.NewBuffer(bs)
in := true
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)
out := false
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)
in := []int{1, 2, 3}
bs, _ := Marshal(&in)
var out []int
Unmarshal(bs, &out)
var bs []byte
buf := bytes.NewBuffer(bs)
in := []any{1.0, "1", true, map[string]any{"Int": 1.0, "String": "1", "Bool": true}}
NewEncoder().WithWriter(buf).WithVersion(Version3).Encode(&in)
out := []any{0.0, "0", false, map[string]any{}}
NewDecoder().WithReader(buf).WithVersion(Version3).Decode(&out)
type Struct struct {
Int int `amf:"tag_int"`
String string `amf:"tag_string"`
Bool bool `amf:"tag_bool"`
Object struct {
Int int `amf:"tag_int"`
String string `amf:"tag_string"`
Bool bool `amf:"tag_bool"`
} `amf:"tag_object"`
}
in := Struct{} // with value be initialized
bs, _ := Marshal(&in)
out := Struct{}
Unmarshal(bs, &out)
type Struct struct {
Int int `amf:"tag_int"`
String string `amf:"tag_string"`
Bool bool `amf:"tag_bool"`
Object struct {
Int int `amf:"tag_int"`
String string `amf:"tag_string"`
Bool bool `amf:"tag_bool"`
} `amf:"tag_object"`
}
in := Struct{} // with value be initialized
bs, _ := Marshal(&in)
out := make(map[string]any)
Unmarshal(bs, &out)
in := map[string]any{"Int": 1.0, "String": "1", "Bool": true}
bs, _ := Marshal(&in)
out := make(map[string]any)
Unmarshal(bs, &out)