encodeData

fun encodeData(piece: Int, totalSize: Long, pieceData: ByteArray): ByteArray

Encode a data message: the bencode dict d8:msg_typei1e5:piecei<n>e10:total_sizei<s>ee, followed by the raw pieceData bytes appended verbatim.

Mirrors write_metadata_packet(msg_t::piece, piece): it writes msg_type, piece and total_size, then append_const_send_buffers the piece bytes.

Parameters

piece

the 0-based piece index.

totalSize

the total length of the whole metadata blob.

pieceData

the raw bytes of this piece (≤ PIECE_SIZE).