jingle_ft: Parse <range/> using the new helper.
This commit is contained in:
parent
0ead24a041
commit
988b6a6160
1 changed files with 11 additions and 35 deletions
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue