Protocols::Kad::Packets::Packet Class Reference

#include <Packet.h> [code]

Inherits Protocols::Generics::PacketBase.

Inherited by Protocols::Kad::Packets::PeerInfoPacket< type >, and Protocols::Kad::Packets::TcpPortPacket< type >.

Inheritance diagram for Protocols::Kad::Packets::Packet:

Inheritance graph
[legend]
Collaboration diagram for Protocols::Kad::Packets::Packet:

Collaboration graph
[legend]
List of all members.

Detailed Description

Base class of all Kad packets.

This class takes reads and writes the header of a Kad packet. The derived classes must implement reading and writing the payload.

The header of Kad packets contains 2 bytes: One defining the protocol id and the other containing the kind of Kad packet.

Check the derived classes for more info about the payload of the different packet types.

Note:
All Kad packets are UDP.
Todo:
Find the way to support both protocol types (compressed and plain).

Definition at line 79 of file Packet.h.

Public Member Functions

virtual QString protocol () const
 Returns the string "Kad".
virtual QString name () const =0
 Returns the name of the PacketBase type the dynamic object belongs to.
virtual Packetcopy () const =0
 Virtual copy constructor.
Protocol protocolId () const
 Returns the Protocol of the Packet object.
PacketType packetType () const
 Returns the PacketType of the Packet object.

Protected Member Functions

 Packet (Data *d, PacketType packetType)
 Constructs a Packet object with a specific PacketType.
virtual bool readHeader (const QByteArray &rawHeader)
 Reads the header fields from raw data.
virtual bool readPayload (const QByteArray &rawPayload)
 Parses the raw bytes in to extract the payload fields.
virtual bool readTrailer (const QByteArray &rawTrailer)
 Kad packets do not have trailers.
virtual QByteArray writeHeader () const
 Writes the packet header and returns the raw bytes.
virtual QByteArray writePayload () const
 Writes the payload fields into raw bytes and returns a QByteArray.
virtual QByteArray writeTrailer () const
 Kad packets do not have trailers.
virtual void readPayload (BinaryReader &)=0
 Reads the payload fields from binaryReader. Called by the implementation of bool Packet::readPayload (const QByteArray &).
virtual void writePayload (BinaryWriter &) const =0

Private Member Functions

 Q_DECLARE_SHARED_DATA (Data)

Classes

class  Data
 Extended private data. More...


Constructor & Destructor Documentation

Packet::Packet Data dd,
PacketType  packetType
[protected]
 

Constructs a Packet object with a specific PacketType.

Note:
The derived classes which call this ctor would pass a newly created object of a class derived from Data, which stores all private data of the dynamic packet type.

The constructor of the derived class which calls this constructor must pass the correct PacketType matching the dynamic type of the packet object.

Definition at line 42 of file Packet.cpp.


Member Function Documentation

virtual Packet* Protocols::Kad::Packets::Packet::copy  )  const [pure virtual]
 

Virtual copy constructor.

Implements Protocols::Generics::PacketBase.

Implemented in Protocols::Kad::Packets::PeerInfoPacket< type >, and Protocols::Kad::Packets::TcpPortPacket< type >.

virtual QString Protocols::Kad::Packets::Packet::name  )  const [pure virtual]
 

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

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

Implements Protocols::Generics::PacketBase.

Implemented in Protocols::Kad::Packets::PeerInfoPacket< type >, and Protocols::Kad::Packets::TcpPortPacket< type >.

PacketType Protocols::Kad::Packets::Packet::packetType  )  const [inline]
 

Returns the PacketType of the Packet object.

Definition at line 124 of file Packet.h.

QString Packet::protocol  )  const [virtual]
 

Returns the string "Kad".

Implements Protocols::Generics::PacketBase.

Definition at line 28 of file Packet.cpp.

Protocol Protocols::Kad::Packets::Packet::protocolId  )  const [inline]
 

Returns the Protocol of the Packet object.

Definition at line 128 of file Packet.h.

Protocols::Kad::Packets::Packet::Q_DECLARE_SHARED_DATA Data   )  [private]
 

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

Reads the header fields from raw data.

Implements Protocols::Generics::PacketBase.

Definition at line 53 of file Packet.cpp.

void Packet::readPayload BinaryReader &   )  [protected, pure virtual]
 

Reads the payload fields from binaryReader. Called by the implementation of bool Packet::readPayload (const QByteArray &).

Implemented in Protocols::Kad::Packets::PeerInfoPacket< type >, and Protocols::Kad::Packets::TcpPortPacket< type >.

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

Parses the raw bytes in to extract the payload fields.

A derived class can either choose to override this function or override Packet::readPayload (BinaryReader& ), which makes parsing using the BinaryReader object much easier.

Implements Protocols::Generics::PacketBase.

Definition at line 110 of file Packet.cpp.

bool Packet::readTrailer const QByteArray &  rawTrailer  )  [protected, virtual]
 

Kad packets do not have trailers.

Returns:
always true as Kad packets do not have trailers.

Definition at line 74 of file Packet.cpp.

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

Writes the packet header and returns the raw bytes.

Implements Protocols::Generics::PacketBase.

Definition at line 81 of file Packet.cpp.

virtual void Protocols::Kad::Packets::Packet::writePayload BinaryWriter &   )  const [protected, pure virtual]
 

Implemented in Protocols::Kad::Packets::PeerInfoPacket< type >, and Protocols::Kad::Packets::TcpPortPacket< type >.

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

Writes the payload fields into raw bytes and returns a QByteArray.

A derived class can either choose to override this function or override Packet::writePayload (BinaryWriter &), which makes writing fields into a QByteArray buffer much easier.

Implements Protocols::Generics::PacketBase.

Definition at line 129 of file Packet.cpp.

QByteArray Packet::writeTrailer  )  const [protected, virtual]
 

Kad packets do not have trailers.

The function returns and empty QByteArray since Kad packets do not have trailers.

Definition at line 99 of file Packet.cpp.


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