FedP2P/bencode
Matt Joiner e25cfdf6b2 The bencode README is markdown 2017-09-12 18:31:56 +10:00
..
testdata bencode: Use the testdata convention in tests 2016-02-23 21:31:15 +11:00
README.md The bencode README is markdown 2017-09-12 18:31:56 +10:00
api.go bencode.Encoder: Unembed the Writer and wrap it in a minimal interface 2016-06-15 15:09:34 +10:00
both_test.go bencode: Update some test code 2016-02-23 21:47:00 +11:00
bytes.go Make bencode.Bytes work with pointer and nonpointer receivers 2016-08-26 20:29:29 +10:00
decode.go bencode: More renames 2016-08-26 14:51:38 +10:00
decode_test.go bencode: When decoding a dict, if the final key is missing its value, don't treat that as an error. 2015-10-02 00:13:43 +10:00
encode.go bencode: More renames 2016-08-26 14:51:38 +10:00
encode_test.go bencode: Encoding nil interfaces are an error except at data root 2015-10-23 12:35:38 +11:00
fuzz.go bencode: Fuzz 2015-08-23 15:59:49 +10:00
tags.go bencode: More renames 2016-08-26 14:51:38 +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)
}