status-go/vendor/github.com/anacrolix/torrent/bencode
Pascal Precht 364838532f Add torrent library dependency 2022-04-06 11:48:16 +02:00
..
README.md Add torrent library dependency 2022-04-06 11:48:16 +02:00
api.go Add torrent library dependency 2022-04-06 11:48:16 +02:00
bytes.go Add torrent library dependency 2022-04-06 11:48:16 +02:00
decode.go Add torrent library dependency 2022-04-06 11:48:16 +02:00
encode.go Add torrent library dependency 2022-04-06 11:48:16 +02:00
misc.go Add torrent library dependency 2022-04-06 11:48:16 +02:00
scanner.go Add torrent library dependency 2022-04-06 11:48:16 +02:00
tags.go Add torrent library dependency 2022-04-06 11:48:16 +02: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)
}