Files
frelay/Protocol/Protocol.h

61 lines
1.3 KiB
C
Raw Normal View History

2025-06-17 11:48:13 +08:00
#ifndef PROTOCOL_H
#define PROTOCOL_H
#include <QByteArray>
#include <QMetaType>
#include <QSharedPointer>
#include <QString>
#include <functional>
2025-06-17 11:48:13 +08:00
constexpr quint32 CHUNK_BUF_SIZE = 1 * 1024 * 1024;
// It is specified here that the first 30 contents (inclusive) are
// used for communication with the server.
// Contents beyond 30 are only forwarded.
enum FrameBufferType : uint16_t {
2025-06-17 16:42:39 +08:00
FBT_NONE = 0,
2025-06-25 17:06:30 +08:00
FBT_SER_MSG_HEARTBEAT,
2025-06-17 16:42:39 +08:00
FBT_SER_MSG_ASKCLIENTS,
FBT_SER_MSG_YOURID,
FBT_SER_MSG_RESPONSE,
FBT_SER_MSG_FORWARD_FAILED,
2025-06-25 17:06:30 +08:00
FBT_SER_MSG_JUDGE_OTHER_ALIVE,
FBT_SER_MSG_OFFLINE,
FBT_CLI_BIN_FILEDATA = 31,
FBT_CLI_MSG_COMMUNICATE,
FBT_CLI_ASK_DIRFILE,
FBT_CLI_ANS_DIRFILE,
FBT_CLI_ASK_HOME,
2025-06-16 20:06:49 +08:00
FBT_CLI_ANS_HOME,
FBT_CLI_REQ_SEND,
2025-06-17 16:42:39 +08:00
FBT_CLI_CAN_SEND,
FBT_CLI_CANOT_SEND,
FBT_CLI_REQ_DOWN,
FBT_CLI_CAN_DOWN,
FBT_CLI_CANOT_DOWN,
FBT_CLI_FILE_BUFFER,
2025-06-17 11:48:13 +08:00
FBT_CLI_TRANS_DONE,
2025-06-20 09:45:39 +08:00
FBT_CLI_TRANS_FAILED,
FBT_CLI_FILE_INFO
};
struct FrameBuffer {
QByteArray data;
QString fid;
QString tid;
2025-06-17 16:42:39 +08:00
FrameBufferType type = FBT_NONE;
bool sendRet;
};
class Protocol
{
public:
Protocol();
public:
static QSharedPointer<FrameBuffer> ParseBuffer(QByteArray& buffer);
static QByteArray PackBuffer(const QSharedPointer<FrameBuffer>& frame);
};
#endif // PROTOCOL_H