mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
jingle_ft: Simplify serialisation.
This commit is contained in:
parent
988b6a6160
commit
e4cfc1b867
1 changed files with 26 additions and 28 deletions
|
@ -108,46 +108,45 @@ impl TryFrom<Element> for File {
|
||||||
impl From<File> for Element {
|
impl From<File> for Element {
|
||||||
fn from(file: File) -> Element {
|
fn from(file: File) -> Element {
|
||||||
let mut root = Element::builder("file")
|
let mut root = Element::builder("file")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT);
|
||||||
.build();
|
|
||||||
if let Some(date) = file.date {
|
if let Some(date) = file.date {
|
||||||
root.append_child(Element::builder("date")
|
root = root.append(Element::builder("date")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT)
|
||||||
.append(date)
|
.append(date)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if let Some(media_type) = file.media_type {
|
if let Some(media_type) = file.media_type {
|
||||||
root.append_child(Element::builder("media-type")
|
root = root.append(Element::builder("media-type")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT)
|
||||||
.append(media_type)
|
.append(media_type)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if let Some(name) = file.name {
|
if let Some(name) = file.name {
|
||||||
root.append_child(Element::builder("name")
|
root = root.append(Element::builder("name")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT)
|
||||||
.append(name)
|
.append(name)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
for (lang, desc) in file.descs.into_iter() {
|
for (lang, desc) in file.descs.into_iter() {
|
||||||
root.append_child(Element::builder("desc")
|
root = root.append(Element::builder("desc")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT)
|
||||||
.attr("xml:lang", lang)
|
.attr("xml:lang", lang)
|
||||||
.append(desc.0)
|
.append(desc.0)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if let Some(size) = file.size {
|
if let Some(size) = file.size {
|
||||||
root.append_child(Element::builder("size")
|
root = root.append(Element::builder("size")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT)
|
||||||
.append(format!("{}", size))
|
.append(format!("{}", size))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if let Some(range) = file.range {
|
if let Some(range) = file.range {
|
||||||
root.append_child(range.into());
|
root = root.append(range);
|
||||||
}
|
}
|
||||||
for hash in file.hashes {
|
for hash in file.hashes {
|
||||||
root.append_child(hash.into());
|
root = root.append(hash);
|
||||||
}
|
}
|
||||||
root
|
root.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -179,10 +178,9 @@ impl TryFrom<Element> for Description {
|
||||||
|
|
||||||
impl From<Description> for Element {
|
impl From<Description> for Element {
|
||||||
fn from(description: Description) -> Element {
|
fn from(description: Description) -> Element {
|
||||||
let file: Element = description.file.into();
|
|
||||||
Element::builder("description")
|
Element::builder("description")
|
||||||
.ns(ns::JINGLE_FT)
|
.ns(ns::JINGLE_FT)
|
||||||
.append(file)
|
.append(description.file)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue