Files
frelay/Struct/InfoMsg.h

76 lines
2.0 KiB
C
Raw Normal View History

2025-06-17 11:48:13 +08:00
#ifndef INFO_MSG_H
2025-06-15 14:31:54 +08:00
#define INFO_MSG_H
#include <QBuffer>
#include <QDataStream>
#include <QIODevice>
#include <QMap>
2025-06-15 14:31:54 +08:00
#include <QString>
#include <QVector>
2025-11-05 23:09:37 +08:00
struct PropertyData {
QString uuid;
QString command;
2025-11-06 23:36:55 +08:00
QString userAction;
QString localPath;
QString remotePath;
2025-11-06 23:36:55 +08:00
qint32 state;
2025-11-06 23:12:13 +08:00
qint32 properE;
2025-11-05 23:09:37 +08:00
};
2025-06-15 14:31:54 +08:00
struct InfoMsg {
qint32 mark{};
2025-11-05 10:57:40 +08:00
QString command;
2025-06-15 14:31:54 +08:00
QString msg;
2025-06-17 16:42:39 +08:00
QString fromPath;
QString toPath;
2025-11-16 19:23:59 +08:00
QString type;
2025-06-17 16:42:39 +08:00
quint64 size{};
quint32 permissions{};
2025-11-05 10:57:40 +08:00
QVector<QString> list;
2025-11-05 23:09:37 +08:00
QMap<QString, PropertyData> mapData;
2025-06-15 14:31:54 +08:00
void serialize(QDataStream& data) const
{
2025-11-16 19:23:59 +08:00
data << mark << command << msg << fromPath << toPath << type << size << permissions;
data << static_cast<qint32>(list.size());
2025-11-05 10:57:40 +08:00
for (const auto& item : list) {
data << item;
}
data << static_cast<qint32>(mapData.size());
for (auto it = mapData.constBegin(); it != mapData.constEnd(); ++it) {
data << it.key();
data << it.value().uuid << it.value().command << it.value().userAction
<< it.value().localPath << it.value().remotePath << it.value().state << it.value().properE;
2025-11-05 23:09:37 +08:00
}
2025-06-15 14:31:54 +08:00
}
void deserialize(QDataStream& data)
{
2025-11-16 19:23:59 +08:00
data >> mark >> command >> msg >> fromPath >> toPath >> type >> size >> permissions;
2025-11-05 10:57:40 +08:00
qint32 listSize;
data >> listSize;
list.resize(listSize);
for (auto& item : list) {
data >> item;
}
2025-11-05 23:09:37 +08:00
qint32 mapSize;
data >> mapSize;
mapData.clear();
2025-11-05 23:09:37 +08:00
for (int i = 0; i < mapSize; ++i) {
QString key;
2025-11-05 23:09:37 +08:00
PropertyData prop;
data >> key;
data >> prop.uuid >> prop.command >> prop.userAction >> prop.localPath
>> prop.remotePath >> prop.state >> prop.properE;
mapData.insert(key, prop);
2025-11-05 23:09:37 +08:00
}
2025-06-15 14:31:54 +08:00
}
};
QDataStream& operator<<(QDataStream& data, const InfoMsg& info);
QDataStream& operator>>(QDataStream& data, InfoMsg& info);
#endif // INFO_MSG_H