Class: QuartzTorrent::Piece

Inherits:
PeerWireMessage show all
Defined in:
lib/quartz_torrent/peermsg.rb

Overview

Piece message. Response to a Request message containing the block of data within a piece.

Constant Summary

Constants inherited from PeerWireMessage

QuartzTorrent::PeerWireMessage::MessageBitfield, QuartzTorrent::PeerWireMessage::MessageCancel, QuartzTorrent::PeerWireMessage::MessageChoke, QuartzTorrent::PeerWireMessage::MessageExtended, QuartzTorrent::PeerWireMessage::MessageHave, QuartzTorrent::PeerWireMessage::MessageInterested, QuartzTorrent::PeerWireMessage::MessageKeepAlive, QuartzTorrent::PeerWireMessage::MessagePiece, QuartzTorrent::PeerWireMessage::MessageRequest, QuartzTorrent::PeerWireMessage::MessageUnchoke, QuartzTorrent::PeerWireMessage::MessageUninterested

Instance Attribute Summary collapse

Attributes inherited from PeerWireMessage

#messageId

Instance Method Summary collapse

Methods inherited from PeerWireMessage

#length

Constructor Details

#initializePiece

Returns a new instance of Piece.



274
275
276
# File 'lib/quartz_torrent/peermsg.rb', line 274

def initialize
  super(MessagePiece)
end

Instance Attribute Details

#blockOffsetObject

Returns the value of attribute blockOffset.



279
280
281
# File 'lib/quartz_torrent/peermsg.rb', line 279

def blockOffset
  @blockOffset
end

#dataObject

Returns the value of attribute data.



280
281
282
# File 'lib/quartz_torrent/peermsg.rb', line 280

def data
  @data
end

#pieceIndexObject

Returns the value of attribute pieceIndex.



278
279
280
# File 'lib/quartz_torrent/peermsg.rb', line 278

def pieceIndex
  @pieceIndex
end

Instance Method Details

#payloadLengthObject



282
283
284
# File 'lib/quartz_torrent/peermsg.rb', line 282

def payloadLength
  8 + @data.length     
end

#serializeTo(io) ⇒ Object



286
287
288
289
# File 'lib/quartz_torrent/peermsg.rb', line 286

def serializeTo(io)
  super(io)
  io.write [@pieceIndex, @blockOffset, @data].pack("NNa*")
end

#to_sObject



295
296
297
298
# File 'lib/quartz_torrent/peermsg.rb', line 295

def to_s
  s = super
  s + ": piece index=#{@pieceIndex}, block offset=#{@blockOffset}"
end

#unserialize(payload) ⇒ Object



291
292
293
# File 'lib/quartz_torrent/peermsg.rb', line 291

def unserialize(payload)
  @pieceIndex, @blockOffset, @data = payload.unpack("NNa*")
end