6 Commits

Author SHA1 Message Date
Ваше Имя 9ccabcd1eb refactor(common): reorganize type aliases and add application-specific types
Reorganize type aliases into dedicated directories and add application-specific
type definitions for chunk index, file size, frame length, and IDs. Improves
code clarity and type safety.
2025-10-09 23:12:25 +04:00
Ваше Имя aeeb22d351 refactor(aliases): replace std_cstdint with ByteBuffer alias 2025-10-09 15:23:38 +04:00
Ваше Имя a4f103d0c8 feat(boost_asio): add TcpResolver alias for Boost.Asio TCP resolver 2025-10-09 14:38:41 +04:00
Ваше Имя bb99d8d812 feat(aliases): add type aliases for fixed-width integers 2025-10-09 14:35:09 +04:00
Ваше Имя 1e6fecb7bd refactor(aliases): add Boost type aliases 2025-10-09 14:25:54 +04:00
Ваше Имя 88520915dc feat(utils/logger): add logging utility with console and file output 2025-10-08 20:24:17 +04:00
11 changed files with 142 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include <cstdint>
#include <vector>
// Alias for raw byte buffer
using ByteBuffer = std::vector<std::uint8_t>;
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <cstdint>
// Sequential file chunk index
using ChunkIndex = std::uint32_t;
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <cstdint>
// File total size in bytes
using FileSize = std::uint64_t;
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <cstdint>
// Wire length prefix type for a single framed message (big-endian on the wire)
using FrameLength = std::uint32_t;
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <cstdint>
// Client, group, or message ID
using Id = std::uint64_t;
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <boost/asio/io_context.hpp>
// IO Context
using IoContext = boost::asio::io_context;
@@ -0,0 +1,9 @@
#pragma once
#include <boost/asio/ip/tcp.hpp>
// TCP
using TcpSocket = boost::asio::ip::tcp::socket;
using TcpAcceptor = boost::asio::ip::tcp::acceptor;
using TcpEndpoint = boost::asio::ip::tcp::endpoint;
using TcpResolver = boost::asio::ip::tcp::resolver;
@@ -0,0 +1,6 @@
#pragma once
#include <boost/asio/steady_timer.hpp>
// Timers
using SteadyTimer = boost::asio::steady_timer;
@@ -0,0 +1,6 @@
#pragma once
#include <boost/system/error_code.hpp>
// Error handling
using ErrorCode = boost::system::error_code;
+63
View File
@@ -0,0 +1,63 @@
#include "logger.hpp"
#include <boost/date_time/posix_time/posix_time_io.hpp>
void Logger::init(bool toConsole, const std::string_view filePath)
{
using namespace boost::log;
using namespace boost::posix_time;
add_common_attributes();
if (toConsole) {
add_console_log(
std::clog,
keywords::format =
(expressions::stream
<< "["
<< expressions::attr<boost::posix_time::ptime>("TimeStamp")
<< "] "
<< "<" << trivial::severity << "> " << expressions::smessage)
);
}
if (!filePath.empty()) {
add_file_log(
keywords::file_name = filePath,
keywords::auto_flush = true,
keywords::format =
(expressions::stream
<< "["
<< expressions::attr<boost::posix_time::ptime>("TimeStamp")
<< "] "
<< "<" << trivial::severity << "> " << expressions::smessage)
);
}
core::get()->set_filter(trivial::severity >= trivial::info);
}
void Logger::info(const std::string_view msg)
{
BOOST_LOG_TRIVIAL(info) << msg;
}
void Logger::warn(const std::string_view msg)
{
BOOST_LOG_TRIVIAL(warning) << msg;
}
void Logger::error(const std::string_view msg)
{
BOOST_LOG_TRIVIAL(error) << msg;
}
void Logger::debug(const std::string_view msg)
{
BOOST_LOG_TRIVIAL(debug) << msg;
}
void Logger::fatal(const std::string_view msg)
{
BOOST_LOG_TRIVIAL(fatal) << msg;
}
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/file.hpp>
class Logger
{
public:
static void
init(bool toConsole = true, const std::string_view filePath = "");
static void info(const std::string_view msg);
static void warn(const std::string_view msg);
static void error(const std::string_view msg);
static void debug(const std::string_view msg);
static void fatal(const std::string_view msg);
};