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
}
-func (me Piece) Length() int64 {
- if me.i == me.Info.NumPieces()-1 {
- return me.Info.TotalLength() - int64(me.i)*me.Info.PieceLength
+type pieceIndex = int
+
+func (p Piece) Length() int64 {
+ if int(p.i) == p.Info.NumPieces()-1 {
+ return p.Info.TotalLength() - int64(p.i)*p.Info.PieceLength
}
- return me.Info.PieceLength
+ return p.Info.PieceLength
}
-func (me Piece) Offset() int64 {
- return int64(me.i) * me.Info.PieceLength
+func (p Piece) Offset() int64 {
+ return int64(p.i) * p.Info.PieceLength
}
-func (me Piece) Hash() (ret Hash) {
- missinggo.CopyExact(&ret, me.Info.Pieces[me.i*20:(me.i+1)*20])
+func (p Piece) Hash() (ret Hash) {
+ copy(ret[:], p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
return
}
+
+func (p Piece) Index() pieceIndex {
+ return p.i
+}