2025-06-14 09:27:50 +08:00
|
|
|
#ifndef INFO_PACK_HPP
|
|
|
|
|
#define INFO_PACK_HPP
|
|
|
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
|
#include <QDataStream>
|
|
|
|
|
#include <QDebug>
|
2025-11-08 18:11:52 +08:00
|
|
|
#include <QIODevice>
|
2025-06-14 09:27:50 +08:00
|
|
|
|
|
|
|
|
template <typename T> QByteArray infoPack(const T& obj)
|
|
|
|
|
{
|
|
|
|
|
QByteArray byteArray;
|
|
|
|
|
QDataStream stream(&byteArray, QIODevice::ReadWrite);
|
|
|
|
|
obj.serialize(stream);
|
|
|
|
|
stream.device()->seek(0);
|
|
|
|
|
return byteArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T> T infoUnpack(const QByteArray& byteArray)
|
|
|
|
|
{
|
|
|
|
|
T obj;
|
|
|
|
|
QDataStream stream(byteArray);
|
|
|
|
|
obj.deserialize(stream);
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-08 18:11:52 +08:00
|
|
|
#endif // INFO_PACK_HPP
|