torrent/bencode
Matt Joiner 9ded7e7e87 Use bytes.Reader instead of bytes.Buffer in a few places 2021-05-05 15:48:57 +10:00
..
testdata
README.md The bencode README is markdown 2017-09-12 18:31:56 +10:00
api.go Use bytes.Reader instead of bytes.Buffer in a few places 2021-05-05 15:48:57 +10:00
bench_test.go goimports -local 2019-08-21 20:58:40 +10:00
both_test.go
bytes.go
decode.go bencode: Decode singleton lists of the expected type 2019-06-13 13:07:37 +10:00
decode_test.go Apply staticcheck 2020-02-20 11:09:57 +11:00
encode.go bencode: Rename string_values->stringValues 2019-12-23 13:39:34 +11:00
encode_test.go bencode: Fix marshalling of []byte(nil) 2018-11-27 08:57:17 +11:00
fuzz.go
misc.go bencode: Remove a lot of expensive allocations 2018-07-25 13:42:28 +10:00
scanner.go bencode.scanner.ReadByte returned errors when it shouldn't have 2017-11-10 23:44:24 +11:00
tags.go bencode: Add ignore_unmarshal_type_error tag 2018-01-27 14:31:46 +11:00

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)
}