mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-04-26 17:54:38 +00:00
change mutiversion methods names
This commit is contained in:
parent
88f4e92ffd
commit
c1ec94bd14
@ -28,12 +28,7 @@ bool AbstractData::toPackage(Package &package,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!toBytesAdaptiveWithVersion(package.data, reqVersion)) {
|
||||
QuasarAppUtils::Params::log("You try send not supported version of packge on the distanation node.",
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
package.data = toBytesOf(reqVersion);
|
||||
package.hdr.command = cmd();
|
||||
package.hdr.triggerHash = triggerHash;
|
||||
package.hdr.size = package.data.size();
|
||||
@ -63,13 +58,22 @@ void AbstractData::fromPakcage(const Package &pkg) {
|
||||
fromBytes(pkg.data);
|
||||
}
|
||||
|
||||
bool AbstractData::toBytesAdaptiveWithVersion(QByteArray& out, unsigned short reqVersion) const {
|
||||
if (reqVersion == ver()) {
|
||||
out = toBytes();
|
||||
return true;
|
||||
QByteArray AbstractData::toBytesOf(unsigned short reqVersion) const {
|
||||
QByteArray res;
|
||||
QDataStream stream(&res, QIODevice::WriteOnly);
|
||||
|
||||
if (parsingVersion()) {
|
||||
stream.setVersion(parsingVersion());
|
||||
}
|
||||
|
||||
return false;
|
||||
toStreamOf(stream, reqVersion);
|
||||
return res;
|
||||
}
|
||||
|
||||
QDataStream &AbstractData::toStreamOf(QDataStream &stream, unsigned short version) const {
|
||||
debug_assert(version == ver(), "from stream should be overload for the multi version packages.");
|
||||
|
||||
return toStream(stream);
|
||||
}
|
||||
|
||||
AbstractData::~AbstractData() {
|
||||
|
@ -180,12 +180,20 @@ public:
|
||||
static QString commandText(){return "NULL";};
|
||||
|
||||
/**
|
||||
* @brief toBytesAdaptiveWithVersion This method should be convert package to rquired version.
|
||||
* @param outputArray This is output byte array after convertation.
|
||||
* @brief toBytesOf This is overload method of StreamBase::toBytes for support multi versions of packages.
|
||||
* @param version This is required version pacakge.
|
||||
* @return true if convertation finished successful.
|
||||
* @return bytes array for package.
|
||||
* @note This is just wrapper method for the AbstractData::toStream method.
|
||||
*/
|
||||
virtual bool toBytesAdaptiveWithVersion(QByteArray& outputArray, unsigned short version) const;
|
||||
QByteArray toBytesOf(unsigned short version) const;
|
||||
|
||||
/**
|
||||
* @brief toStreamOf This overrload of the base toStream method for support the multi version packages.
|
||||
* @param stream this is stream object.
|
||||
* @param version this is custom version of parsing function.
|
||||
* @return stream object.
|
||||
*/
|
||||
virtual QDataStream& toStreamOf(QDataStream& stream, unsigned short version) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
@ -113,15 +113,6 @@ public:
|
||||
_data = newToken;
|
||||
}
|
||||
|
||||
bool toBytesAdaptiveWithVersion(QByteArray& outputArray, unsigned short version) const override {
|
||||
if (AbstractData::toBytesAdaptiveWithVersion(outputArray, version)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
version == ???
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
QDataStream &fromStream(QDataStream &stream) override {
|
||||
|
||||
@ -143,8 +134,8 @@ protected:
|
||||
QDataStream &toStream(QDataStream &stream) const override {
|
||||
stream << static_cast<int>(_packData.size());
|
||||
|
||||
for (const auto &ptr: qAsConst(_packData)) {
|
||||
stream << *ptr;
|
||||
for (const auto &data: qAsConst(_packData)) {
|
||||
stream << *data;
|
||||
}
|
||||
|
||||
stream << _data;
|
||||
@ -152,6 +143,17 @@ protected:
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream &toStreamOf(QDataStream &stream, unsigned short version) const override {
|
||||
stream << static_cast<int>(_packData.size());
|
||||
|
||||
for (const auto &data: qAsConst(_packData)) {
|
||||
data->toStreamOf(stream, version);
|
||||
}
|
||||
|
||||
stream << _data;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<QSharedPointer<Package>> _packData;
|
||||
|
Loading…
x
Reference in New Issue
Block a user