Protocols::BitTorrent::Packets::PacketProtocol Class Reference

#include <PacketProtocol.h> [code]

Inherits Protocols::Generics::PacketProtocol.

Inheritance diagram for Protocols::BitTorrent::Packets::PacketProtocol:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

Implements the BitTorrent PacketProtocol.

See also:
Protocols::Generics::PacketProtocol

Definition at line 37 of file PacketProtocol.h.

Public Types

enum  Constants { HeaderLength = 4 }

Public Member Functions

int headerLength () const
 Returns the length of a BitTorrent packet's header.
int payloadLength (const QByteArray &header) const
 Extracts the payload length encoded in header.
GenericsPacket createPacket (const QByteArray &header, const QByteArray &payload) const
 Creates a BitTorrent packet from raw data.

Static Private Member Functions

static Packet getPacketFromTypeByte (uchar byte)
 Helper that returns a Packet of type corresponding to bytes.
static Packet parsedOrBadPacket (Packet &packet, const QByteArray &rawHeader, const QByteArray &rawPayload)
 Helper that parses the raw bytes and returns a BadPacket if parsing failed.


Member Enumeration Documentation

enum Protocols::BitTorrent::Packets::PacketProtocol::Constants
 

Enumerator:
HeaderLength  The length of a BitTorrent packet's header.

Definition at line 40 of file PacketProtocol.h.


Member Function Documentation

GenericsPacket PacketProtocol::createPacket const QByteArray &  rawHeader,
const QByteArray &  rawPayload
const [virtual]
 

Creates a BitTorrent packet from raw data.

Parameters:
rawHeader contains the raw header bytes.
rawPayload contains the raw payload bytes.
Returns:
A Packet object encapsulating a PacketBase derived object of the correct runtime type parsed from rawHeader and rawPayload.

A Packet object encapsulating a BadPacket object if the packet type encoded in the raw bytes was unknown or if parsing failed.

Precondition:
rawHeader is HeaderLength bytes in length

Implements Protocols::Generics::PacketProtocol.

Definition at line 82 of file PacketProtocol.cpp.

Packet PacketProtocol::getPacketFromTypeByte uchar  byte  )  [static, private]
 

Helper that returns a Packet of type corresponding to bytes.

Definition at line 95 of file PacketProtocol.cpp.

int PacketProtocol::headerLength  )  const [virtual]
 

Returns the length of a BitTorrent packet's header.

Implements Protocols::Generics::PacketProtocol.

Definition at line 45 of file PacketProtocol.cpp.

Packet PacketProtocol::parsedOrBadPacket Packet packet,
const QByteArray &  rawHeader,
const QByteArray &  rawPayload
[static, private]
 

Helper that parses the raw bytes and returns a BadPacket if parsing failed.

Parameters:
packet is the object which to to parse rawHeader and rawPayload.
rawHeader contains the rawHeader bytes.
rawPayload contains the rawPayload bytes.
Returns:
packet after rawHeader and rawPayload were parsed and the parsing succeeded.

A BadPacket initialized with rawHeader and rawPayload if the parsing failed.

Definition at line 149 of file PacketProtocol.cpp.

int PacketProtocol::payloadLength const QByteArray &  header  )  const [virtual]
 

Extracts the payload length encoded in header.

Parameters:
header contains the raw header bytes.
Returns:
The lenght of the payload in bytes as encoded in header.
Precondition:
header must be exactly HeaderLength bytes long.

Implements Protocols::Generics::PacketProtocol.

Definition at line 58 of file PacketProtocol.cpp.


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