Heart/ClientProtocol/clientprotocol.cpp
2019-10-08 18:02:25 +03:00

64 lines
932 B
C++

#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;
}
return true;
}
void Header::reset() {
size = 0;
command = 0;
triggerCommnad = 0;
}
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;
}
}