From ad36468b84c1575fd46824ff02c0308dd9f3e138 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Wed, 9 Oct 2024 19:19:32 +0000 Subject: [PATCH] Add iq types --- library/include/larra/iq.hpp | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 library/include/larra/iq.hpp diff --git a/library/include/larra/iq.hpp b/library/include/larra/iq.hpp new file mode 100644 index 0000000..93b07cd --- /dev/null +++ b/library/include/larra/iq.hpp @@ -0,0 +1,56 @@ +#pragma once +#include +#include +#include +#include + +namespace larra::xmpp { + +namespace iq { + +template +struct BaseImplWithPayload { + std::string id; + PayloadType payload; + static const inline std::string kName = Name; + template + [[nodiscard]] constexpr auto Id(this Self&& self, std::string id) -> std::decay_t { + return utils::FieldSetHelper::With<"id", BaseImplWithPayload>(std::forward(self), std::move(id)); + } + template + [[nodiscard]] constexpr auto Payload(this Self&& self, NewPayloadType value) { + return utils::FieldSetHelper::With<"payload", BaseImplWithPayload, false>(std::forward(self), std::move(value)); + } + friend constexpr auto operator<<(xmlpp::Element* element, const BaseImplWithPayload& self) { + element->set_attribute("id", self.id); + element->set_attribute("type", kName); + using S = Serialization; + S::Serialize(element->add_child_element(S::kDefaultName, S::kPrefix), self.payload); + } +}; +static constexpr auto kGetName = "get"; + +template +using Get = BaseImplWithPayload; + +static constexpr auto kSetName = "set"; + +template +using Set = BaseImplWithPayload; + +static constexpr auto kResultName = "result"; + +template +using Result = BaseImplWithPayload; + +static constexpr auto kErrorName = "error"; + +template +using Error = BaseImplWithPayload; + +} // namespace iq + +template +using Iq = std::variant, iq::Set, iq::Result, iq::Error>; + +} // namespace larra::xmpp