8 #ifndef NETWORKMESSAGE_H_
9 #define NETWORKMESSAGE_H_
11 #define NM_READ_OK (1)
12 #define NM_READ_INCOMPLETE (2)
13 #define NM_READ_FAILED (0)
15 #include <QHostAddress>
19 class QAbstractSocket;
23 #define MSGTYPE(name) static const QByteArray _ ## name ( #name )
47 static const QByteArray
__TRUE(
"1");
48 static const QByteArray
__FALSE(
"0");
70 bool writeMessage(QUdpSocket* socket,
const QHostAddress& address, quint16 port);
71 void reset() { _fields.clear(); _bufferSize = 0; _mode = 0; }
74 bool hasField(QByteArray& key) {
return _fields.contains(key); }
75 QString
getFieldString(
const QByteArray& key)
const {
return QString::fromUtf8(_fields.value(key)); }
76 QByteArray
getFieldBytes(
const QByteArray& key)
const {
return _fields.value(key); }
77 void setField(
const QByteArray& key,
const QByteArray& value) {
if (_mode == 1 || _mode == 2) qFatal(
"setField called in bad state."); _fields.insert(key, value); _mode = 0; }
78 void setField(
const QByteArray& key,
const QString& value) {
setField(key, value.toUtf8()); }
static const QByteArray __TRUE("1")
static const QByteArray __FALSE("0")
void setField(const QByteArray &key, const QString &value)
bool writeMessage(QAbstractSocket *socket)
QString getFieldString(const QByteArray &key) const
bool readComplete() const
bool parseHeader(char *header)
virtual ~NetworkMessage()
int readMessage(QAbstractSocket *socket)
bool hasField(QByteArray &key)
bool writeComplete() const
QHash< QByteArray, QByteArray > _fields
static const QByteArray & _BOOL(bool val)
QByteArray getFieldBytes(const QByteArray &key) const
void setField(const QByteArray &key, const QByteArray &value)
bool parseMessage(char *buffer)
void buildErrorMessage(const QString &error)