Function derp::nested
[−]
[src]
pub fn nested<'a, F, R>(
input: &mut Reader<'a>,
tag: Tag,
decoder: F
) -> Result<R> where
F: FnOnce(&mut Reader<'a>) -> Result<R>,
Return the value of the given tag and apply a decoding function to it.
extern crate derp; extern crate untrusted; use derp::Tag; use untrusted::Input; const NESTED: &'static [u8] = &[ 0x30, 0x14, // seq 0x30, 0x0c, // seq 0x02, 0x04, 0x0a, 0x0b, 0x0c, 0x0d, // x 0x02, 0x04, 0x1a, 0x1b, 0x1c, 0x1d, // y 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, // z ]; fn main () { let input = Input::from(NESTED); let (x, y, z) = input.read_all(derp::Error::Read, |input| { derp::nested(input, Tag::Sequence, |input| { let (x, y) = derp::nested(input, Tag::Sequence, |input| { let x = derp::positive_integer(input)?; let y = derp::positive_integer(input)?; Ok((x, y)) })?; let z = derp::positive_integer(input)?; Ok((x, y, z)) }) }).unwrap(); assert_eq!(x, Input::from(&[0x0a, 0x0b, 0x0c, 0x0d])); assert_eq!(y, Input::from(&[0x1a, 0x1b, 0x1c, 0x1d])); assert_eq!(z, Input::from(&[0x01, 0x02, 0x03, 0x04])); }