/
Shymer123
/
LumenServer
Обзор
Документация
Войти
/
Shymer123
/
LumenServer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Server/SourceFiles/Core/Network/RequestContext.h
88 строк
2 KB
Shymer123
Initial commit: LumenServer
20 июн 2026, 12:43
20 июн 2026, 12:43
173f14c
Код
Авторство
О чём код?
#ifndef REQUESTCONTEXT_H #define REQUESTCONTEXT_H #include <optional> #include <string> #include <nlohmann/json.hpp> #include <variant> namespace Core::Network { class TcpSession; } namespace Core::Network { enum class RequestType { JSON, FILE }; struct JsonBody { nlohmann::json data; }; struct FileBody { nlohmann::json header; std::vector<std::byte> rawData; }; struct RequestContext { std::optional<std::string> userId; std::variant<JsonBody, FileBody> body; RequestType getType() const { return std::holds_alternative<JsonBody>(body) ? RequestType::JSON : RequestType::FILE; } bool isJson() const { return std::holds_alternative<JsonBody>(body); } bool isFile() const { return std::holds_alternative<FileBody>(body); } std::optional<std::reference_wrapper<nlohmann::json>> json() { if(auto* json = std::get_if<JsonBody>(&body)) { return json->data; } return std::nullopt; } std::optional<std::reference_wrapper<const nlohmann::json>> json() const { if(auto* json = std::get_if<JsonBody>(&body)) { return std::make_optional(std::cref(json->data)); } return std::nullopt; } std::optional<std::reference_wrapper<FileBody>> file() { if(auto* file = std::get_if<FileBody>(&body)) { return *file; } return std::nullopt; } std::optional<std::reference_wrapper<const FileBody>> file() const { if(auto* file = std::get_if<FileBody>(&body)) { return *file; } return std::nullopt; } }; } // namespace Core::Network #endif //REQUESTCONTEXT_H