+Q_DECLARE_METATYPE(UserId)
+Q_DECLARE_METATYPE(MsgId)
+Q_DECLARE_METATYPE(BufferId)
+Q_DECLARE_METATYPE(NetworkId)
+Q_DECLARE_METATYPE(IdentityId)
+Q_DECLARE_METATYPE(AccountId)
+
+Q_DECLARE_METATYPE(QHostAddress)
+
+// a few typedefs
+using MsgIdList = QList<MsgId>;
+using BufferIdList = QList<BufferId>;
+
+/**
+ * Catch-all stream serialization operator for enum types.
+ *
+ * @param[in,out] out Stream to serialize to
+ * @param[in] value Value to serialize
+ * @returns A reference to the stream
+ */
+template<typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
+QDataStream& operator<<(QDataStream& out, T value)
+{
+ out << static_cast<typename std::underlying_type<T>::type>(value);
+ return out;
+}
+
+/**
+ * Catch-all stream serialization operator for enum types.
+ *
+ * @param[in,out] in Stream to deserialize from
+ * @param[out] value Value to deserialize into
+ * @returns A reference to the stream
+ */
+template<typename T, typename = typename std::enable_if<std::is_enum<T>::value>::type>
+QDataStream& operator>>(QDataStream& in, T& value)
+{
+ typename std::underlying_type<T>::type v;
+ in >> v;
+ value = static_cast<T>(v);
+ return in;
+}
+
+// Exceptions
+
+/**
+ * Thrown during initialization to enforce exiting the application before the event loop is started
+ */
+struct ExitException
+{
+ int exitCode;
+ QString errorString;
+
+ ExitException(int code = EXIT_FAILURE, QString error = {})
+ : exitCode(code)
+ , errorString(std::move(error))
+ {}
+};