# README
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)
}
# Functions
Marshal the value 'v' to the bencode form, return the result as []byte and an error if any.
Unmarshal the bencode value in the 'data' to a value pointed by the 'v' pointer, return a non-nil error if any.
# Constants
~128MiB.
# Structs
A non-nil error was returned after calling MarshalBencode on a type which implements the Marshaler interface.
In case if marshaler cannot encode a type, it will return this error.
Malformed bencode input, unmarshaler failed to parse it.
A non-nil error was returned after calling UnmarshalBencode on a type which implements the Unmarshaler interface.
Unmarshaler tried to write to an unexported (therefore unwritable) field.
Unmarshal argument must be a non-nil value of some pointer type.
Unmarshaler spotted a value that was not appropriate for a given Go value.
# Interfaces
Any type which implements this interface, will be marshaled using the specified method.
Any type which implements this interface, will be unmarshaled using the specified method.