#include <net_base.h>
#include <util.h>

std::shared_ptr<spdlog::logger> g_Logger;

void TestHandle(CFrameBuffer* buf)
{
    std::string chinese_test("中文测试");
    g_Logger->debug("type: {}", buf->type_);
    g_Logger->info("len: {}", buf->len_);
    g_Logger->warn("{} exec. {} 1", __FUNCTION__, chinese_test);
    g_Logger->error("{} exec. {} 2", __FUNCTION__, chinese_test);
}

int main()
{
    // setlocale(LC_ALL, ".utf-8");
    char buffer[] = "Java";
    g_Logger = get_logger("test1", "test1.log");
    asio::io_context io_context;
    std::shared_ptr<CTcpClient> client = std::make_shared<CTcpClient>(io_context, g_Logger);
    if (!client->connect("127.0.0.1", "8080")) {
        return -1;
    }
    //client->send(buffer, sizeof(buffer));
    client->register_func([](CFrameBuffer* buf) { TestHandle(buf); });
    client->async_recv();
    std::thread t([&io_context]() { io_context.run(); });
    char line[512]{};
    while (std::cin.getline(line, 512)) {
        if (std::strstr(line, "end")) {
            break;
        }
    }
    client->disconnect();
    t.join();
    return 0;
}