From 2612b22d54346b147e9f6f3f233b6b76dd943e42 Mon Sep 17 00:00:00 2001 From: KAMADA Ken'ichi Date: Sat, 19 Nov 2016 20:10:12 +0900 Subject: [PATCH] Parse UNDEFINED fields. --- src/value.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/value.rs b/src/value.rs index f375b51..801ecd5 100644 --- a/src/value.rs +++ b/src/value.rs @@ -46,6 +46,8 @@ pub enum Value<'a> { Rational(Vec), /// Vector of 8-bit signed integers. Unused in the Exif specification. SByte(Vec), + /// Slice of 8-bit bytes. + Undefined(&'a [u8]), /// The type is unknown to this implementation. /// The associated values are the type and the count, and the /// offset of the "Value Offset" element. @@ -73,6 +75,7 @@ pub fn get_type_info<'a, E>(typecode: u16) 4 => (4, parse_long::), 5 => (8, parse_rational::), 6 => (1, parse_sbyte), + 7 => (1, parse_undefined), _ => (0, parse_unknown), } } @@ -132,6 +135,11 @@ fn parse_sbyte<'a>(data: &'a [u8], offset: usize, count: usize) Value::SByte(islice.to_vec()) } +fn parse_undefined<'a>(data: &'a [u8], offset: usize, count: usize) + -> Value<'a> { + Value::Undefined(&data[offset .. offset + count]) +} + // This is a dummy function and will never be called. #[allow(unused_variables)] fn parse_unknown<'a>(data: &'a [u8], offset: usize, count: usize) @@ -253,4 +261,20 @@ mod tests { } } } + + #[test] + fn undefined() { + let sets: &[(&[u8], &[u8])] = &[ + (b"x", b""), + (b"x\xbe\xad", b"\xbe\xad"), + ]; + let (unitlen, parser) = get_type_info::(7); + for &(data, ans) in sets { + assert!((data.len() - 1) % unitlen == 0); + match parser(data, 1, (data.len() - 1) / unitlen) { + Value::Undefined(v) => assert_eq!(v, ans), + v => panic!("wrong variant {:?}", v), + } + } + } }