Skip to content

Commit

Permalink
more examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
ginohu committed Jan 26, 2024
1 parent 6c46ebc commit af4ddbe
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 14 deletions.
96 changes: 89 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand All @@ -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
Expand Down
96 changes: 89 additions & 7 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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编解码库

# 特性
Expand All @@ -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"`
Expand All @@ -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)
```

# 引用
Expand Down

0 comments on commit af4ddbe

Please sign in to comment.