]> Sergey Matveev's repositories - btrtrc.git/blobdiff - metainfo/piece.go
Drop support for go 1.20
[btrtrc.git] / metainfo / piece.go
index 7d95212671c675967bbece0d7fa24bbd8e935973..d8895384d0a1858d17bd3d08fdf89dd4672b3f99 100644 (file)
@@ -1,14 +1,14 @@
 package metainfo
 
-import "github.com/anacrolix/missinggo"
-
 type Piece struct {
-       Info *InfoEx
-       i    int
+       Info *Info // Can we embed the fields here instead, or is it something to do with saving memory?
+       i    pieceIndex
 }
 
+type pieceIndex = int
+
 func (p Piece) Length() int64 {
-       if p.i == p.Info.NumPieces()-1 {
+       if int(p.i) == p.Info.NumPieces()-1 {
                return p.Info.TotalLength() - int64(p.i)*p.Info.PieceLength
        }
        return p.Info.PieceLength
@@ -19,6 +19,10 @@ func (p Piece) Offset() int64 {
 }
 
 func (p Piece) Hash() (ret Hash) {
-       missinggo.CopyExact(&ret, p.Info.Pieces[p.i*20:(p.i+1)*20])
+       copy(ret[:], p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
        return
 }
+
+func (p Piece) Index() pieceIndex {
+       return p.i
+}