2
0
mirror of synced 2025-02-23 22:28:11 +00:00
Matt Joiner cd7e6dcd5c bencode: Avoid allocating interface string up front
This should fix crashes during fuzzing. It's not a complete fix, we really want to limit the amount a given Decode can allocate. Maybe Go isn't the right language for this.
2021-12-12 16:56:01 +11:00
..
2021-08-12 13:46:02 +10:00
2016-02-23 21:47:00 +11:00
2021-11-08 14:47:01 +11:00
2017-09-12 18:31:56 +10: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)
}