xmpp-parsers: Convert avatar to xso
This commit is contained in:
parent
a2ece705cc
commit
e9b6fd5d8b
1 changed files with 13 additions and 11 deletions
|
|
@ -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.
|
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
||||||
Data, "data", AVATAR_DATA,
|
#[xml(namespace = ns::AVATAR_DATA, name = "data")]
|
||||||
text: (
|
pub struct Data {
|
||||||
/// Vector of bytes representing the avatar’s image.
|
/// Vector of bytes representing the avatar’s 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.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue