jingle_ft: Parse <range/> using the new helper.

This commit is contained in:
Emmanuel Gil Peyrot 2017-11-23 16:33:08 +00:00
parent 0ead24a041
commit 988b6a6160

View file

@ -18,41 +18,17 @@ use minidom::{Element, IntoAttributeValue};
use error::Error; use error::Error;
use ns; use ns;
#[derive(Debug, Clone, PartialEq)] generate_element_with_children!(
pub struct Range { #[derive(PartialEq)]
pub offset: u64, Range, "range", ns::JINGLE_FT,
pub length: Option<u64>, attributes: [
pub hashes: Vec<Hash>, offset: u64 = "offset" => default,
} length: Option<u64> = "length" => optional
],
impl TryFrom<Element> for Range { children: [
type Err = Error; hashes: Vec<Hash> = ("hash", ns::HASHES) => Hash
]
fn try_from(elem: Element) -> Result<Range, Error> { );
check_self!(elem, "range", ns::JINGLE_FT);
check_no_unknown_attributes!(elem, "range", ["offset", "length"]);
let mut hashes = vec!();
for child in elem.children() {
hashes.push(Hash::try_from(child.clone())?);
}
Ok(Range {
offset: get_attr!(elem, "offset", default),
length: get_attr!(elem, "length", optional),
hashes: hashes,
})
}
}
impl From<Range> for Element {
fn from(range: Range) -> Element {
Element::builder("range")
.ns(ns::JINGLE_FT)
.attr("offset", if range.offset == 0 { None } else { Some(range.offset) })
.attr("length", range.length)
.append(range.hashes)
.build()
}
}
type Lang = String; type Lang = String;