Documentation ¶
Overview ¶
Package bencode is a library for encoding/decoding bencode data into Go data structures.
Index ¶
Constants ¶
const ( // IntegerStart is the starting delimiter for a bencoded integer. IntegerStart byte = 'i' // IntegerEnd is the ending delimiter for a bencoded integer. IntegerEnd byte = 'e' // ByteStringDelimiter is the size/string delimiter for a bencoded bytestring. ByteStringDelimiter byte = ':' // ListStart is the starting delimiter for a bencoded list. ListStart byte = 'l' // ListEnd is the ending delimiter for a bencoded list. ListEnd byte = 'e' // DictStart is the starting delimiter for a bencoded dict. DictStart byte = 'd' // DictEnd is the ending delimiter for a bencoded dict. DictEnd byte = 'e' )
Variables ¶
var ( // ErrWrongStartByte is the error returned when a wrong start // delimiter is found instead of the expected one ErrWrongStartByte = errors.New("wrong object start byte") // ErrUnknownType is the error returned when a non-bencode package object // (Integer, ByteString, List or Dict) is passed to the API ErrUnknownType = errors.New("unknown object type") )
Functions ¶
This section is empty.
Types ¶
type ByteString ¶
type ByteString struct {
// contains filtered or unexported fields
}
ByteString represents the bencode bytestring type.
func NewByteString ¶
func NewByteString(s string) ByteString
NewByteString returns a bencode ByteString initialized with the given parameter.
func (ByteString) MarshalBinary ¶
func (bs ByteString) MarshalBinary() ([]byte, error)
MarshalBinary satisfies the encoding.BinaryMarshaler interface to marshal a ByteString in binary form.
func (*ByteString) UnmarshalBinary ¶
func (bs *ByteString) UnmarshalBinary(data []byte) error
UnmarshalBinary satisfies the encoding.BinaryUnmarshaler interface to unmarshal a ByteString from binary data.
func (ByteString) Value ¶
func (bs ByteString) Value() string
Value returns a representation of the ByteString using Go standard data type string.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes bencode values from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
type Dict ¶
type Dict struct {
// contains filtered or unexported fields
}
Dict represents the bencode dict type.
func NewDict ¶
func NewDict(d map[ByteString]interface{}) Dict
NewDict returns a bencode Dict initialized with the given parameter.
func (Dict) MarshalBinary ¶
MarshalBinary satisfies the encoding.BinaryMarshaler interface to marshal a Dict in binary form.
func (*Dict) UnmarshalBinary ¶
UnmarshalBinary satisfies the encoding.BinaryUnmarshaler interface to unmarshal a Dict from binary data.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes bencode values to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
type Integer ¶
type Integer struct {
// contains filtered or unexported fields
}
Integer represents the bencode integer type.
func NewInteger ¶
NewInteger returns a bencode Integer initialized with the given parameter.
func (Integer) MarshalBinary ¶
MarshalBinary satisfies the encoding.BinaryMarshaler interface to marshal an Integer in binary form.
func (*Integer) UnmarshalBinary ¶
UnmarshalBinary satisfies the encoding.BinaryUnmarshaler interface to unmarshal an Integer from binary data.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents the bencode list type.
func NewList ¶
func NewList(l []interface{}) List
NewList returns a bencode List initialized with the given parameter.
func (List) MarshalBinary ¶
MarshalBinary satisfies the encoding.BinaryMarshaler interface to marshal a List in binary form.
func (*List) UnmarshalBinary ¶
UnmarshalBinary satisfies the encoding.BinaryUnmarshaler interface to unmarshal a List from binary data.