use std::ptr;
use crate::Error;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Page {
pub ptype: u8,
flags: u8,
reserved: u16,
generation: u32,
scn: u32,
pageno: u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct HeaderPage {
pub pag: Page,
pub page_size: u16,
ods_version: u16,
pages: u32,
next_page: u32,
oldest_transaction: u32,
oldest_active: u32,
next_transaction: u32,
sequence: u16,
flags: u16,
create_data: [i32; 2],
attachment_id: u32,
shadow_count: i32,
cpu: u8,
os: u8,
cc: u8,
compatibility_flags: u8,
ods_minor: u16,
end: u16,
page_buffers: u32,
oldest_snapshot: u32,
backup_pages: i32,
cpypt_page: u32,
crypt_plugin: [u8; 32],
att_high: i16,
tra_high: [u8; 4],
data: [u8; 1],
}
impl HeaderPage {
pub fn from_bytes(bytes: [u8; 1024]) -> Result<HeaderPage, Error> {
let hdr: HeaderPage = unsafe { ptr::read(bytes.as_ptr() as *const _) };
if hdr.pag.ptype != 0x01 {
return Err(Error::InvalidPage {
tpe: hdr.pag.ptype,
expected: 0x01,
desc: "header".to_string(),
});
}
Ok(hdr)
}
}