2019-10-08 13:03:13 +03:00
|
|
|
#include "clientprotocol.h"
|
|
|
|
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QVariantMap>
|
|
|
|
#include <map.h>
|
|
|
|
|
|
|
|
namespace ClientProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
Header::Header() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Header::isValid() const {
|
|
|
|
|
|
|
|
if (sizeof (*this) != 4) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-08 18:02:25 +03:00
|
|
|
return true;
|
2019-10-08 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Header::reset() {
|
|
|
|
size = 0;
|
2019-10-08 18:02:25 +03:00
|
|
|
command = 0;
|
|
|
|
triggerCommnad = 0;
|
2019-10-08 13:03:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Package::Package() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Package::isValid() const {
|
|
|
|
if (!hdr.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.size() && hdr.command != data.at(0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hdr.size == static_cast<unsigned int> (data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Package::toBytes() const {
|
|
|
|
QByteArray res;
|
|
|
|
res.append(reinterpret_cast<char*>(const_cast<Header*>(&hdr)),
|
|
|
|
sizeof (hdr));
|
|
|
|
|
|
|
|
res.append(data);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Package::reset() {
|
|
|
|
hdr.reset();
|
|
|
|
data.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initClientProtockol() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|