Class: QuartzTorrent::Piece
- Inherits:
-
PeerWireMessage
- Object
- PeerWireMessage
- QuartzTorrent::Piece
- 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
-
#blockOffset ⇒ Object
Returns the value of attribute blockOffset.
-
#data ⇒ Object
Returns the value of attribute data.
-
#pieceIndex ⇒ Object
Returns the value of attribute pieceIndex.
Attributes inherited from PeerWireMessage
Instance Method Summary collapse
-
#initialize ⇒ Piece
constructor
A new instance of Piece.
- #payloadLength ⇒ Object
- #serializeTo(io) ⇒ Object
- #to_s ⇒ Object
- #unserialize(payload) ⇒ Object
Methods inherited from PeerWireMessage
Constructor Details
#initialize ⇒ Piece
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
#blockOffset ⇒ Object
Returns the value of attribute blockOffset.
279 280 281 |
# File 'lib/quartz_torrent/peermsg.rb', line 279 def blockOffset @blockOffset end |
#data ⇒ Object
Returns the value of attribute data.
280 281 282 |
# File 'lib/quartz_torrent/peermsg.rb', line 280 def data @data end |
#pieceIndex ⇒ Object
Returns the value of attribute pieceIndex.
278 279 280 |
# File 'lib/quartz_torrent/peermsg.rb', line 278 def pieceIndex @pieceIndex end |
Instance Method Details
#payloadLength ⇒ Object
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_s ⇒ Object
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 |