| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::one::property::color::Color; |
| 3 |
use crate::one::property::{simple, PropertyType}; |
| 4 |
use crate::one::property_set::PropertySetId; |
| 5 |
use crate::onestore::object::Object; |
| 6 |
|
| 7 |
/// A section's metadata. |
| 8 |
/// |
| 9 |
/// See [\[MS-ONE\] 2.2.31]. |
| 10 |
/// |
| 11 |
/// [\[MS-ONE\] 2.2.31]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/c8cd2fe2-593b-45f8-8da0-03ca6f6f704d |
| 12 |
#[derive(Debug)] |
| 13 |
pub(crate) struct Data { |
| 14 |
pub(crate) schema_revision_in_order_to_read: u32, |
| 15 |
pub(crate) schema_revision_in_order_to_write: u32, |
| 16 |
pub(crate) display_name: Option<String>, |
| 17 |
pub(crate) color: Option<Color>, |
| 18 |
} |
| 19 |
|
| 20 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 21 |
if object.id() != PropertySetId::SectionMetadata.as_jcid() { |
| 22 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 23 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 24 |
) |
| 25 |
.into()); |
| 26 |
} |
| 27 |
|
| 28 |
let schema_revision_in_order_to_read = |
| 29 |
simple::parse_u32(PropertyType::SchemaRevisionInOrderToRead, object)?.ok_or_else(|| { |
| 30 |
ErrorKind::MalformedOneNoteFileData( |
| 31 |
"section metadata has no schema revision in order to read".into(), |
| 32 |
) |
| 33 |
})?; |
| 34 |
let schema_revision_in_order_to_write = |
| 35 |
simple::parse_u32(PropertyType::SchemaRevisionInOrderToWrite, object)?.ok_or_else( |
| 36 |
|| { |
| 37 |
ErrorKind::MalformedOneNoteFileData( |
| 38 |
"section metadata has no schema revision in order to write".into(), |
| 39 |
) |
| 40 |
}, |
| 41 |
)?; |
| 42 |
let display_name = simple::parse_string(PropertyType::SectionDisplayName, object)?; |
| 43 |
let color = Color::parse(PropertyType::SectionColor, object)?; |
| 44 |
|
| 45 |
let data = Data { |
| 46 |
schema_revision_in_order_to_read, |
| 47 |
schema_revision_in_order_to_write, |
| 48 |
display_name, |
| 49 |
color, |
| 50 |
}; |
| 51 |
|
| 52 |
Ok(data) |
| 53 |
} |