Documentation ¶
Index ¶
- Constants
- func IsEmptyValue(v reflect.Value) bool
- func Marshal(v any) ([]byte, error)
- func MustMarshal(v any) []byte
- func Unmarshal(data []byte, v any) (err error)
- type Bytes
- type Data
- func (this Data) GetAnnounce() string
- func (this Data) GetComment() string
- func (this Data) GetCreatedBy() string
- func (this Data) GetCreationDate() int64
- func (this Data) GetCreationDateTime(tz ...string) time.Time
- func (this Data) GetInfo() map[string]any
- func (this Data) GetInfoItem(key string) any
- func (this Data) GetInfoKeys() []string
- func (this Data) GetItem(key string) any
- func (this Data) GetItemInt64(key string) int64
- func (this Data) GetItemMap(key string) map[string]any
- func (this Data) GetItemString(key string) string
- func (this Data) GetKeys() []string
- func (this Data) SetAnnounce(data string) Data
- func (this Data) SetComment(data string) Data
- func (this Data) SetCreatedBy(data string) Data
- func (this Data) SetCreationDate(data int64) Data
- func (this Data) SetCreationDateTime(t time.Time) Data
- func (this Data) SetInfo(data map[string]any) Data
- func (this Data) SetItem(key string, data any) Data
- func (this Data) String() string
- func (this Data) ToArray() map[string]any
- func (this Data) ToInfoArray() map[string]any
- func (this Data) ToInfoJSON() string
- func (this Data) ToJSON() string
- type Decoder
- type Encoder
- type FileInfo
- type MarshalTypeError
- type Marshaler
- type MarshalerError
- type MaxStrLen
- type MultipleInfo
- type MultipleInfoFile
- type MultipleTorrent
- func (this MultipleTorrent) GetAnnounceList() []string
- func (this MultipleTorrent) GetCreationDateTime(tz ...string) time.Time
- func (this MultipleTorrent) GetInfoHash() ([20]byte, error)
- func (this MultipleTorrent) GetInfoHashString() string
- func (this MultipleTorrent) SetCreationDateTime(t time.Time) MultipleTorrent
- type SingleInfo
- type SingleTorrent
- func (this SingleTorrent) GetAnnounceList() []string
- func (this SingleTorrent) GetCreationDateTime(tz ...string) time.Time
- func (this SingleTorrent) GetInfoHash() ([20]byte, error)
- func (this SingleTorrent) GetInfoHashString() string
- func (this SingleTorrent) SetCreationDateTime(t time.Time) SingleTorrent
- type SyntaxError
- type UnmarshalFieldError
- type UnmarshalInvalidArgError
- type UnmarshalTypeError
- type Unmarshaler
- type UnmarshalerError
- type UnusedTrailingBytesError
Constants ¶
const DefaultDecodeMaxStrLen = 1<<27 - 1 // ~128MiB
The default bencode string length limit. This is a poor attempt to prevent excessive memory allocation when parsing, but also leaves the window open to implement a better solution.
Variables ¶
This section is empty.
Functions ¶
func IsEmptyValue ¶
Returns whether the value represents the empty value for its type. Used for example to determine if complex types satisfy the common "omitempty" tag option for marshalling.
func Marshal ¶
Marshal the value 'v' to the bencode form, return the result as []byte and an error if any.
func Unmarshal ¶
Unmarshal the bencode value in the 'data' to a value pointed by the 'v' pointer, return a non-nil error if any. If there are trailing bytes, this results in UnusedTrailingBytesError, but the value will be valid. It's probably more consistent to use Decoder.Decode if you want to rely on this behaviour (inspired by Rust's serde here).
Types ¶
type Decoder ¶
type MarshalTypeError ¶
In case if marshaler cannot encode a type, it will return this error. Typical example of such type is float32/float64 which has no bencode representation.
func (*MarshalTypeError) Error ¶
func (e *MarshalTypeError) Error() string
type Marshaler ¶
Any type which implements this interface, will be marshaled using the specified method.
type MarshalerError ¶
A non-nil error was returned after calling MarshalBencode on a type which implements the Marshaler interface.
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
type MultipleInfo ¶
type MultipleInfo struct { // 每个块的20个字节的SHA1 Hash的值(二进制格式) Pieces string `bencode:"pieces"` // 每个块的大小,单位字节 整数 PieceLength int `bencode:"piece length"` // 文件长度 整数 Length int `bencode:"length,omitempty"` // 目录名 字符串 Name string `bencode:"name"` // 目录名编码 NameUtf8 string `bencode:"name.utf-8,omitempty"` // 文件信息 Files []MultipleInfoFile `bencode:"files"` }
多文件信息
func (MultipleInfo) GetPieceHashes ¶
func (this MultipleInfo) GetPieceHashes() ([][20]byte, error)
每个分片的 SHA-1 hash 长度是20 把他们从Pieces中切出来
type MultipleInfoFile ¶
type MultipleInfoFile struct { // 文件长度 单位字节 整数 Length int `bencode:"length"` // 文件的路径和名字 列表 Path []string `bencode:"path"` // path.utf-8:文件名的UTF-8编码 PathUtf8 string `bencode:"path.utf-8,omitempty"` }
文件信息
type MultipleTorrent ¶
type MultipleTorrent struct { // `bencode:""` // tracker服务器的URL 字符串 Announce string `bencode:"announce"` // 备用tracker服务器列表 列表 // 发现 announce-list 后面跟了两个l(ll) announce-listll AnnounceList [][]string `bencode:"announce-list,omitempty"` // 种子的创建时间 整数 CreatDate int64 `bencode:"creation date"` // 备注 字符串 Comment string `bencode:"comment"` // 创建者 字符串 CreatedBy string `bencode:"created by"` // 详情 Info MultipleInfo `bencode:"info"` // 包含一系列ip和相应端口的列表,是用于连接DHT初始node Nodes [][]any `bencode:"nodes,omitempty"` // 文件的默认编码 Encoding string `bencode:"encoding,omitempty"` // 备注的utf-8编码 CommentUtf8 string `bencode:"comment.utf-8,omitempty"` }
多文件 包含5:files 版本为通用类,非通用类需要直接用 map 获取数据或者生成数据
func (MultipleTorrent) GetAnnounceList ¶
func (this MultipleTorrent) GetAnnounceList() []string
获取备用节点
func (MultipleTorrent) GetCreationDateTime ¶
func (this MultipleTorrent) GetCreationDateTime(tz ...string) time.Time
获取格式化后的创建时间
func (MultipleTorrent) GetInfoHash ¶
func (this MultipleTorrent) GetInfoHash() ([20]byte, error)
生成 info hash
func (MultipleTorrent) GetInfoHashString ¶
func (this MultipleTorrent) GetInfoHashString() string
生成 info hash 字符
func (MultipleTorrent) SetCreationDateTime ¶
func (this MultipleTorrent) SetCreationDateTime(t time.Time) MultipleTorrent
设置创建时间
type SingleInfo ¶
type SingleInfo struct { Pieces string `bencode:"pieces"` PieceLength int `bencode:"piece length"` Length int `bencode:"length"` Name string `bencode:"name"` NameUtf8 string `bencode:"name.utf-8,omitempty"` // 文件发布者 Publisher string `bencode:"publisher,omitempty"` PublisherUtf8 string `bencode:"publisher.utf-8,omitempty"` // 文件发布者的网址 PublisherUrl string `bencode:"publisher-url,omitempty"` PublisherUrlUtf8 string `bencode:"publisher-url.utf-8,omitempty"` MD5Sum string `bencode:"md5sum,omitempty"` Private bool `bencode:"private,omitempty"` }
单文件信息
func (SingleInfo) GetPieceHashes ¶
func (this SingleInfo) GetPieceHashes() ([][20]byte, error)
每个分片的 SHA-1 hash 长度是20 把他们从Pieces中切出来
type SingleTorrent ¶
type SingleTorrent struct { // `bencode:""` // tracker服务器的URL 字符串 Announce string `bencode:"announce"` // 备用tracker服务器列表 列表 // 发现 announce-list 后面跟了两个l(ll) announce-listll AnnounceList [][]string `bencode:"announce-list,omitempty"` // 种子的创建时间 整数 CreatDate int64 `bencode:"creation date"` // 备注 字符串 Comment string `bencode:"comment"` // 创建者 字符串 CreatedBy string `bencode:"created by"` // 详情 Info SingleInfo `bencode:"info"` // 包含一系列ip和相应端口的列表,是用于连接DHT初始node Nodes [][]any `bencode:"nodes,omitempty"` // 文件的默认编码 Encoding string `bencode:"encoding,omitempty"` // 备注的utf-8编码 CommentUtf8 string `bencode:"comment.utf-8,omitempty"` }
单文件 版本为通用类,非通用类需要直接用 map 获取数据或者生成数据
func (SingleTorrent) GetCreationDateTime ¶
func (this SingleTorrent) GetCreationDateTime(tz ...string) time.Time
获取格式化后的创建时间
func (SingleTorrent) GetInfoHash ¶
func (this SingleTorrent) GetInfoHash() ([20]byte, error)
生成 info hash
func (SingleTorrent) GetInfoHashString ¶
func (this SingleTorrent) GetInfoHashString() string
生成 info hash 字符
func (SingleTorrent) SetCreationDateTime ¶
func (this SingleTorrent) SetCreationDateTime(t time.Time) SingleTorrent
设置创建时间
type SyntaxError ¶
Malformed bencode input, unmarshaler failed to parse it.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type UnmarshalFieldError ¶
type UnmarshalFieldError struct { Key string Type reflect.Type Field reflect.StructField }
Unmarshaler tried to write to an unexported (therefore unwritable) field.
func (*UnmarshalFieldError) Error ¶
func (e *UnmarshalFieldError) Error() string
type UnmarshalInvalidArgError ¶
Unmarshal argument must be a non-nil value of some pointer type.
func (*UnmarshalInvalidArgError) Error ¶
func (e *UnmarshalInvalidArgError) Error() string
type UnmarshalTypeError ¶
Unmarshaler spotted a value that was not appropriate for a given Go value.
func (*UnmarshalTypeError) Error ¶
func (e *UnmarshalTypeError) Error() string
This could probably be a value type, but we may already have users assuming that it's passed by pointer.
type Unmarshaler ¶
Any type which implements this interface, will be unmarshaled using the specified method.
type UnmarshalerError ¶
A non-nil error was returned after calling UnmarshalBencode on a type which implements the Unmarshaler interface.
func (*UnmarshalerError) Error ¶
func (e *UnmarshalerError) Error() string
type UnusedTrailingBytesError ¶
type UnusedTrailingBytesError struct {
NumUnusedBytes int
}
func (UnusedTrailingBytesError) Error ¶
func (me UnusedTrailingBytesError) Error() string