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