plugai_updsrv/deps/github.com/anacrolix/torrent/bencode
hailin 6eefab86da first commit 2025-06-18 13:27:25 +08:00
..
testdata first commit 2025-06-18 13:27:25 +08:00
README.md first commit 2025-06-18 13:27:25 +08:00
api.go first commit 2025-06-18 13:27:25 +08:00
bench_test.go first commit 2025-06-18 13:27:25 +08:00
both_test.go first commit 2025-06-18 13:27:25 +08:00
bytes.go first commit 2025-06-18 13:27:25 +08:00
bytes_test.go first commit 2025-06-18 13:27:25 +08:00
decode.go first commit 2025-06-18 13:27:25 +08:00
decode_test.go first commit 2025-06-18 13:27:25 +08:00
encode.go first commit 2025-06-18 13:27:25 +08:00
encode_test.go first commit 2025-06-18 13:27:25 +08:00
fuzz_test.go first commit 2025-06-18 13:27:25 +08:00
misc.go first commit 2025-06-18 13:27:25 +08:00
scanner.go first commit 2025-06-18 13:27:25 +08:00
string.go first commit 2025-06-18 13:27:25 +08:00
string_go120.go first commit 2025-06-18 13:27:25 +08:00
tags.go first commit 2025-06-18 13:27:25 +08: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)
}