transm/util/util.h

68 lines
1.3 KiB
C
Raw Normal View History

2024-12-11 22:51:43 +08:00
#pragma once
#include "of_util.h"
#include <cstdint>
2024-12-12 23:11:55 +08:00
#include <functional>
2024-12-11 10:22:14 +08:00
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
2024-12-14 23:59:13 +08:00
constexpr int g_BuffSize = 102400;
enum FrameType : int16_t {
TYPE_DEFAULT = 0,
TYPE_GET_LIST,
TYPE_DOWN_LIST,
TYPE_UP_LIST,
TYPE_CANCEL_LIST,
TYPE_OPEN_FILE,
TYPE_TRANS_FILE,
TYPE_TRANS_DONE,
TYPE_INTERRUPT,
TYPE_NO_HIT_TASK,
TYPE_WAITTING,
TYPE_HEARTS,
TYPE_OFFLINE,
TYPE_JUDGE_ACTIVE
};
2024-12-11 10:22:14 +08:00
2024-12-11 17:00:59 +08:00
using namespace ofen;
2024-12-11 10:22:14 +08:00
std::shared_ptr<spdlog::logger> get_logger(const std::string& mark, const std::string& log_file);
2024-12-11 17:00:59 +08:00
class CFrameBuffer
{
public:
CFrameBuffer();
~CFrameBuffer();
2024-12-12 23:11:55 +08:00
public:
std::string fid_{};
std::string tid_{};
2024-12-11 22:51:43 +08:00
public:
FrameType type_{};
2024-12-11 22:51:43 +08:00
char* data_{};
int len_{};
char mark_{};
2024-12-11 17:00:59 +08:00
};
2024-12-12 23:11:55 +08:00
using ExFun_t = std::function<void(CFrameBuffer* buf)>;
2024-12-11 17:00:59 +08:00
/*
transm TCP
header 2 char: 0xFF 0xFE
type 2 char:
mark 1 char:
from 32 char:
to 32 char:
2024-12-11 17:00:59 +08:00
len 4 char:
data xxxxx:
tail 2 char: 0xFF 0xFF
*/
class CTransProtocal
{
public:
CTransProtocal();
~CTransProtocal();
2024-12-11 17:00:59 +08:00
public:
2024-12-11 22:51:43 +08:00
static CFrameBuffer* parse(CMutBuffer& buffer);
static bool pack(CFrameBuffer* buf, char** out_buf, int& len);
2024-12-13 16:59:31 +08:00
};