Working with BitTorrent? You need Beancode.
- Easy API based on stdlib
- Almost full unit test coverage: 86%
- Support int, string, slice, map, and struct
Let's define a common struct for encoding and decoding processes:
type Boo struct {
Foo int `beancode:"foo"`
Bar string `Beancode:"bar"`
}
To marshal into Bencode:
from := Boo{Foo: 42, Bar: "qux"}
val, err := beancode.Marshal(from)
To unmarshal from Bencode:
var to Boo
from := "d3:fooi42e3:bar3:quxe"
err := beancode.Unmarshal(from, &to)
Voila, as simple as that!
go get github.com/dxtym/beancode
Covered on AMD Ryzen 3 4300U with Radeon Graphics (8GB RAM).
- Marshal: 3652 ns/op, 361 B/op, 17 allocs/op
- Unmarshal: 3672 ns/op, 1515 B/op, 22 allocs/op
- Implement decode to struct
- Enhance benchmark performance
- Have some documentation