Function libxivdat::section::as_section [−][src]
pub fn as_section(bytes: &[u8]) -> Result<SectionData<'_>, DATError>
Expand description
Interprets a byte slice as SectionData
.
Errors
Returns a DATError::Overflow
or
DATError::Underflow
if the slice length
does not match the content_size specified in the section header.
If the tag or content is not valid utf8 text, a DATError::BadEncoding
error will be returned.
Examples
use libxivdat::dat_file::DATFile; use libxivdat::section::{as_section,SECTION_HEADER_SIZE}; use std::io::Read; let mut dat_file = DATFile::open("./resources/TEST_SECTION.DAT").unwrap(); let mut content_bytes = [0u8; 24 + SECTION_HEADER_SIZE]; dat_file.read_exact(&mut content_bytes).unwrap(); let section = as_section(&content_bytes).unwrap(); assert_eq!(section.tag, "T"); assert_eq!(section.content_size, 24); assert_eq!(section.content, "This is a test section.");