Documentation
¶
Overview ¶
Package bencode provides primitives to easily encode values in bencode format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultDecoderOptions = DecoderOptions{
MaxIntegerLength: 64 * 1024,
MaxStringLength: 16 * 1024 * 1024,
}
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoderWithOptions ¶
func NewDecoderWithOptions(r io.Reader, options DecoderOptions) *Decoder
type DecoderOptions ¶
type DecoderOptions struct { // MaxIntegerLength is the maximum amount of bytes that will be used when // reading integer values, excluding delimiters. // // For example, `i10e` needs `MaxIntegerLength >= 2` because `10` is 2 // bytes long. // // This value does NOT affect the parsing of strings. MaxIntegerLength int // MaxStringLength is the maximum length of the content of a string that // can be parsed, excluding its prefix. // // For example, `4:test` needs `MaxStringLength >= 4` becase `test` is 4 // bytes long. // // The parsing of byte strings is NOT affected by `MaxIntegerLength`. When // reading a byte string's prefix, the decoder will read at most // `len(fmt.Sprintf("%d",MaxStringLength))` bytes for the length part, and // will expect a `:` byte after that. // // For example, if `MaxStringLength=9`, then `12:Lorem ipsum.` will return // an error because it will read at most 1 byte for the length (because // `len("9")==1`), but since the next byte is not a delimiter (it's a `2` // instead of `:`), it will stop reading right there and return an error. MaxStringLength int64 }
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
func NewDictionary ¶
func NewDictionary() *Dictionary
func (*Dictionary) Bencode ¶
func (d *Dictionary) Bencode() []byte
func (*Dictionary) Remove ¶
func (d *Dictionary) Remove(key String)
func (*Dictionary) Set ¶
func (d *Dictionary) Set(key String, value Value)
type ErrInvalidToken ¶
type ErrInvalidToken struct {
Offset int64
}
func (*ErrInvalidToken) Error ¶
func (e *ErrInvalidToken) Error() string
type ErrStringTooLong ¶
func (*ErrStringTooLong) Error ¶
func (e *ErrStringTooLong) Error() string
type ErrUnexpectedByte ¶
func (*ErrUnexpectedByte) Error ¶
func (e *ErrUnexpectedByte) Error() string
type Token ¶
Token is an interface holding one of the token types: TokenDictionaryStart, TokenListStart, TokenString, TokenInteger, TokenEnd.
type TokenDictionaryStart ¶
type TokenDictionaryStart struct {
// contains filtered or unexported fields
}
type TokenInteger ¶
type TokenInteger struct { Value int64 // contains filtered or unexported fields }
type TokenListStart ¶
type TokenListStart struct {
// contains filtered or unexported fields
}
type TokenReader ¶
type TokenString ¶
type TokenString struct { Value []byte // contains filtered or unexported fields }
func (*TokenString) Offset ¶
func (ts *TokenString) Offset() int64
func (*TokenString) Raw ¶
func (ts *TokenString) Raw() []byte
Click to show internal directories.
Click to hide internal directories.