transm/util/util.h

59 lines
1.1 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-13 16:59:31 +08:00
constexpr auto gGet = "Get";
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 id_{};
2024-12-11 22:51:43 +08:00
public:
int16_t type_{};
char* data_{};
int len_{};
char mark_{};
2024-12-11 17:00:59 +08:00
};
class SimpleBuffer
{
public:
SimpleBuffer() = default;
~SimpleBuffer();
public:
std::string id_;
char* data_{};
int len_{};
};
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:
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
};