#include <PacketBase.h> [code]
Inherits Protocols::Generics::PacketBase.
Inherited by Protocols::BitTorrent::Packets::AllowedFast, Protocols::BitTorrent::Packets::BadPacket, Protocols::BitTorrent::Packets::BitField, Protocols::BitTorrent::Packets::Cancel, Protocols::BitTorrent::Packets::Choke, Protocols::BitTorrent::Packets::Have, Protocols::BitTorrent::Packets::HaveAll, Protocols::BitTorrent::Packets::HaveNone, Protocols::BitTorrent::Packets::Interested, Protocols::BitTorrent::Packets::Keepalive, Protocols::BitTorrent::Packets::NotInterested, Protocols::BitTorrent::Packets::Piece, Protocols::BitTorrent::Packets::Port, Protocols::BitTorrent::Packets::RejectRequest, Protocols::BitTorrent::Packets::Request, Protocols::BitTorrent::Packets::SuggestPiece, and Protocols::BitTorrent::Packets::Unchoke.
Inheritance diagram for Protocols::BitTorrent::Packets::PacketBase:


This class takes reads and writes the header of a BitTorrent packet. The derived classes must implement reading and writing the payload.
The header of BitTorrent packets contains a 4 byte big-endian integer which says how many bytes follow it (rest of header plus payload). If all four bytes are null, than the packet is of type KeepalivePacket. Otherwise the header contains one further byte specifying the PacketType of the packet.
Check the derived classes for more info about the payload of the different PacketBase types.
Definition at line 74 of file PacketBase.h.
Public Member Functions | |
| virtual QString | protocol () const |
| Returns the string "BitTorrent". | |
| virtual QString | name () const =0 |
| Returns the name of the PacketBase type the dynamic object belongs to. | |
| virtual auto_ptr< DataBase > | copy () const =0 |
| Virtual copy constructor. | |
| PacketType | packetType () const |
| Returns the PacketType of the PacketBase object. | |
Protected Member Functions | |
| PacketBase (Data *d, PacketType packetType) | |
| Constructs a PacketBase object. | |
| virtual bool | readHeader (const QByteArray &rawHeader) |
| Reads the header fields from raw data. | |
| virtual bool | readPayload (const QByteArray &rawPayload) |
| Reads the payload fields from raw bytes. | |
| virtual QByteArray | writeHeader () const |
| Writes the PacketBase header and returns the raw bytes. | |
| virtual QByteArray | writePayload () const |
| Returns the raw bytes representation of the payload fields. | |
| virtual void | readPayload (BinaryReader &)=0 |
| Reads the payload fields from binaryReader. | |
| virtual void | writePayload (BinaryWriter &) const =0 |
Private Member Functions | |
| Q_DECLARE_SHARED_DATA (Data) | |
Classes | |
| class | Data |
|
||||||||||||
|
Constructs a PacketBase object.
Definition at line 53 of file PacketBase.cpp. |
|
|
|
Returns the name of the PacketBase type the dynamic object belongs to.
Implements Protocols::Generics::PacketBase. Implemented in Protocols::BitTorrent::Packets::AllowedFast, Protocols::BitTorrent::Packets::BadPacket, Protocols::BitTorrent::Packets::BitField, Protocols::BitTorrent::Packets::Cancel, Protocols::BitTorrent::Packets::Choke, Protocols::BitTorrent::Packets::Have, Protocols::BitTorrent::Packets::HaveAll, Protocols::BitTorrent::Packets::HaveNone, Protocols::BitTorrent::Packets::Interested, Protocols::BitTorrent::Packets::Keepalive, Protocols::BitTorrent::Packets::NotInterested, Protocols::BitTorrent::Packets::Piece, Protocols::BitTorrent::Packets::Port, Protocols::BitTorrent::Packets::RejectRequest, Protocols::BitTorrent::Packets::Request, Protocols::BitTorrent::Packets::SuggestPiece, and Protocols::BitTorrent::Packets::Unchoke. |
|
|
Returns the PacketType of the PacketBase object.
Definition at line 118 of file PacketBase.h. |
|
|
Returns the string "BitTorrent".
Implements Protocols::Generics::PacketBase. Definition at line 28 of file PacketBase.cpp. |
|
|
|
|
|
Reads the header fields from raw data.
Implements Protocols::Generics::PacketBase. Reimplemented in Protocols::BitTorrent::Packets::BadPacket. Definition at line 77 of file PacketBase.cpp. |
|
|
|
Reads the payload fields from raw bytes.
Implements Protocols::Generics::PacketBase. Reimplemented in Protocols::BitTorrent::Packets::BadPacket. Definition at line 129 of file PacketBase.cpp. |
|
|
Writes the PacketBase header and returns the raw bytes. If the PacketBase is of type KeepalivePacket, then 4 zero bytes are returned. Otherwise the length of the payload + 1 will be written as 4 byte big-endian integer followed by a single byte denoting the PacketType. Implements Protocols::Generics::PacketBase. Reimplemented in Protocols::BitTorrent::Packets::BadPacket. Definition at line 101 of file PacketBase.cpp. |
|
|
Implemented in Protocols::BitTorrent::Packets::AllowedFast, Protocols::BitTorrent::Packets::BadPacket, Protocols::BitTorrent::Packets::BitField, Protocols::BitTorrent::Packets::Cancel, Protocols::BitTorrent::Packets::Choke, Protocols::BitTorrent::Packets::Have, Protocols::BitTorrent::Packets::HaveAll, Protocols::BitTorrent::Packets::HaveNone, Protocols::BitTorrent::Packets::Interested, Protocols::BitTorrent::Packets::Keepalive, Protocols::BitTorrent::Packets::NotInterested, Protocols::BitTorrent::Packets::Piece, Protocols::BitTorrent::Packets::Port, Protocols::BitTorrent::Packets::RejectRequest, Protocols::BitTorrent::Packets::Request, Protocols::BitTorrent::Packets::SuggestPiece, and Protocols::BitTorrent::Packets::Unchoke. |
|
|
Returns the raw bytes representation of the payload fields.
Implements Protocols::Generics::PacketBase. Reimplemented in Protocols::BitTorrent::Packets::BadPacket. Definition at line 158 of file PacketBase.cpp. |