aboutsummaryrefslogtreecommitdiff
path: root/source/include/wanda/message.hpp
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2022-09-16 21:36:12 +0200
committerFelix Morgner <felix.morgner@gmail.com>2022-09-16 21:36:12 +0200
commit64922e213ac731279cf3341253e67509adb2dfc8 (patch)
treeddcf4fd5b05ac426ecf032e43e8662c2f9ce0f57 /source/include/wanda/message.hpp
parentd22bc7b557d36da41fe88d3188a7cd335c3ccaa0 (diff)
downloadwanda-64922e213ac731279cf3341253e67509adb2dfc8.tar.xz
wanda-64922e213ac731279cf3341253e67509adb2dfc8.zip
wanda: restructure source directory
Diffstat (limited to 'source/include/wanda/message.hpp')
-rw-r--r--source/include/wanda/message.hpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/source/include/wanda/message.hpp b/source/include/wanda/message.hpp
new file mode 100644
index 0000000..866408f
--- /dev/null
+++ b/source/include/wanda/message.hpp
@@ -0,0 +1,83 @@
+/**
+ * @file message.hpp
+ * @author Felix Morgner (felix.morgner@gmail.com)
+ * @since 1.0.0
+ */
+
+#ifndef WANDA_MESSAGE_HPP
+#define WANDA_MESSAGE_HPP
+
+#include <cstddef>
+#include <istream>
+#include <optional>
+#include <string>
+
+namespace wanda
+{
+ inline namespace v1
+ {
+ /**
+ * @brief The version argument for the hello message reflecting the current version
+ */
+ auto constexpr message_argument_hello = "1.0.0";
+ } // namespace v1
+
+ /**
+ * @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
+
+#endif \ No newline at end of file