Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
abstractdata.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "abstractdata.h"
9#include <QDataStream>
10#include <QMap>
11#include <quasarapp.h>
12#include <QCryptographicHash>
13#include <qaglobalutils.h>
14
15namespace QH {
16namespace PKG {
17
20
22 const DistVersion& ,
23 unsigned int triggerHash) const {
24
25 if (!isValid()) {
26 return false;
27 }
28
29 package.data = toBytes();
30 package.hdr.command = cmd();
31 package.hdr.triggerHash = triggerHash;
32 package.hdr.size = package.data.size();
33
34 package.hdr.hash = package.calcHash();
35
36
37 return package.isValid();
38}
39
41 return true;
42}
43
44QString AbstractData::toString() const {
45 return QString("Type: %0 \n"
46 "Command: %1 \n").
47 arg(cmdString()).
48 arg(cmd());
49}
50
52 fromBytes(pkg.data);
53}
54
58
59
60
61}
62}
The DistVersion class This is information of supported versions of the destinations api.
Definition distversion.h:21
virtual bool toPackage(Package &package, const DistVersion &reqVersion, unsigned int triggerHash=0) const
toPackage This method convert this class object to the package. For more info see Package class.
virtual bool isValid() const
isValid This method check current object to valid.
void fromPakcage(const Package &pkg)
fromPakcage - This method initialize the current object from a package class object.
QString toString() const override
toString - Return a string implementation for this object.
virtual QString cmdString() const =0
cmdString - This is command string of this object, (for generate cmd use macross QH_PACKAGE)
virtual unsigned short cmd() const =0
cmd - This is command of this object, (for generate cmd use macross QH_PACKAGE)
AbstractData()
AbstractData - Base constructor of this object.
The Package struct. This is base structure for transporting data by network between QH nodes....
Definition package.h:23
unsigned int calcHash() const
calcHash This method recalc hash sum for this pacakge.
Definition package.cpp:44
QByteArray data
data This is source data of package.
Definition package.h:33
virtual bool isValid() const
isValid This method validation a current package. Default implementation is checked a header and comp...
Definition package.cpp:18
Header hdr
hdr This is header of package. For more information see the Header struct.
Definition package.h:29
bool fromBytes(const QByteArray &data)
fromBytes This method provide initialization of object from byte array.
QByteArray toBytes() const
toBytes This method convert a current object to bytes array.
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
unsigned int hash
hash This is unique id of a package. id calc with CRC32 function for Qt implementation.
Definition header.h:38
unsigned int triggerHash
triggerHash This is hash of request package that package has been responded. The server should write ...
Definition header.h:44
unsigned int size
size This is size of package data (exclude header size).
Definition header.h:33
unsigned short command
command of package for more information see the AbstractData::toPackage method.
Definition header.h:23