parsers: use derive macros for simple text-based elements
This commit is contained in:
parent
b0803f831b
commit
298bf006bf
3 changed files with 44 additions and 36 deletions
|
@ -4,17 +4,21 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
use crate::iq::{IqGetPayload, IqResultPayload};
|
||||
use crate::util::text_node_codecs::{Codec, JidCodec, Text};
|
||||
use xso::{FromXml, IntoXml};
|
||||
|
||||
generate_element!(
|
||||
/// Request from a client to stringprep/PRECIS a string into a JID.
|
||||
JidPrepQuery, "jid", JID_PREP,
|
||||
text: (
|
||||
/// The potential JID.
|
||||
data: Text
|
||||
)
|
||||
);
|
||||
use jid::Jid;
|
||||
|
||||
use crate::iq::{IqGetPayload, IqResultPayload};
|
||||
use crate::ns;
|
||||
|
||||
/// Request from a client to stringprep/PRECIS a string into a JID.
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::JID_PREP, name = "jid")]
|
||||
pub struct JidPrepQuery {
|
||||
/// The potential JID.
|
||||
#[xml(text)]
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
impl IqGetPayload for JidPrepQuery {}
|
||||
|
||||
|
@ -25,14 +29,14 @@ impl JidPrepQuery {
|
|||
}
|
||||
}
|
||||
|
||||
generate_element!(
|
||||
/// Response from the server with the stringprep’d/PRECIS’d JID.
|
||||
JidPrepResponse, "jid", JID_PREP,
|
||||
text: (
|
||||
/// The JID.
|
||||
jid: JidCodec
|
||||
)
|
||||
);
|
||||
/// Response from the server with the stringprep’d/PRECIS’d JID.
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::JID_PREP, name = "jid")]
|
||||
pub struct JidPrepResponse {
|
||||
/// The JID.
|
||||
#[xml(text)]
|
||||
pub jid: Jid,
|
||||
}
|
||||
|
||||
impl IqResultPayload for JidPrepResponse {}
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
use xso::{FromXml, IntoXml};
|
||||
|
||||
use crate::message::MessagePayload;
|
||||
use crate::util::text_node_codecs::{Codec, Text};
|
||||
use crate::ns;
|
||||
|
||||
generate_element!(
|
||||
/// Container for a set of reactions.
|
||||
|
@ -22,14 +24,14 @@ generate_element!(
|
|||
|
||||
impl MessagePayload for Reactions {}
|
||||
|
||||
generate_element!(
|
||||
/// One emoji reaction.
|
||||
Reaction, "reaction", REACTIONS,
|
||||
text: (
|
||||
/// The text of this reaction.
|
||||
emoji: Text
|
||||
)
|
||||
);
|
||||
/// One emoji reaction.
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::REACTIONS, name = "reaction")]
|
||||
pub struct Reaction {
|
||||
/// The text of this reaction.
|
||||
#[xml(text)]
|
||||
pub emoji: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
//! For vCard updates defined in [XEP-0153](https://xmpp.org/extensions/xep-0153.html),
|
||||
//! see [`vcard_update`][crate::vcard_update] module.
|
||||
|
||||
use xso::{FromXml, IntoXml};
|
||||
|
||||
use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload};
|
||||
use crate::util::text_node_codecs::{Codec, Text, WhitespaceAwareBase64};
|
||||
use crate::util::text_node_codecs::{Codec, WhitespaceAwareBase64};
|
||||
use crate::{ns, Error};
|
||||
use minidom::Element;
|
||||
|
||||
|
@ -30,14 +32,14 @@ generate_element!(
|
|||
]
|
||||
);
|
||||
|
||||
generate_element!(
|
||||
/// The type of the photo.
|
||||
Type, "TYPE", VCARD,
|
||||
text: (
|
||||
/// The type as a plain text string; at least "image/jpeg", "image/gif" and "image/png" SHOULD be supported.
|
||||
data: Text
|
||||
)
|
||||
);
|
||||
/// The type of the photo.
|
||||
#[derive(FromXml, IntoXml, PartialEq, Debug, Clone)]
|
||||
#[xml(namespace = ns::VCARD, name = "TYPE")]
|
||||
pub struct Type {
|
||||
/// The type as a plain text string; at least "image/jpeg", "image/gif" and "image/png" SHOULD be supported.
|
||||
#[xml(text)]
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
generate_element!(
|
||||
/// The binary data of the photo.
|
||||
|
|
Loading…
Reference in a new issue