Ggep.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 #ifndef PROTOCOLS__GNUTELLA__PACKETS__EXTENSIONS__GGEP_H
00023 #define PROTOCOLS__GNUTELLA__PACKETS__EXTENSIONS__GGEP_H
00024
00025 #include "Imports.h"
00026
00027 namespace Protocols {
00028 namespace Gnutella {
00029 namespace Packets {
00030 namespace Extensions {
00031
00032 class BinaryReader;
00033 class BinaryWriter;
00034
00036
00045 class Ggep
00046 {
00047 public:
00049 static const uchar LastExtension = 0x80;
00050 static const int MaxIdLength = 8;
00051
00052 enum HeaderFlag
00053 {
00054 Encoding = 0x40,
00055 Compression = 0x20,
00056 Reserved = 0x10,
00057 IDLength = 0x0F
00058 };
00059
00060
00061 Q_DECLARE_FLAGS(HeaderFlags, HeaderFlag)
00062
00063
00064
00067 typedef QByteArray GgepId;
00068
00069 static Ggep * fromId (const GgepId &id,
00070 int flags,
00071 const QByteArray &rawData);
00072
00073 Ggep (int flags);
00074 virtual ~Ggep();
00075 virtual Ggep * copy() const = 0;
00076
00077 virtual GgepId id() const = 0;
00078
00079 bool isFlagSet (HeaderFlag flag) const;
00080 void setFlag (HeaderFlag flag);
00081 void resetFlag (HeaderFlag flag);
00082
00083 bool parse (const QByteArray &);
00084 QByteArray rawData() const;
00085 bool operator== (const Ggep &ggep) const;
00086 bool operator!= (const Ggep &ggep) const;
00087
00088 protected:
00089 virtual void readData (BinaryReader &reader) = 0;
00090 virtual void writeData (BinaryWriter &writer) const = 0;
00091
00092 HeaderFlags flags;
00093 };
00094
00095 Q_DECLARE_OPERATORS_FOR_FLAGS(Ggep::HeaderFlags)
00096
00097 inline bool Ggep::isFlagSet (HeaderFlag flag) const
00098 { return flags & flag; }
00099
00100 inline void Ggep::setFlag (HeaderFlag flag)
00101 { flags |= flag; }
00102
00103 inline void Ggep::resetFlag (HeaderFlag flag)
00104 { flags &= ~flag; }
00105
00106 }
00107 }
00108 }
00109 }
00110
00111 #endif // PROTOCOLS__GNUTELLA__PACKETS__EXTENSIONS__GGEP_H