diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-08-31 11:44:04 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-09-13 16:14:43 +0200 |
commit | 2ca5f6b03fbae4bfe9edd62f04c4a88d273c2ac8 (patch) | |
tree | 02cd9ddc9ff287259956de9282091ca46c3879da /src/buildtool/execution_api/remote/config.hpp | |
parent | ece5187ea8984d31a335ed1078bd421e979f7513 (diff) | |
download | justbuild-2ca5f6b03fbae4bfe9edd62f04c4a88d273c2ac8.tar.gz |
remote: Extract port parsing in own library
Diffstat (limited to 'src/buildtool/execution_api/remote/config.hpp')
-rw-r--r-- | src/buildtool/execution_api/remote/config.hpp | 33 |
1 files changed, 1 insertions, 32 deletions
diff --git a/src/buildtool/execution_api/remote/config.hpp b/src/buildtool/execution_api/remote/config.hpp index 449e9506..e7ad3a57 100644 --- a/src/buildtool/execution_api/remote/config.hpp +++ b/src/buildtool/execution_api/remote/config.hpp @@ -28,38 +28,7 @@ #include <fmt/core.h> #include <nlohmann/json.hpp> -#include "gsl/gsl" -#include "src/buildtool/logging/logger.hpp" -#include "src/utils/cpp/type_safe_arithmetic.hpp" - -// Port -struct PortTag : type_safe_arithmetic_tag<std::uint16_t> {}; -using Port = type_safe_arithmetic<PortTag>; - -[[nodiscard]] static auto ParsePort(int const port_num) noexcept - -> std::optional<Port> { - try { - static constexpr int kMaxPortNumber{ - std::numeric_limits<uint16_t>::max()}; - if (port_num >= 0 and port_num <= kMaxPortNumber) { - return gsl::narrow_cast<Port::value_t>(port_num); - } - } catch (std::out_of_range const& e) { - Logger::Log(LogLevel::Error, "Port raised out_of_range exception."); - } - return std::nullopt; -} - -[[nodiscard]] static auto ParsePort(std::string const& port) noexcept - -> std::optional<Port> { - try { - auto port_num = std::stoi(port); - return ParsePort(port_num); - } catch (std::invalid_argument const& e) { - Logger::Log(LogLevel::Error, "Port raised invalid_argument exception."); - } - return std::nullopt; -} +#include "src/buildtool/common/remote/port.hpp" class RemoteExecutionConfig { public: |