xmpp-parsers: Convert avatar to xso

This commit is contained in:
Emmanuel Gil Peyrot 2024-07-24 17:27:33 +02:00 committed by Maxime “pep” Buquet
commit e9b6fd5d8b

View file

@ -4,12 +4,14 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use xso::{AsXml, FromXml}; use xso::{
text::{Base64, StripWhitespace},
AsXml, FromXml,
};
use crate::hashes::Sha1HexAttribute; use crate::hashes::Sha1HexAttribute;
use crate::ns; use crate::ns;
use crate::pubsub::PubSubPayload; use crate::pubsub::PubSubPayload;
use crate::util::text_node_codecs::{Codec, WhitespaceAwareBase64};
generate_element!( generate_element!(
/// Communicates information about an avatar. /// Communicates information about an avatar.
@ -51,14 +53,14 @@ pub struct Info {
pub url: Option<String>, pub url: Option<String>,
} }
generate_element!(
/// The actual avatar data. /// The actual avatar data.
Data, "data", AVATAR_DATA, #[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
text: ( #[xml(namespace = ns::AVATAR_DATA, name = "data")]
pub struct Data {
/// Vector of bytes representing the avatars image. /// Vector of bytes representing the avatars image.
data: WhitespaceAwareBase64 #[xml(text(codec = Base64<StripWhitespace>))]
) pub data: Vec<u8>,
); }
impl PubSubPayload for Data {} impl PubSubPayload for Data {}
@ -130,6 +132,6 @@ mod tests {
FromElementError::Invalid(Error::Other(string)) => string, FromElementError::Invalid(Error::Other(string)) => string,
_ => panic!(), _ => panic!(),
}; };
assert_eq!(message, "Unknown attribute in data element.") assert_eq!(message, "Unknown attribute in Data element.")
} }
} }