TcpPortPacket.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PROTOCOLS__KAD__PACKETS__TCP__PORT__PACKET
00024 #define PROTOCOLS__KAD__PACKETS__TCP__PORT__PACKET
00025
00026 #include "Imports.h"
00027 #include "Packet.h"
00028
00029 namespace Protocols {
00030 namespace Kad {
00031 namespace Packets {
00032
00034
00040 template <PacketType type>
00041 class TcpPortPacket: public Packet
00042 {
00043 public:
00044 virtual QString name() const;
00045 virtual TcpPortPacket* copy() const;
00046
00047 TcpPortPacket();
00048
00049 protected:
00050 virtual void readPayload (BinaryReader &);
00051 virtual void writePayload (BinaryWriter &) const;
00052
00053 enum Constants
00054 {
00055 PayloadLength = 2,
00056 };
00057
00059
00062 class Data: public Packet::Data
00063 {
00064 Q_SHARED_DATA_COPY (Data);
00065
00066 public:
00067 quint16 tcpPort;
00068 };
00069
00070 Q_DECLARE_SHARED_DATA (Data);
00071
00072 private:
00074 static const QString name_;
00075 };
00076
00078
00082 template <PacketType type>
00083 QString TcpPortPacket <type>::name() const
00084 {
00085 return name_;
00086 }
00087
00089 template <PacketType type>
00090 TcpPortPacket<type>* TcpPortPacket <type>::copy() const
00091 {
00092 return new TcpPortPacket (*this);
00093 }
00094
00096
00101 template <PacketType type>
00102 TcpPortPacket <type>::TcpPortPacket()
00103 : Packet (new Data, type)
00104 {
00105 }
00106
00108
00111 template <PacketType type>
00112 void TcpPortPacket <type>::readPayload (BinaryReader &reader)
00113 {
00114 Q_SD (Data);
00115 d->tcpPort = reader.readUInt16();
00116 }
00117
00119
00122 template <PacketType type>
00123 void TcpPortPacket <type>::writePayload (BinaryWriter &writer) const
00124 {
00125 Q_SD (const Data);
00126 writer.reserve (PayloadLength);
00127 writer.writeUInt16(d->tcpPort);
00128 }
00129
00130 }
00131 }
00132 }
00133
00134 #endif