torrent/bencode
Matt Joiner 02b6ee9954
Add bencode.Bytes.GoString
2022-03-09 20:57:23 +11:00
..
testdata Add failing bencode fuzz input 2021-12-12 16:56:01 +11:00
README.md The bencode README is markdown 2017-09-12 18:31:56 +10:00
api.go Don't panic on int parse failures 2021-08-12 13:46:02 +10:00
bench_test.go Drop bradfitz/iter dependency (#605) 2021-09-14 13:46:50 +10:00
both_test.go bencode: Update some test code 2016-02-23 21:47:00 +11:00
bytes.go Add bencode.Bytes.GoString 2022-03-09 20:57:23 +11:00
bytes_test.go bencode.Bytes: Tests and stricter checks 2021-11-02 17:28:05 +11:00
decode.go bencode: Support decoding "" as dict key 2022-01-07 19:11:41 +11:00
decode_test.go Format code with gofumpt (#724) 2022-02-11 22:45:12 +11:00
encode.go gofumpt 2021-11-08 14:47:01 +11:00
encode_test.go bencode: Encode arrays of bytes as strings 2021-10-28 16:21:23 +11:00
fuzz_test.go Add bencode FuzzInterfaceRoundTrip 2021-12-12 16:56:01 +11:00
misc.go bencode: simplify getting `marshalerType` and `unmarshalerType` (#652) 2021-09-18 12:43:53 +10:00
scanner.go bencode.scanner.ReadByte returned errors when it shouldn't have 2017-11-10 23:44:24 +11:00
tags.go Rework bencode decoding so it might support embedded structs 2021-06-07 13:01:40 +10: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)
}