9#include "qaglobalutils.h"
19 _serializers(serializers) {
21 if (serializers.size()) {
22 _packageVersion.
setMax(serializers.lastKey());
23 _packageVersion.
setMin(serializers.firstKey());
29 if (!_serializers.size()) {
31 "Your MultiversionData not support any serialized functions. "
32 "Please initialize it in constructor of the MultiversionData class.");
39 unsigned short version = 0;
43 stream.device()->seek(0);
46 return _serializers.value(version).from(stream);
51 if (!_serializers.size()) {
53 "Your MultiversionData not support any serialized functions. "
54 "Please initialize it in constructor of the MultiversionData class.");
58 stream << QByteArray{
MAGIC};
59 stream << _serializers.lastKey();
61 return _serializers.last().to(stream);
66 QDataStream stream(&res, QIODevice::WriteOnly);
79 auto serializer = _serializers.value(ver, {});
82 "Your MultiversionData not support the required version serialized functions. "
83 "Please initialize it in constructor of the MultiversionData class.");
88 stream << QByteArray{
MAGIC};
92 return serializer.to(stream);
97 unsigned int triggerHash)
const {
114 return _packageVersion;
The DistVersion class This is information of supported versions of the destinations api.
void setMax(unsigned short newMax)
void setMin(unsigned short newMin)
int getMaxCompatible(const DistVersion &distVersion) const
getMaxСompatible return maximum available on booth nodes version.
virtual bool isValid() const
isValid This method check current object to valid.
virtual unsigned short cmd() const =0
cmd - This is command of this object, (for generate cmd use macross QH_PACKAGE)
QDataStream & toStreamOf(QDataStream &stream, const DistVersion &version) const
toStreamOf This overrload of the base toStream method for support the multi version packages.
QDataStream & fromStream(QDataStream &stream) override final
fromStream This method should be read all bytes from the stream object and full the current object.
QByteArray toBytesOf(const DistVersion &version) const
toBytesOf This is overload method of StreamBase::toBytes for support multi versions of packages.
MultiversionData(const QMap< unsigned short, SerializationBox > &serializers)
MultiversionData main constructor.
bool toPackage(Package &package, const DistVersion &reqVersion, unsigned int triggerHash=0) const override final
toPackage This method convert this class object to the package. For more info see Package class.
const DistVersion & packageVersion() const
packageVersion This method should be return number of the pacakge version.
QDataStream & toStream(QDataStream &stream) const override final
fromStream This method should be write all members of the current object to the stream object.
The Package struct. This is base structure for transporting data by network between QH nodes....
unsigned int calcHash() const
calcHash This method recalc hash sum for this pacakge.
QByteArray data
data This is source data of package.
virtual bool isValid() const
isValid This method validation a current package. Default implementation is checked a header and comp...
Header hdr
hdr This is header of package. For more information see the Header struct.
virtual int parsingVersion() const
parsingVersion this method return parsing version of Qt. By Default is 0 (last available parsing)....
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...