xso: use values instead of types for text codecs

This allows stateful or configurable codecs without having to express
all configuration in the type name itself. For example, we could have a
Base64 type with configurable Base64 engines without having to duplicate
the Base64 type itself.

(Note that the different engines in the Base64 crate are values, not
types.)
This commit is contained in:
Jonas Schäfer 2024-08-03 10:51:23 +02:00
commit 271c31c9d4
10 changed files with 150 additions and 101 deletions

View file

@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use xso::{
text::{Base64, StripWhitespace},
text::{Base64, StripWhitespace, TextCodec},
AsXml, FromXml,
};
@ -58,7 +58,7 @@ pub struct Info {
#[xml(namespace = ns::AVATAR_DATA, name = "data")]
pub struct Data {
/// Vector of bytes representing the avatars image.
#[xml(text(codec = Base64<StripWhitespace>))]
#[xml(text(codec = Base64.filtered(StripWhitespace)))]
pub data: Vec<u8>,
}

View file

@ -20,7 +20,7 @@ pub struct Handshake {
///
/// If None, it is the successful reply from the server, the stream is now
/// fully established and both sides can now exchange stanzas.
#[xml(text(codec = FixedHex<20>))]
#[xml(text(codec = FixedHex::<20>))]
pub data: Option<[u8; 20]>,
}

View file

@ -15,7 +15,7 @@
use xso::{
error::Error,
text::{Base64, StripWhitespace},
text::{Base64, StripWhitespace, TextCodec},
AsXml, FromXml,
};
@ -50,7 +50,7 @@ pub struct Type {
#[xml(namespace = ns::VCARD, name = "BINVAL")]
pub struct Binval {
/// The actual data.
#[xml(text(codec = Base64<StripWhitespace>))]
#[xml(text(codec = Base64.filtered(StripWhitespace)))]
pub data: Vec<u8>,
}

View file

@ -30,7 +30,7 @@ pub struct VCardUpdate {
#[xml(namespace = ns::VCARD_UPDATE, name = "photo")]
pub struct Photo {
/// The SHA1 hash of the avatar. Empty when there is no photo.
#[xml(text(codec = FixedHex<20>))]
#[xml(text(codec = FixedHex::<20>))]
pub data: Option<[u8; 20]>,
}