diff --git a/README.md b/README.md index 000a7a7..8209422 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,6 @@ English | [中文](README.zh_CN.md) # gamf -![Go](https://github.com/goccy/go-json/workflows/Go/badge.svg) -[![GoDoc](https://godoc.org/github.com/goccy/go-json?status.svg)](https://pkg.go.dev/github.com/goccy/go-json?tab=doc) -[![codecov](https://codecov.io/gh/goccy/go-json/branch/master/graph/badge.svg)](https://codecov.io/gh/goccy/go-json) - Easiest AMF encoder/decoder for Go. # Features @@ -21,6 +17,81 @@ go get github.com/gnolizuh/gamf # How to use +## Integer + +``` +in := 1 +bs, _ := Marshal(&in) + +var out int +Unmarshal(bs, &out) +``` + +## Float + +``` +in := 1.0 +bs, _ := Marshal(&in) + +var out float64 +Unmarshal(bs, &out) +``` + +## String + +``` +in := "1" +bs, _ := Marshal(&in) + +var out string +Unmarshal(bs, &out) +``` + +## Bool + +``` +in := "1" +bs, _ := Marshal(&in) + +var out string +Unmarshal(bs, &out) +``` + +## Slice + +``` +in := []int{1, 2, 3} +bs, _ := Marshal(&in) + +var out []int +Unmarshal(bs, &out) +``` + +## Struct + +### Struct to Struct + +``` +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) +``` + +### Struct to Map + ``` type Struct struct { Int int `amf:"tag_int"` @@ -33,10 +104,21 @@ type Struct struct { } `amf:"tag_object"` } -bs, _ := Marshal(&Struct{}) +in := Struct{} // with value be initialized +bs, _ := Marshal(&in) + +out := make(map[string]interface{}) +Unmarshal(bs, &out) +``` + +## Map + +``` +in := map[string]interface{}{"Int": 1.0, "String": "1", "Bool": true} +bs, _ := Marshal(&in) -s := Struct{} -Unmarshal(bs, &s) +out := make(map[string]interface{}) +Unmarshal(bs, &out) ``` # Reference diff --git a/README.zh_CN.md b/README.zh_CN.md index ed44418..0eac179 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -2,10 +2,6 @@ # gamf -![Go](https://github.com/goccy/go-json/workflows/Go/badge.svg) -[![GoDoc](https://godoc.org/github.com/goccy/go-json?status.svg)](https://pkg.go.dev/github.com/goccy/go-json?tab=doc) -[![codecov](https://codecov.io/gh/goccy/go-json/branch/master/graph/badge.svg)](https://codecov.io/gh/goccy/go-json) - 基于Go实现的极简AMF编解码库 # 特性 @@ -21,6 +17,81 @@ go get github.com/gnolizuh/gamf # 用法 +## Integer + +``` +in := 1 +bs, _ := Marshal(&in) + +var out int +Unmarshal(bs, &out) +``` + +## Float + +``` +in := 1.0 +bs, _ := Marshal(&in) + +var out float64 +Unmarshal(bs, &out) +``` + +## String + +``` +in := "1" +bs, _ := Marshal(&in) + +var out string +Unmarshal(bs, &out) +``` + +## Bool + +``` +in := "1" +bs, _ := Marshal(&in) + +var out string +Unmarshal(bs, &out) +``` + +## Slice + +``` +in := []int{1, 2, 3} +bs, _ := Marshal(&in) + +var out []int +Unmarshal(bs, &out) +``` + +## Struct + +### Struct to Struct + +``` +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) +``` + +### Struct to Map + ``` type Struct struct { Int int `amf:"tag_int"` @@ -33,10 +104,21 @@ type Struct struct { } `amf:"tag_object"` } -bs, _ := Marshal(&Struct{}) +in := Struct{} // with value be initialized +bs, _ := Marshal(&in) + +out := make(map[string]interface{}) +Unmarshal(bs, &out) +``` + +## Map + +``` +in := map[string]interface{}{"Int": 1.0, "String": "1", "Bool": true} +bs, _ := Marshal(&in) -s := Struct{} -Unmarshal(bs, &s) +out := make(map[string]interface{}) +Unmarshal(bs, &out) ``` # 引用