From 577fc0845718ed8ad5bebf02a277c0579a817f77 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 17 May 2024 17:58:38 +0200 Subject: wanda: restructure source layout --- source/lib/src/proto/command.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 source/lib/src/proto/command.cpp (limited to 'source/lib/src/proto/command.cpp') diff --git a/source/lib/src/proto/command.cpp b/source/lib/src/proto/command.cpp new file mode 100644 index 0000000..5a669f5 --- /dev/null +++ b/source/lib/src/proto/command.cpp @@ -0,0 +1,47 @@ +#include "wanda/proto/command.hpp" + +namespace wanda::proto +{ + std::optional command::message() const + { + using namespace std::string_literals; + auto const command = [this] { + switch (id) + { + case command_id::change: + return "CHANGE"s; + default: + return ""s; + } + }(); + + auto argument_string = std::string{}; + for (int index = 0ul; index < arguments.size(); ++index) + { + argument_string += (index) ? "," + arguments[index] : arguments[index]; + } + + if (command.empty()) + { + return std::nullopt; + } + + return wanda::proto::message{"C", command, argument_string}; + } + + std::optional make_command(message message) + { + if (message.command == "CHANGE") + { + return {{command_id::change}}; + } + + return std::nullopt; + } + + command make_change_command() + { + return {command_id::change}; + } + +} // namespace wanda::proto \ No newline at end of file -- cgit v1.2.3