Protocols::BitTorrent::Packets::BadPacket Class Reference

#include <BadPacket.h> [code]

Inherits Protocols::BitTorrent::Packets::PacketBase.

Inheritance diagram for Protocols::BitTorrent::Packets::BadPacket:

Inheritance graph
[legend]
Collaboration diagram for Protocols::BitTorrent::Packets::BadPacket:

Collaboration graph
[legend]
List of all members.

Detailed Description

A packet class encapsulating the raw data of a packet that cannot be parsed.

BadPacket is intended to be used as a Null Object where a PacketBase object is required. It can also be used to store the raw bytes of packets that either cannot be parsed or whose PacketType is unknown.

See also:
Packet, PacketProtocol

Definition at line 41 of file BadPacket.h.

Public Member Functions

QString name () const
 Returns the name of the PacketBase type the dynamic object belongs to.
auto_ptr< DataBasecopy () const
 Virtual copy constructor.
 BadPacket (PacketType type=KeepalivePacket, const QByteArray &rawHeader=QByteArray(), const QByteArray &rawPayload=QByteArray())
 Constructs an object from raw data.

Protected Member Functions

void invalidateHeader ()
 Invalidate the header raw data.
void invalidatePayload ()
 Invalidate the payload raw data.
bool readHeader (const QByteArray &rawHeader)
 Parsing the header of a BadPacket always succeeds.
bool readPayload (const QByteArray &rawPayload)
 Parsing the payload of a BadPacket always succeeds.
QByteArray writeHeader () const
 Writes the PacketBase header and returns the raw bytes.
QByteArray writePayload () const
 Returns the raw bytes representation of the payload fields.
void readPayload (BinaryReader &)
 Reads the payload fields from binaryReader.
void writePayload (BinaryWriter &) const

Private Member Functions

 Q_DECLARE_SHARED_DATA (Data)

Classes

class  Data
 BadPacket private data. More...


Constructor & Destructor Documentation

BadPacket::BadPacket PacketType  type = KeepalivePacket,
const QByteArray &  rawHeader = QByteArray(),
const QByteArray &  rawPayload = QByteArray()
 

Constructs an object from raw data.

Definition at line 40 of file BadPacket.cpp.


Member Function Documentation

auto_ptr< DataBase > BadPacket::copy  )  const [virtual]
 

Virtual copy constructor.

Implements Protocols::BitTorrent::Packets::PacketBase.

Definition at line 32 of file BadPacket.cpp.

void BadPacket::invalidateHeader  )  [protected, virtual]
 

Invalidate the header raw data.

The raw header bytes will be rebuilt next time rawHeader() is called.

See also:
invalidatePayload()

Reimplemented from Protocols::Generics::PacketBase.

Definition at line 52 of file BadPacket.cpp.

void BadPacket::invalidatePayload  )  [protected, virtual]
 

Invalidate the payload raw data.

The payload is invalidated, due to the fact that the payloadLength field may have changed, and the header is marked as invalid too. These will be rebuilt next time rawHeader() and rawPayload() are called.

See also:
invalidateHeader()

Reimplemented from Protocols::Generics::PacketBase.

Definition at line 57 of file BadPacket.cpp.

QString BadPacket::name  )  const [virtual]
 

Returns the name of the PacketBase type the dynamic object belongs to.

Todo:
Better use PacketId (which possibly contains the ProtocolId)?

Implements Protocols::BitTorrent::Packets::PacketBase.

Definition at line 27 of file BadPacket.cpp.

Protocols::BitTorrent::Packets::BadPacket::Q_DECLARE_SHARED_DATA Data   )  [private]
 

bool BadPacket::readHeader const QByteArray &  rawHeader  )  [protected, virtual]
 

Parsing the header of a BadPacket always succeeds.

Reimplemented from Protocols::BitTorrent::Packets::PacketBase.

Definition at line 63 of file BadPacket.cpp.

void BadPacket::readPayload BinaryReader  )  [protected, virtual]
 

Reads the payload fields from binaryReader.

Parameters:
binaryReader is the BinaryReader object from which to read the payload fields.
Note:
This function is called by the implementation of bool PacketBase::readPayload (const QByteArray &). You could chose to implement either of them.

Implements Protocols::BitTorrent::Packets::PacketBase.

Definition at line 86 of file BadPacket.cpp.

bool BadPacket::readPayload const QByteArray &  rawPayload  )  [protected, virtual]
 

Parsing the payload of a BadPacket always succeeds.

Reimplemented from Protocols::BitTorrent::Packets::PacketBase.

Definition at line 69 of file BadPacket.cpp.

QByteArray BadPacket::writeHeader  )  const [protected, virtual]
 

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.

Reimplemented from Protocols::BitTorrent::Packets::PacketBase.

Definition at line 74 of file BadPacket.cpp.

void BadPacket::writePayload BinaryWriter  )  const [protected, virtual]
 

Implements Protocols::BitTorrent::Packets::PacketBase.

Definition at line 91 of file BadPacket.cpp.

QByteArray BadPacket::writePayload  )  const [protected, virtual]
 

Returns the raw bytes representation of the payload fields.

Returns:
A byte array containing the raw bytes representation of the packet's payload.
Note:
A derived class can either choose to override this function or override PacketBase::writePayload (BinaryWriter &), which wakes writing fields into a QByteArray buffer much easier.

Reimplemented from Protocols::BitTorrent::Packets::PacketBase.

Definition at line 80 of file BadPacket.cpp.


The documentation for this class was generated from the following files: