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 ns;
#[derive(Debug, Clone, PartialEq)]
pub struct Range {
pub offset: u64,
pub length: Option<u64>,
pub hashes: Vec<Hash>,
}
impl TryFrom<Element> for Range {
type Err = Error;
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()
}
}
generate_element_with_children!(
#[derive(PartialEq)]
Range, "range", ns::JINGLE_FT,
attributes: [
offset: u64 = "offset" => default,
length: Option<u64> = "length" => optional
],
children: [
hashes: Vec<Hash> = ("hash", ns::HASHES) => Hash
]
);
type Lang = String;