1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::io::Cursor;
use byteorder::{ReadBytesExt, BigEndian};
use std::fmt;
use OggMetadataError;
pub struct Metadata {
pub pixels_width :u32,
pub pixels_height :u32,
}
impl fmt::Debug for Metadata {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "size {}x{}", self.pixels_width, self.pixels_height)
}
}
pub struct IdentHeader {
pub picture_region_width :u32,
pub picture_region_height :u32,
}
#[allow(unused_variables)]
pub fn read_header_ident(packet :&[u8]) -> Result<IdentHeader, OggMetadataError> {
let mut rdr = Cursor::new(packet);
let vmaj = try!(rdr.read_u8());
let vmin = try!(rdr.read_u8());
let vrev = try!(rdr.read_u8());
let fmbw = try!(rdr.read_u16::<BigEndian>());
let fmbh = try!(rdr.read_u16::<BigEndian>());
let picw = try!(rdr.read_uint::<BigEndian>(3)) as u32;
let pich = try!(rdr.read_uint::<BigEndian>(3)) as u32;
let hdr :IdentHeader = IdentHeader {
picture_region_width : picw,
picture_region_height : pich,
};
return Ok(hdr);
}