From 8bbecdae722480078d89b95e6b1c0f464790f180 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 27 Aug 2024 10:03:22 +1000 Subject: [PATCH] Fix empty Info marshalling test --- metainfo/info.go | 11 ++++++----- metainfo/info_test.go | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/metainfo/info.go b/metainfo/info.go index 015876ed..e58bb10e 100644 --- a/metainfo/info.go +++ b/metainfo/info.go @@ -13,11 +13,12 @@ import ( // The info dictionary. See BEP 3 and BEP 52. type Info struct { - PieceLength int64 `bencode:"piece length"` // BEP3 - Pieces []byte `bencode:"pieces,omitempty"` // BEP3 - Name string `bencode:"name"` // BEP3 - NameUtf8 string `bencode:"name.utf-8,omitempty"` - Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files + PieceLength int64 `bencode:"piece length"` // BEP3 + // BEP 3. This can be omitted because isn't needed in non-hybrid v2 infos. See BEP 52. + Pieces []byte `bencode:"pieces,omitempty"` + Name string `bencode:"name"` // BEP3 + NameUtf8 string `bencode:"name.utf-8,omitempty"` + Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files ExtendedFileAttrs Private *bool `bencode:"private,omitempty"` // BEP27 // TODO: Document this field. diff --git a/metainfo/info_test.go b/metainfo/info_test.go index d65ac2f1..9fd3bded 100644 --- a/metainfo/info_test.go +++ b/metainfo/info_test.go @@ -1,6 +1,7 @@ package metainfo import ( + g "github.com/anacrolix/generics" "testing" "github.com/stretchr/testify/assert" @@ -10,6 +11,7 @@ import ( func TestMarshalInfo(t *testing.T) { var info Info + g.MakeSliceWithLength(&info.Pieces, 0) b, err := bencode.Marshal(info) assert.NoError(t, err) assert.EqualValues(t, "d4:name0:12:piece lengthi0e6:pieces0:e", string(b)) -- 2.48.1