FedP2P/bencode/README.md

39 lines
536 B
Markdown
Raw Normal View History

2012-06-20 21:21:32 +08:00
Bencode encoding/decoding sub package. Uses similar API design to Go's json package.
2017-09-05 22:42:37 +08:00
## Install
```sh
go get github.com/anacrolix/torrent
```
## Usage
```go
package demo
import (
bencode "github.com/anacrolix/torrent/bencode"
)
type Message struct {
Query string `json:"q,omitempty" bencode:"q,omitempty"`
}
var v Message
func main(){
// encode
data, err := bencode.Marshal(v)
if err != nil {
log.Fatal(err)
}
//decode
err := bencode.Unmarshal(data, &v)
if err != nil {
log.Fatal(err)
}
fmt.Println(v)
}
```