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

int main()
{
    CFrameBuffer* buf = new CFrameBuffer();
    buf->data_ = new char[256];
    std::memset(buf->data_, 0x0, 256);
    int buf_len = std::snprintf(buf->data_, 256, "%s", "Hello Cplusplus.");
    buf->len_ = buf_len;
    char* data = nullptr;
    int len = 0;
    if (!CTransProtocal::pack(buf, &data, len)) {
        delete buf;
        return -1;
    }
    auto logger = get_logger("test1", "test1.log");
    asio::io_context io_context;
    CTcpClient client(io_context, logger);
    if (!client.connect("127.0.0.1", "8080")) {
        return -1;
    }
    logger->info("send len:{}", len);
    std::cout << client.send(data, len) << std::endl;
    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();

    delete buf;
    return 0;
}