aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/xep_0115.rs
blob: 1c2ef69302a7054953950443442f40835f15a10f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use peanuts::{
    element::{FromElement, IntoElement},
    Element,
};

pub const XMLNS: &str = "http://jabber.org/protocol/caps";

#[derive(Debug, Clone)]
pub struct C {
    pub ext: Option<String>,
    pub hash: String,
    pub node: String,
    pub ver: String,
}

impl FromElement for C {
    fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
        element.check_name("c")?;
        element.check_namespace(XMLNS)?;

        let ext = element.attribute_opt("ext")?;
        let hash = element.attribute("hash")?;
        let node = element.attribute("node")?;
        let ver = element.attribute("ver")?;

        Ok(Self {
            ext,
            hash,
            node,
            ver,
        })
    }
}

impl IntoElement for C {
    fn builder(&self) -> peanuts::element::ElementBuilder {
        Element::builder("c", Some(XMLNS))
            .push_attribute_opt("ext", self.ext.clone())
            .push_attribute("hash", self.hash.clone())
            .push_attribute("node", self.node.clone())
            .push_attribute("ver", self.ver.clone())
    }
}