]> Sergey Matveev's repositories - btrtrc.git/blob - metainfo/piece.go
Drop support for go 1.20
[btrtrc.git] / metainfo / piece.go
1 package metainfo
2
3 type Piece struct {
4         Info *Info // Can we embed the fields here instead, or is it something to do with saving memory?
5         i    pieceIndex
6 }
7
8 type pieceIndex = int
9
10 func (p Piece) Length() int64 {
11         if int(p.i) == p.Info.NumPieces()-1 {
12                 return p.Info.TotalLength() - int64(p.i)*p.Info.PieceLength
13         }
14         return p.Info.PieceLength
15 }
16
17 func (p Piece) Offset() int64 {
18         return int64(p.i) * p.Info.PieceLength
19 }
20
21 func (p Piece) Hash() (ret Hash) {
22         copy(ret[:], p.Info.Pieces[p.i*HashSize:(p.i+1)*HashSize])
23         return
24 }
25
26 func (p Piece) Index() pieceIndex {
27         return p.i
28 }