YTSFlix_Go/vendor/github.com/anacrolix/torrent/bencode
2018-11-04 15:58:15 +01:00
..
api.go init 2018-11-04 15:58:15 +01:00
bytes.go init 2018-11-04 15:58:15 +01:00
decode.go init 2018-11-04 15:58:15 +01:00
encode.go init 2018-11-04 15:58:15 +01:00
fuzz.go init 2018-11-04 15:58:15 +01:00
misc.go init 2018-11-04 15:58:15 +01:00
README.md init 2018-11-04 15:58:15 +01:00
scanner.go init 2018-11-04 15:58:15 +01:00
tags.go init 2018-11-04 15:58:15 +01:00

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