gofmt and update encoding tags
This commit is contained in:
parent
89e4899841
commit
c4a2cbbbbe
5 changed files with 46 additions and 45 deletions
|
@ -206,19 +206,19 @@ type SVPair struct {
|
||||||
|
|
||||||
func TestDecode(t *testing.T) {
|
func TestDecode(t *testing.T) {
|
||||||
tests := []SVPair{
|
tests := []SVPair{
|
||||||
SVPair{"i0e", int64(0)},
|
{"i0e", int64(0)},
|
||||||
SVPair{"i0e", 0},
|
{"i0e", 0},
|
||||||
SVPair{"i100e", 100},
|
{"i100e", 100},
|
||||||
SVPair{"i-100e", -100},
|
{"i-100e", -100},
|
||||||
SVPair{"1:a", "a"},
|
{"1:a", "a"},
|
||||||
SVPair{"2:a\"", "a\""},
|
{"2:a\"", "a\""},
|
||||||
SVPair{"11:0123456789a", "0123456789a"},
|
{"11:0123456789a", "0123456789a"},
|
||||||
SVPair{"le", []int64{}},
|
{"le", []int64{}},
|
||||||
SVPair{"li1ei2ee", []int{1, 2}},
|
{"li1ei2ee", []int{1, 2}},
|
||||||
SVPair{"l3:abc3:defe", []string{"abc", "def"}},
|
{"l3:abc3:defe", []string{"abc", "def"}},
|
||||||
SVPair{"li42e3:abce", []any{42, "abc"}},
|
{"li42e3:abce", []any{42, "abc"}},
|
||||||
SVPair{"de", map[string]any{}},
|
{"de", map[string]any{}},
|
||||||
SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
||||||
}
|
}
|
||||||
for _, sv := range tests {
|
for _, sv := range tests {
|
||||||
if err := check(sv.s, sv.v); err != nil {
|
if err := check(sv.s, sv.v); err != nil {
|
||||||
|
@ -244,19 +244,19 @@ func TestUnmarshal(t *testing.T) {
|
||||||
nestedDictionary := structNested{"aa", "q", "ping", innerDict}
|
nestedDictionary := structNested{"aa", "q", "ping", innerDict}
|
||||||
|
|
||||||
tests := []SVPair{
|
tests := []SVPair{
|
||||||
SVPair{"i100e", 100},
|
{"i100e", 100},
|
||||||
SVPair{"i-100e", -100},
|
{"i-100e", -100},
|
||||||
SVPair{"1:a", "a"},
|
{"1:a", "a"},
|
||||||
SVPair{"2:a\"", "a\""},
|
{"2:a\"", "a\""},
|
||||||
SVPair{"11:0123456789a", "0123456789a"},
|
{"11:0123456789a", "0123456789a"},
|
||||||
SVPair{"le", []int64{}},
|
{"le", []int64{}},
|
||||||
SVPair{"li1ei2ee", []int{1, 2}},
|
{"li1ei2ee", []int{1, 2}},
|
||||||
SVPair{"l3:abc3:defe", []string{"abc", "def"}},
|
{"l3:abc3:defe", []string{"abc", "def"}},
|
||||||
SVPair{"li42e3:abce", []any{42, "abc"}},
|
{"li42e3:abce", []any{42, "abc"}},
|
||||||
SVPair{"de", map[string]any{}},
|
{"de", map[string]any{}},
|
||||||
SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
|
||||||
SVPair{"d1:ai10e1:b3:foo11:sea monster3:bare", structA{10, "foo", "bar"}},
|
{"d1:ai10e1:b3:foo11:sea monster3:bare", structA{10, "foo", "bar"}},
|
||||||
SVPair{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
|
{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
|
||||||
}
|
}
|
||||||
for _, sv := range tests {
|
for _, sv := range tests {
|
||||||
if err := checkUnmarshal(sv.s, sv.v); err != nil {
|
if err := checkUnmarshal(sv.s, sv.v); err != nil {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/vbatts/go-bt/bencode"
|
|
||||||
"github.com/vbatts/go-bt/torrent"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/vbatts/go-bt/bencode"
|
||||||
|
"github.com/vbatts/go-bt/torrent"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,30 +10,30 @@ map[string]interface {}{"announce":"http://torrent.fedoraproject.org:6969/announ
|
||||||
*/
|
*/
|
||||||
type File struct {
|
type File struct {
|
||||||
// URL of a main tracker
|
// URL of a main tracker
|
||||||
Announce string "announce"
|
Announce string `bencode:"announce"`
|
||||||
|
|
||||||
// Epoch of the creation of this torrent
|
// Epoch of the creation of this torrent
|
||||||
CreationDate int64 "creation date"
|
CreationDate int64 `bencode:"creation date"`
|
||||||
|
|
||||||
// Dictionary about this torrent, including files to be tracked
|
// Dictionary about this torrent, including files to be tracked
|
||||||
Info TorrentFileInfo "info"
|
Info TorrentFileInfo `bencode:"info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TorrentFileInfo struct {
|
type TorrentFileInfo struct {
|
||||||
// suggested file/directory name where the file(s) are to be saved
|
// suggested file/directory name where the file(s) are to be saved
|
||||||
Name string "name"
|
Name string `bencode:"name"`
|
||||||
|
|
||||||
// hash list of joined SHA1 sums (160-bit length)
|
// hash list of joined SHA1 sums (160-bit length)
|
||||||
Pieces string "pieces"
|
Pieces string `bencode:"pieces"`
|
||||||
|
|
||||||
// number of bytes per piece
|
// number of bytes per piece
|
||||||
PieceLength int64 "piece length"
|
PieceLength int64 `bencode:"piece length"`
|
||||||
|
|
||||||
// size of the file in bytes (only if this torrent is for a single file)
|
// size of the file in bytes (only if this torrent is for a single file)
|
||||||
Length int64 "length"
|
Length int64 `bencode:"length"`
|
||||||
|
|
||||||
// list of information about the files
|
// list of information about the files
|
||||||
Files []FileInfo "files"
|
Files []FileInfo `bencode:"files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tfi TorrentFileInfo) PiecesList() []string {
|
func (tfi TorrentFileInfo) PiecesList() []string {
|
||||||
|
@ -46,15 +46,16 @@ func (tfi TorrentFileInfo) PiecesList() []string {
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
// size of file in bytes
|
// size of file in bytes
|
||||||
Length int64 "length"
|
Length int64 `bencode:"length"`
|
||||||
|
|
||||||
// list of strings corresponding to subdirectory names, the last of which is the actual file name
|
// list of strings corresponding to subdirectory names, the last of which is the actual file name
|
||||||
Path []string "path"
|
Path []string `bencode:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type torrentError struct {
|
type torrentError struct {
|
||||||
Msg string
|
Msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (te torrentError) Error() string {
|
func (te torrentError) Error() string {
|
||||||
return te.Msg
|
return te.Msg
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue