16176b762e
* Add linter CI Signed-off-by: Bora M. Alper <bora@boramalper.org> * Make gosec CI ignore SHA1 and upload sarif Signed-off-by: Bora M. Alper <bora@boramalper.org> * Fix formatting of source files Signed-off-by: Bora M. Alper <bora@boramalper.org> * Make go vet ignore unkeyed composite literals and fix other warnings Signed-off-by: Bora M. Alper <bora@boramalper.org> * Make staticcheck ignore unused methods and fix other warnings Signed-off-by: Bora M. Alper <bora@boramalper.org> * Use golangci-lint Signed-off-by: Bora M. Alper <bora@boramalper.org> |
||
---|---|---|
.. | ||
testdata | ||
README.md | ||
api.go | ||
bench_test.go | ||
both_test.go | ||
bytes.go | ||
decode.go | ||
decode_test.go | ||
encode.go | ||
encode_test.go | ||
fuzz.go | ||
misc.go | ||
scanner.go | ||
tags.go |
README.md
Bencode encoding/decoding sub package. Uses similar API design to Go's json package.
Install
go get github.com/anacrolix/torrent
Usage
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)
}