#pragma once #include "of_util.h" #include #include #include #include #include #include #include #include #include constexpr size_t g_BuffSize = 102400; const size_t MAX_FRAME_SIZE = 10 * g_BuffSize; 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, TYPE_REQUEST_UPDATE_LIST, TYPE_CONFIRM_UPDATE_LIST, TYPE_UNCONFIRM_UPDATE_LIST, TYPE_DONE_UPDATE_LIST, TYPE_FAILED_UPDATE_LIST, TYPE_GET_ID, TYPE_FILE_SIZE }; using namespace ofen; std::shared_ptr get_logger(const std::string& mark, const std::string& log_file); class CFrameBuffer { public: CFrameBuffer(); ~CFrameBuffer(); public: std::string fid_{}; std::string tid_{}; public: FrameType type_{}; char* data_{}; int len_{}; char mark_{}; }; using ExFun_t = std::function; /* 【 transm TCP 数据协议 】 header 2 char: 0xFF 0xFE type 2 char: mark 1 char: from 32 char: to 32 char: len 4 char: data xxxxx: tail 2 char: 0xFF 0xFF */ class CTransProtocal { public: CTransProtocal(); ~CTransProtocal(); public: static CFrameBuffer* parse(CMutBuffer& buffer); static bool pack(CFrameBuffer* buf, char** out_buf, int& len); static void display_progress(float percent); }; inline std::string now_str() { auto now = std::chrono::system_clock::now(); auto time_t_now = std::chrono::system_clock::to_time_t(now); auto milliseconds = std::chrono::duration_cast(now.time_since_epoch()) % 1000; std::ostringstream timestamp; timestamp << std::put_time(std::localtime(&time_t_now), "[%Y-%m-%d %H:%M:%S") << "." << std::setfill('0') << std::setw(3) << milliseconds.count() << "] "; return timestamp.str(); } template void pdebug(const std::string& format, Args&&... args) { fmt::print(fg(fmt::color::steel_blue), now_str() + format + "\n", std::forward(args)...); } template void pinfo(const std::string& format, Args&&... args) { fmt::print(fg(fmt::color::gray), now_str() + format + "\n", std::forward(args)...); } template void pwarn(const std::string& format, Args&&... args) { fmt::print(fg(fmt::color::yellow_green), now_str() + format + "\n", std::forward(args)...); } template void perror(const std::string& format, Args&&... args) { fmt::print(fg(fmt::color::orange_red), now_str() + format + "\n", std::forward(args)...); }