addPiece

fun addPiece(piece: Int, data: ByteArray): Boolean

Store the bytes of one metadata piece. Mirrors the validity checks in received_metadata:

  • piece must be in range,

  • the piece must not overflow the total ((piece*16K + len > total) is rejected),

  • and a piece other than the last must be exactly UtMetadata.PIECE_SIZE long (libtorrent enforces this implicitly because it sizes the buffer from total_size).

Re-adding an already-present piece is a no-op that still returns true.

Return

true if the piece was accepted (or already present); false if it was out of range or the wrong size for its position.