Debian Codegraph @

.cargo/vendor/onenote_parser/src/one/property_set/picture_container.rs

raw
1 use crate::errors::{ErrorKind, Result};
2 use crate::one::property::{simple, PropertyType};
3 use crate::one::property_set::PropertySetId;
4 use crate::onestore::object::Object;
5
6 /// A picture container.
7 ///
8 /// See [\[MS-ONE\] 2.2.36].
9 ///
10 /// [\[MS-ONE\] 2.2.36]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/28112f88-80f5-49b2-8988-d4a66dcc4d80
11 #[derive(Debug)]
12 pub(crate) struct Data {
13 pub(crate) data: Vec<u8>,
14 pub(crate) extension: Option<String>,
15 }
16
17 pub(crate) fn parse(object: &Object) -> Result<Data> {
18 if object.id() != PropertySetId::PictureContainer.as_jcid()
19 && object.id() != PropertySetId::XpsContainer.as_jcid()
20 {
21 return Err(ErrorKind::MalformedOneNoteFileData(
22 format!("unexpected object type: 0x{:X}", object.id().0).into(),
23 )
24 .into());
25 }
26
27 let data = object.file_data().map(|v| v.to_vec()).unwrap_or_default();
28 let extension = simple::parse_string(PropertyType::PictureFileExtension, object)?;
29
30 Ok(Data { data, extension })
31 }