bencode

package
v2.0.0-rc.2.0...-2c67ad4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2017 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package bencode implements bencoding of data as defined in BEP 3 using type assertion over reflection for performance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the bencoding of v.

func Unmarshal

func Unmarshal(buf []byte) (interface{}, error)

Unmarshal deserializes and returns the bencoded value in buf.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads bencoded objects from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

func (dec *Decoder) Decode() (interface{}, error)

Decode unmarshals the next bencoded value in the stream.

type Dict

type Dict map[string]interface{}

Dict represents a bencode dictionary.

func NewDict

func NewDict() Dict

NewDict allocates the memory for a Dict.

func (Dict) MarshalBencode

func (d Dict) MarshalBencode() ([]byte, error)

MarshalBencode implements the Marshaler interface for Dict.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder writes bencoded objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (enc *Encoder) Encode(v interface{}) error

Encode writes the bencoding of v to the stream.

type List

type List []interface{}

List represents a bencode list.

func NewList

func NewList() List

NewList allocates the memory for a List.

func (List) MarshalBencode

func (l List) MarshalBencode() ([]byte, error)

MarshalBencode implements the Marshaler interface for List.

type Marshaler

type Marshaler interface {
	MarshalBencode() ([]byte, error)
}

Marshaler is the interface implemented by objects that can marshal themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL