#include #include namespace { inline auto ToOptionalString(const xmlpp::Attribute* attribute) -> std::optional { return attribute ? std::optional{std::string{attribute->get_value()}} : std::nullopt; } template inline auto ToOptionalUser(const xmlpp::Attribute* attribute) { if constexpr(IsJid) { return attribute ? std::optional{larra::xmpp::BareJid::Parse(attribute->get_value())} : std::nullopt; } else { return ToOptionalString(attribute); } } auto ToString(std::string data) -> std::string { return std::move(data); }; } // namespace namespace larra::xmpp { template auto impl::BasicStream::SerializeStream(xmlpp::Element* node) const -> void { if(this->from) { node->set_attribute("from", ToString(*this->from)); } if(this->to) { node->set_attribute("to", ToString(*this->to)); } if(this->id) { node->set_attribute("id", *this->id); } if(this->version) { node->set_attribute("version", *this->version); } if(this->xmlLang) { node->set_attribute("lang", *this->xmlLang, "xml"); } node->set_namespace_declaration("http://etherx.jabber.org/streams", "stream"); } template auto ServerStream::SerializeStream(xmlpp::Element* node) const -> void; template auto ServerToUserStream::SerializeStream(xmlpp::Element* node) const -> void; template auto UserStream::SerializeStream(xmlpp::Element* node) const -> void; template auto impl::BasicStream::Parse(const xmlpp::Element* node) -> impl::BasicStream { return {ToOptionalUser(node->get_attribute("from")), ToOptionalUser(node->get_attribute("to")), ToOptionalString(node->get_attribute("id")), ToOptionalString(node->get_attribute("version")), ToOptionalString(node->get_attribute("lang", "xml"))}; } template auto UserStream::Parse(const xmlpp::Element* node) -> UserStream; template auto ServerStream::Parse(const xmlpp::Element* node) -> ServerStream; template auto ServerToUserStream::Parse(const xmlpp::Element* node) -> ServerToUserStream; } // namespace larra::xmpp