gofmt and update encoding tags

This commit is contained in:
Vincent Batts 2014-08-14 15:19:42 -04:00
parent 89e4899841
commit c4a2cbbbbe
5 changed files with 46 additions and 45 deletions

View file

@ -206,19 +206,19 @@ type SVPair struct {
func TestDecode(t *testing.T) {
tests := []SVPair{
SVPair{"i0e", int64(0)},
SVPair{"i0e", 0},
SVPair{"i100e", 100},
SVPair{"i-100e", -100},
SVPair{"1:a", "a"},
SVPair{"2:a\"", "a\""},
SVPair{"11:0123456789a", "0123456789a"},
SVPair{"le", []int64{}},
SVPair{"li1ei2ee", []int{1, 2}},
SVPair{"l3:abc3:defe", []string{"abc", "def"}},
SVPair{"li42e3:abce", []any{42, "abc"}},
SVPair{"de", map[string]any{}},
SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
{"i0e", int64(0)},
{"i0e", 0},
{"i100e", 100},
{"i-100e", -100},
{"1:a", "a"},
{"2:a\"", "a\""},
{"11:0123456789a", "0123456789a"},
{"le", []int64{}},
{"li1ei2ee", []int{1, 2}},
{"l3:abc3:defe", []string{"abc", "def"}},
{"li42e3:abce", []any{42, "abc"}},
{"de", map[string]any{}},
{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
}
for _, sv := range tests {
if err := check(sv.s, sv.v); err != nil {
@ -244,19 +244,19 @@ func TestUnmarshal(t *testing.T) {
nestedDictionary := structNested{"aa", "q", "ping", innerDict}
tests := []SVPair{
SVPair{"i100e", 100},
SVPair{"i-100e", -100},
SVPair{"1:a", "a"},
SVPair{"2:a\"", "a\""},
SVPair{"11:0123456789a", "0123456789a"},
SVPair{"le", []int64{}},
SVPair{"li1ei2ee", []int{1, 2}},
SVPair{"l3:abc3:defe", []string{"abc", "def"}},
SVPair{"li42e3:abce", []any{42, "abc"}},
SVPair{"de", map[string]any{}},
SVPair{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
SVPair{"d1:ai10e1:b3:foo11:sea monster3:bare", structA{10, "foo", "bar"}},
SVPair{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
{"i100e", 100},
{"i-100e", -100},
{"1:a", "a"},
{"2:a\"", "a\""},
{"11:0123456789a", "0123456789a"},
{"le", []int64{}},
{"li1ei2ee", []int{1, 2}},
{"l3:abc3:defe", []string{"abc", "def"}},
{"li42e3:abce", []any{42, "abc"}},
{"de", map[string]any{}},
{"d3:cati1e3:dogi2ee", map[string]any{"cat": 1, "dog": 2}},
{"d1:ai10e1:b3:foo11:sea monster3:bare", structA{10, "foo", "bar"}},
{"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe", nestedDictionary},
}
for _, sv := range tests {
if err := checkUnmarshal(sv.s, sv.v); err != nil {

View file

@ -66,7 +66,7 @@ func (j *decoder) Elem(i int) builder {
v = make([]interface{}, 0, 8)
j.value = v
}
/* XXX There is a bug in here somewhere, but append() works fine.
/* XXX There is a bug in here somewhere, but append() works fine.
lens := len(v)
if cap(v) <= lens {
news := make([]interface{}, 0, lens*2)
@ -74,7 +74,7 @@ func (j *decoder) Elem(i int) builder {
v = news
}
v = v[0 : lens+1]
*/
*/
v = append(v, nil)
j.value = v
return newDecoder(v, i)

View file

@ -1,10 +1,10 @@
package main
import (
"github.com/vbatts/go-bt/bencode"
"github.com/vbatts/go-bt/torrent"
"flag"
"fmt"
"github.com/vbatts/go-bt/bencode"
"github.com/vbatts/go-bt/torrent"
"os"
)

View file

@ -10,30 +10,30 @@ map[string]interface {}{"announce":"http://torrent.fedoraproject.org:6969/announ
*/
type File struct {
// URL of a main tracker
Announce string "announce"
Announce string `bencode:"announce"`
// 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
Info TorrentFileInfo "info"
Info TorrentFileInfo `bencode:"info"`
}
type TorrentFileInfo struct {
// 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)
Pieces string "pieces"
Pieces string `bencode:"pieces"`
// 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)
Length int64 "length"
Length int64 `bencode:"length"`
// list of information about the files
Files []FileInfo "files"
Files []FileInfo `bencode:"files"`
}
func (tfi TorrentFileInfo) PiecesList() []string {
@ -46,15 +46,16 @@ func (tfi TorrentFileInfo) PiecesList() []string {
type FileInfo struct {
// 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
Path []string "path"
Path []string `bencode:"path"`
}
type torrentError struct {
Msg string
}
func (te torrentError) Error() string {
return te.Msg
}