aboutsummaryrefslogtreecommitdiff
path: root/source/lib/include/wanda/proto/message.hpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2024-05-17 17:58:38 +0200
committerFelix Morgner <felix.morgner@gmail.com>2024-05-17 17:58:38 +0200
commit577fc0845718ed8ad5bebf02a277c0579a817f77 (patch)
tree3d1cdc53c426a0ba60a7996619a7b787850bb3b3 /source/lib/include/wanda/proto/message.hpp
parentde5bf7ca3b7a2bf6be35b86486b00dc6a071b950 (diff)
downloadwanda-develop.tar.xz
wanda-develop.zip
wanda: restructure source layoutHEADdevelop
Diffstat (limited to 'source/lib/include/wanda/proto/message.hpp')
-rw-r--r--source/lib/include/wanda/proto/message.hpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/source/lib/include/wanda/proto/message.hpp b/source/lib/include/wanda/proto/message.hpp
new file mode 100644
index 0000000..03a30c2
--- /dev/null
+++ b/source/lib/include/wanda/proto/message.hpp
@@ -0,0 +1,84 @@
+/**
+ * @file message.hpp
+ * @author Felix Morgner (felix.morgner@gmail.com)
+ * @since 1.0.0
+ */
+
+#ifndef WANDA_PROTO_MESSAGE_HPP
+#define WANDA_PROTO_MESSAGE_HPP
+
+#include <spdlog/common.h>
+
+#include <cstddef>
+#include <istream>
+#include <optional>
+#include <string>
+#include <string_view>
+
+namespace wanda::proto
+{
+ /**
+ * @brief A tag to mark messages originating from the controller
+ */
+ auto constexpr message_source_controller = "C";
+
+ /**
+ * @brief A tag to mark messages originating from the daemon
+ */
+ auto constexpr message_source_daemon = "D";
+
+ /**
+ * @brief The command of the hello message
+ */
+ auto constexpr message_command_hello = "HELLO";
+
+ /**
+ * @brief A control protocol message, consisting of a @p source, @p command, and @p arguments
+ */
+ struct message
+ {
+ /**
+ * @brief Serialize this message into a string
+ */
+ explicit operator std::string() const;
+
+ /**
+ * @brief Get the size of the message as if it was serialized
+ */
+ std::size_t size() const;
+
+ /**
+ * @brief The source of the message
+ */
+ std::string source;
+
+ /**
+ * @brief The command of the message
+ */
+ std::string command;
+
+ /**
+ * @brief The arguments of the message command
+ */
+ std::optional<std::string> argument;
+ };
+
+ /**
+ * @brief Deserialize a message from the given stream
+ */
+ std::istream & operator>>(std::istream & in, message & message);
+
+ /**
+ * @brief Serialize a message to the given stream
+ */
+ std::ostream & operator<<(std::ostream & out, message const & message);
+
+} // namespace wanda::proto
+
+template<>
+struct spdlog::fmt_lib::formatter<wanda::proto::message> : spdlog::fmt_lib::formatter<std::string>
+{
+ auto format(wanda::proto::message const & message, format_context & context) const -> decltype(context.out());
+};
+
+#endif \ No newline at end of file