bencode

package
v0.0.0-...-d617ca5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

Marshal returns the bencode encoding of v.

func Unmarshal

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

Unmarshal parses the b-encoded data and stores the result in the value pointed to by v. If v is nil or not a pointer, Unmarshal returns an InvalidUnmarshalError.

func Valid

func Valid(data []byte) bool

Valid reports whether data is a valid Bencode encoding.

Types

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type Marshaler

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

Marshaler is the interface implemented by types that can marshal themselves into valid Bencode.

type MarshalerError

type MarshalerError struct {
	Type reflect.Type
	Err  error
}

A MarshalerError is returned by Marshal when marshal fail

func (*MarshalerError) Error

func (e *MarshalerError) Error() string

type RawMessage

type RawMessage []byte

RawMessage is a raw encoded bencode value.

func (RawMessage) MarshalBencode

func (m RawMessage) MarshalBencode() ([]byte, error)

MarshalBencode returns m as the JSON encoding of m.

func (*RawMessage) UnmarshalBencode

func (m *RawMessage) UnmarshalBencode(data []byte) error

UnmarshalBencode sets *m to a copy of data.

type SyntaxError

type SyntaxError struct {
	Offset int64
	// contains filtered or unexported fields
}

A SyntaxError is a description of a Bencode syntax error.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value  string       // description of Bencode value - "bool", "array", "number -5"
	Type   reflect.Type // type of Go value it could not be assigned to
	Offset int64        // error occurred after reading Offset bytes
	Struct string       // name of the struct type containing the field
	Field  string       // name of the field holding the Go value
}

An UnmarshalTypeError describes a Bencode value that was not appropriate for a value of a specific Go type.

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalBencode([]byte) error
}

Unmarshaler is the interface implemented by types that can unmarshal a Bencode description of themselves. The input can be assumed to be a valid encoding of a Bencode value. UnmarshalBencode must copy the Bencode data if it wishes to retain the data after returning.

By convention, to approximate the behavior of Unmarshal itself, Unmarshalers implement UnmarshalBencode([]byte("null")) as a no-op.

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.

func (*UnsupportedTypeError) Error

func (e *UnsupportedTypeError) Error() string

Jump to

Keyboard shortcuts

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