This commit is contained in:
+13
-2
@@ -463,7 +463,7 @@ impl SubBlock {
|
||||
///
|
||||
/// \\returns An error-code indicating success or failure of the operation.
|
||||
pub fn get_raw_data(&self, tp: RawDataType, size: i32) -> Result<(i32, Vec<u8>), Error> {
|
||||
let mut data = Vec::<u8>::with_capacity(size as usize);
|
||||
let mut data = vec![0u8; size as usize];
|
||||
let size = Box::into_raw(Box::new(size as c_ulong));
|
||||
lib_czi_error(unsafe {
|
||||
libCZI_SubBlockGetRawData(**self, tp as c_int, size, data.as_mut_ptr() as *mut c_void)
|
||||
@@ -510,7 +510,7 @@ impl Attachment {
|
||||
///
|
||||
/// \\returns An error-code indicating success or failure of the operation.
|
||||
pub fn get_raw_data(&self, size: i32) -> Result<(i32, Vec<u8>), Error> {
|
||||
let mut data = Vec::<u8>::with_capacity(size as usize);
|
||||
let mut data = vec![0u8; size as usize];
|
||||
let size = Box::into_raw(Box::new(size as c_ulong));
|
||||
lib_czi_error(unsafe {
|
||||
libCZI_AttachmentGetRawData(**self, size, data.as_mut_ptr() as *mut c_void)
|
||||
@@ -518,6 +518,17 @@ impl Attachment {
|
||||
Ok((unsafe { *Box::from_raw(size) as i32 }, data))
|
||||
}
|
||||
|
||||
/// convenience method that extracts some types of data
|
||||
pub fn get_data(&self) -> Result<AttachmentData, Error> {
|
||||
let (n, _) = self.get_raw_data(0)?;
|
||||
let (_, data) = self.get_raw_data(n)?;
|
||||
Ok(match self.get_info()?.get_content_file_type()?.as_str() {
|
||||
"CZTIMS" | "CZFOC" => AttachmentData::from_float(data.as_slice())?,
|
||||
"CZEXP" | "CZHWS" | "CZMVM" | "CZFBMX" => AttachmentData::from_xml(data.as_slice())?,
|
||||
_ => AttachmentData::Unknown(data),
|
||||
})
|
||||
}
|
||||
|
||||
/// Release the specified attachment object.
|
||||
///
|
||||
/// \\param attachment_object The attachment object to be released.
|
||||
|
||||
Reference in New Issue
Block a user