#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DwgSectionLocatorRecord {
pub number: Option<u8>,
pub seeker: i64,
pub size: i64,
}
impl DwgSectionLocatorRecord {
pub fn new(number: Option<u8>) -> Self {
Self {
number,
seeker: 0,
size: 0,
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DwgSectionDescriptor {
pub name: String,
pub page_type: i32,
pub compressed_size: u64,
pub page_count: i32,
pub decompressed_size: u64,
pub compressed_code: i32,
pub section_id: i32,
pub encrypted: i32,
pub local_sections: Vec<DwgLocalSectionMap>,
}
impl DwgSectionDescriptor {
pub fn new(name: &str) -> Self {
Self {
name: name.to_string(),
page_type: super::section_definition::PAGE_TYPE_DATA_SECTION,
compressed_size: 0,
page_count: 0,
decompressed_size: 0x7400,
compressed_code: 2, section_id: 0,
encrypted: 0,
local_sections: Vec::new(),
}
}
pub fn is_compressed(&self) -> bool {
self.compressed_code == 2
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DwgLocalSectionMap {
pub compression: i32,
pub page_number: i32,
pub offset: u64,
pub compressed_size: u64,
pub decompressed_size: u64,
pub seeker: i64,
pub size: i64,
pub checksum: u32,
pub oda: u32,
pub section_map: i32,
pub page_size: i64,
}
impl DwgLocalSectionMap {
pub fn new() -> Self {
Self {
compression: 2,
page_number: 0,
offset: 0,
compressed_size: 0,
decompressed_size: 0,
seeker: 0,
size: 0,
checksum: 0,
oda: 0,
section_map: 0,
page_size: 0,
}
}
pub fn with_section_map(section_map: i32) -> Self {
let mut map = Self::new();
map.section_map = section_map;
map
}
}
impl Default for DwgLocalSectionMap {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_section_locator_record() {
let record = DwgSectionLocatorRecord::new(Some(2));
assert_eq!(record.number, Some(2));
assert_eq!(record.seeker, 0);
assert_eq!(record.size, 0);
}
#[test]
fn test_section_descriptor_defaults() {
let desc = DwgSectionDescriptor::new("AcDb:Header");
assert_eq!(desc.name, "AcDb:Header");
assert_eq!(desc.decompressed_size, 0x7400);
assert_eq!(desc.compressed_code, 2);
assert!(desc.is_compressed());
assert_eq!(desc.page_type, 0x4163043B);
}
#[test]
fn test_section_descriptor_uncompressed() {
let mut desc = DwgSectionDescriptor::new("AcDb:Header");
desc.compressed_code = 1;
assert!(!desc.is_compressed());
}
#[test]
fn test_local_section_map_defaults() {
let map = DwgLocalSectionMap::new();
assert_eq!(map.compression, 2);
assert_eq!(map.page_number, 0);
}
}