model

package
v0.0.0-...-02b7c36 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BTag = "bencode"

Variables

View Source
var (
	ErrNum     = errors.New("expect num")
	ErrCol     = errors.New("expect colon")
	ErrEpI     = errors.New("expect char i")
	ErrEpE     = errors.New("expect char e")
	ErrTyp     = errors.New("wrong type")
	ErrIvd     = errors.New("invalid bencode")
	ErrEncode  = errors.New("unexpect error while encoding")
	ErrMarshal = errors.New("marshal dst must be struct or slice ptr")
	ErrParse   = errors.New("parse torrent file failed")
)

Functions

func Encode

func Encode(o *BNode, writer io.Writer) (int, error)

func MarshalBen

func MarshalBen(w io.Writer, v interface{}) int

func OrderIter

func OrderIter(mp BDict) iter.Seq2[string, BObject]

func PrintBobj

func PrintBobj(b BObject, tab string)

func UnmarshalBen

func UnmarshalBen(r io.Reader, receiver interface{}) error

r: bencode字符串或者文件的读取流 receiver: 接收者,可以是int|string|map[string]*Bobject|[]*Bobject

Types

type BDict

type BDict map[string]BObject

func (*BDict) Decode

func (o *BDict) Decode(br *bufio.Reader, node *BNode)

func (*BDict) Encode

func (o *BDict) Encode(writer io.Writer) (int, error)

func (*BDict) Type

func (o *BDict) Type() Btype

type BInt

type BInt int

func (*BInt) Decode

func (o *BInt) Decode(br *bufio.Reader, node *BNode)

func (*BInt) Encode

func (o *BInt) Encode(writer io.Writer) (int, error)

func (*BInt) Type

func (o *BInt) Type() Btype

type BList

type BList []BObject

func (*BList) Decode

func (o *BList) Decode(br *bufio.Reader, node *BNode)

func (*BList) Encode

func (o *BList) Encode(writer io.Writer) (int, error)

func (*BList) Type

func (o *BList) Type() Btype

type BNode

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

func BenDecode

func BenDecode(r io.Reader) (*BNode, error)

func DecodeFromFile

func DecodeFromFile(name string) ([]*BNode, error)

func DecodeFromString

func DecodeFromString(str string) ([]*BNode, error)

type BObject

type BObject interface {
	Type() Btype
	Encode(writer io.Writer) (int, error)
	Decode(br *bufio.Reader, node *BNode)
}

type BStr

type BStr string

func (*BStr) Decode

func (o *BStr) Decode(br *bufio.Reader, node *BNode)

func (*BStr) Encode

func (o *BStr) Encode(writer io.Writer) (int, error)

func (*BStr) Type

func (o *BStr) Type() Btype

type Btype

type Btype uint8
const (
	BINVALID Btype = iota
	BSTR
	BINT
	BLIST
	BDICT
)

Jump to

Keyboard shortcuts

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