Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
///
|
|
|
|
|
/// File-level read/write functionality.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
|
2026-11-16 20:44:48 -08:00
|
|
|
use crate::record::{RecordHeader, Record};
|
|
|
|
|
use crate::records;
|
|
|
|
|
use crate::elements::{read_elements, scan_elements, DListBuilder, FListBuilder, ScanRefRecord};
|
2026-11-16 21:28:54 -08:00
|
|
|
use crate::basic::{ErrType, IResult, OResult, decode_utf8, take_bytes, fail};
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
|
|
|
|
|
use std::string::String;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use arrow_schema::{DataType, Field, Fields};
|
|
|
|
|
use arrow_array::{
|
|
|
|
|
StructArray,
|
|
|
|
|
builder::{
|
|
|
|
|
BooleanBuilder, Float64Builder, Int16Builder, StringBuilder, StructBuilder,
|
|
|
|
|
UInt32Builder, UInt64Builder,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
/// Representation of the GDS file header.
|
|
|
|
|
///
|
|
|
|
|
/// File header records: HEADER BGNLIB LIBNAME UNITS
|
|
|
|
|
/// Optional records are ignored if present and never written.
|
|
|
|
|
///
|
|
|
|
|
/// Version is written as `600`.
|
|
|
|
|
///
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct FileHeader {
|
|
|
|
|
/// Number of user units in one database unit
|
|
|
|
|
user_units_per_db_unit: f64,
|
|
|
|
|
/// Number of meters in one database unit
|
|
|
|
|
meters_per_db_unit: f64,
|
|
|
|
|
/// Last-modified time [y, m, d, h, m, s]
|
|
|
|
|
mod_time: [i16; 6],
|
|
|
|
|
/// Last-accessed time [y, m, d, h, m, s]
|
|
|
|
|
acc_time: [i16; 6],
|
|
|
|
|
/// Library name
|
|
|
|
|
name: Vec<u8>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FileHeader {
|
|
|
|
|
pub fn new(name: &[u8], meters_per_db_unit: f64, user_units_per_db_unit: f64) -> Self {
|
|
|
|
|
FileHeader{
|
|
|
|
|
mod_time: [0, 1, 1, 0, 0, 0],
|
|
|
|
|
acc_time: [0, 1, 1, 0, 0, 0],
|
|
|
|
|
name: name.to_owned(),
|
|
|
|
|
user_units_per_db_unit,
|
|
|
|
|
meters_per_db_unit,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Read and construct a header from the provided input.
|
|
|
|
|
///
|
|
|
|
|
/// Args:
|
|
|
|
|
/// input: Seekable input to read from
|
|
|
|
|
///
|
|
|
|
|
/// Returns:
|
|
|
|
|
/// FileHeader object
|
|
|
|
|
///
|
|
|
|
|
pub fn read(input: &[u8]) -> IResult<'_, Self> {
|
|
|
|
|
let (input, _version) = records::HEADER::read(input)?;
|
|
|
|
|
let (input, [mod_time, acc_time]) = records::BGNLIB::read(input)?;
|
|
|
|
|
let (input, name) = records::LIBNAME::skip_and_read(input)?;
|
|
|
|
|
let (input, (uu, dbu)) = records::UNITS::skip_and_read(input)?;
|
|
|
|
|
|
|
|
|
|
Ok((input, FileHeader{
|
|
|
|
|
mod_time,
|
|
|
|
|
acc_time,
|
|
|
|
|
name,
|
|
|
|
|
user_units_per_db_unit: uu,
|
|
|
|
|
meters_per_db_unit: dbu,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Write the header to a input
|
|
|
|
|
///
|
|
|
|
|
/// Args:
|
|
|
|
|
/// input: input to write to
|
|
|
|
|
///
|
|
|
|
|
/// Returns:
|
|
|
|
|
/// number of bytes written
|
|
|
|
|
///
|
|
|
|
|
pub fn write<W: Write>(&self, ww: &mut W) -> OResult {
|
|
|
|
|
let mut size = 0;
|
|
|
|
|
size += records::HEADER::write(ww, &600)?;
|
|
|
|
|
size += records::BGNLIB::write(ww, &[self.mod_time, self.acc_time])?;
|
|
|
|
|
size += records::LIBNAME::write(ww, &self.name)?;
|
|
|
|
|
size += records::UNITS::write(ww, &(self.user_units_per_db_unit, self.meters_per_db_unit))?;
|
|
|
|
|
Ok(size)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn make_name_list_type() -> DataType {
|
|
|
|
|
DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(DataType::Utf8, false)
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn make_time_type() -> DataType {
|
|
|
|
|
DataType::FixedSizeList(Arc::new(
|
|
|
|
|
Field::new_list_field(DataType::Int16, false),
|
|
|
|
|
),
|
|
|
|
|
6,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn make_top_level_builder(cells_field: Field, extra_fields: Vec<Field>) -> StructBuilder {
|
|
|
|
|
let mut fields = vec![
|
|
|
|
|
Field::new("meters_per_db_unit", DataType::Float64, false),
|
|
|
|
|
Field::new("user_units_per_db_unit", DataType::Float64, false),
|
|
|
|
|
Field::new("lib_name", DataType::Utf8, false),
|
|
|
|
|
Field::new("mod_time", make_time_type(), false),
|
|
|
|
|
Field::new("acc_time", make_time_type(), false),
|
|
|
|
|
cells_field,
|
|
|
|
|
Field::new("cell_names", make_name_list_type(), false),
|
|
|
|
|
];
|
|
|
|
|
fields.extend(extra_fields);
|
|
|
|
|
StructBuilder::from_fields(fields, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn reference_type(is_array: bool, properties: Option<&DataType>) -> DataType {
|
|
|
|
|
let mut fields = vec![
|
|
|
|
|
Field::new("target", DataType::UInt32, false),
|
|
|
|
|
Field::new("invert_y", DataType::Boolean, false),
|
|
|
|
|
Field::new("scale", DataType::Float64, false),
|
|
|
|
|
Field::new("angle_rad", DataType::Float64, false),
|
|
|
|
|
Field::new("xy", DataType::UInt64, false),
|
|
|
|
|
];
|
|
|
|
|
if is_array {
|
|
|
|
|
fields.extend([
|
|
|
|
|
Field::new("xy0", DataType::UInt64, false),
|
|
|
|
|
Field::new("xy1", DataType::UInt64, false),
|
|
|
|
|
Field::new("counts", DataType::UInt32, false),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
if let Some(properties) = properties {
|
|
|
|
|
fields.push(Field::new("properties", properties.clone(), true));
|
|
|
|
|
}
|
|
|
|
|
DataType::Struct(Fields::from(fields))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn make_library_builder() -> StructBuilder {
|
|
|
|
|
let property_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("key", DataType::Int16, false),
|
|
|
|
|
Field::new("value", DataType::Utf8, false),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let property_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(property_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let sref_struct_t = reference_type(false, None);
|
|
|
|
|
let aref_struct_t = reference_type(true, None);
|
|
|
|
|
let sref_prop_struct_t = reference_type(false, Some(&property_list_t));
|
|
|
|
|
let aref_prop_struct_t = reference_type(true, Some(&property_list_t));
|
|
|
|
|
|
|
|
|
|
let text_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("layer", DataType::UInt32, false),
|
|
|
|
|
Field::new("presentation_horiz", DataType::UInt8, true),
|
|
|
|
|
Field::new("presentation_vert", DataType::UInt8, true),
|
|
|
|
|
Field::new("presentation_font", DataType::UInt8, true),
|
|
|
|
|
Field::new("path_type", DataType::Int16, true),
|
|
|
|
|
Field::new("width", DataType::Int32, true),
|
|
|
|
|
Field::new("invert_y", DataType::Boolean, true),
|
|
|
|
|
Field::new("mag", DataType::Float64, true),
|
|
|
|
|
Field::new("angle_deg", DataType::Float64, true),
|
|
|
|
|
Field::new("xy", DataType::UInt64, false),
|
|
|
|
|
Field::new("string", DataType::Utf8, false),
|
|
|
|
|
Field::new("properties", property_list_t.clone(), true),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let coords_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(DataType::Int32, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let boundary_batch_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("layer", DataType::UInt32, false),
|
|
|
|
|
Field::new("vertices", coords_t.clone(), false),
|
|
|
|
|
Field::new(
|
|
|
|
|
"vertex_offsets",
|
|
|
|
|
DataType::List(Arc::new(Field::new_list_field(DataType::UInt32, false))),
|
|
|
|
|
false,
|
|
|
|
|
),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let rect_batch_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("layer", DataType::UInt32, false),
|
|
|
|
|
Field::new("rects", coords_t.clone(), false),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let boundary_prop_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("layer", DataType::UInt32, false),
|
|
|
|
|
Field::new("vertices", coords_t.clone(), false),
|
|
|
|
|
Field::new("properties", property_list_t.clone(), true),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let path_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("layer", DataType::UInt32, false),
|
|
|
|
|
Field::new("path_type", DataType::Int16, true),
|
|
|
|
|
Field::new("extension_start", DataType::Int32, true),
|
|
|
|
|
Field::new("extension_end", DataType::Int32, true),
|
|
|
|
|
Field::new("width", DataType::Int32, true),
|
|
|
|
|
Field::new("xy", coords_t.clone(), false),
|
|
|
|
|
Field::new("properties", property_list_t.clone(), true),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let boxnode_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("layer", DataType::UInt32, false),
|
|
|
|
|
Field::new("xy", coords_t.clone(), false),
|
|
|
|
|
Field::new("properties", property_list_t.clone(), true),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let sref_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(sref_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let aref_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(aref_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let sref_prop_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(sref_prop_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let aref_prop_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(aref_prop_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let text_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(text_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let boundary_batch_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(boundary_batch_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let rect_batch_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(rect_batch_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let boundary_prop_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(boundary_prop_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let path_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(path_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let boxnode_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(boxnode_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let layer_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(DataType::UInt32, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let cell_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("id", DataType::UInt32, false),
|
|
|
|
|
Field::new("file_offset", DataType::UInt64, false),
|
|
|
|
|
Field::new("srefs", sref_list_t, false),
|
|
|
|
|
Field::new("arefs", aref_list_t, false),
|
|
|
|
|
Field::new("sref_props", sref_prop_list_t, false),
|
|
|
|
|
Field::new("aref_props", aref_prop_list_t, false),
|
|
|
|
|
Field::new("rect_batches", rect_batch_list_t, false),
|
|
|
|
|
Field::new("boundary_batches", boundary_batch_list_t, false),
|
|
|
|
|
Field::new("boundary_props", boundary_prop_list_t, false),
|
|
|
|
|
Field::new("paths", path_list_t, false),
|
|
|
|
|
Field::new("nodes", boxnode_list_t.clone(), true),
|
|
|
|
|
Field::new("boxes", boxnode_list_t.clone(), true),
|
|
|
|
|
Field::new("texts", text_list_t, false),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let cells_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(cell_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
make_top_level_builder(
|
|
|
|
|
Field::new("cells", cells_list_t, false),
|
|
|
|
|
vec![
|
|
|
|
|
Field::new("layers", layer_list_t, false),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn make_scan_builder() -> StructBuilder {
|
|
|
|
|
let scan_ref_struct_t = reference_type(true, None);
|
|
|
|
|
|
|
|
|
|
let scan_ref_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(scan_ref_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let scan_cell_struct_t = DataType::Struct(Fields::from(vec![
|
|
|
|
|
Field::new("id", DataType::UInt32, false),
|
|
|
|
|
Field::new("struct_start_offset", DataType::UInt64, false),
|
|
|
|
|
Field::new("struct_end_offset", DataType::UInt64, false),
|
|
|
|
|
Field::new("refs", scan_ref_list_t, false),
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
let scan_cells_list_t = DataType::List(Arc::new(
|
|
|
|
|
Field::new_list_field(scan_cell_struct_t, false)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
make_top_level_builder(
|
|
|
|
|
Field::new("cells", scan_cells_list_t, false),
|
|
|
|
|
Vec::new(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_file_header(
|
|
|
|
|
lib_builder: &mut StructBuilder,
|
|
|
|
|
header: &FileHeader,
|
2026-11-16 21:28:54 -08:00
|
|
|
) -> Result<(), ErrType> {
|
|
|
|
|
let name = decode_utf8(header.name.clone())?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let dbu_builder = lib_builder.field_builder::<Float64Builder>(0).unwrap();
|
|
|
|
|
dbu_builder.append_value(header.meters_per_db_unit);
|
|
|
|
|
let uu_builder = lib_builder.field_builder::<Float64Builder>(1).unwrap();
|
|
|
|
|
uu_builder.append_value(header.user_units_per_db_unit);
|
|
|
|
|
let libname_builder = lib_builder.field_builder::<StringBuilder>(2).unwrap();
|
2026-11-16 21:28:54 -08:00
|
|
|
libname_builder.append_value(name);
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let mtl_builder = lib_builder.field_builder::<FListBuilder>(3).unwrap();
|
|
|
|
|
let mt_builder = mtl_builder.values().as_any_mut().downcast_mut::<Int16Builder>().unwrap();
|
|
|
|
|
mt_builder.append_values(&header.mod_time, &[true; 6]);
|
|
|
|
|
mtl_builder.append(true);
|
|
|
|
|
let atl_builder = lib_builder.field_builder::<FListBuilder>(4).unwrap();
|
|
|
|
|
let at_builder = atl_builder.values().as_any_mut().downcast_mut::<Int16Builder>().unwrap();
|
|
|
|
|
at_builder.append_values(&header.acc_time, &[true; 6]);
|
|
|
|
|
atl_builder.append(true);
|
2026-11-16 21:28:54 -08:00
|
|
|
Ok(())
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_names(
|
|
|
|
|
lib_builder: &mut StructBuilder,
|
|
|
|
|
field_index: usize,
|
|
|
|
|
names: HashMap<String, u32>,
|
|
|
|
|
) {
|
|
|
|
|
// Interned IDs are consecutive, so a vector directly represents ID order.
|
|
|
|
|
let mut ordered_names = vec![String::new(); names.len()];
|
|
|
|
|
for (name, id) in names {
|
|
|
|
|
ordered_names[id as usize] = name;
|
|
|
|
|
}
|
|
|
|
|
let names_builder = lib_builder.field_builder::<DListBuilder>(field_index).unwrap();
|
|
|
|
|
let name_builder = names_builder.values().as_any_mut().downcast_mut::<StringBuilder>().unwrap();
|
|
|
|
|
for name in ordered_names {
|
|
|
|
|
name_builder.append_value(name);
|
|
|
|
|
}
|
|
|
|
|
names_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_layers(
|
|
|
|
|
lib_builder: &mut StructBuilder,
|
|
|
|
|
layers: HashMap<u32, u32>,
|
|
|
|
|
) {
|
|
|
|
|
let mut ordered_layers = vec![0; layers.len()];
|
|
|
|
|
for (layer, id) in layers {
|
|
|
|
|
ordered_layers[id as usize] = layer;
|
|
|
|
|
}
|
|
|
|
|
let layers_builder = lib_builder.field_builder::<DListBuilder>(7).unwrap();
|
|
|
|
|
let layer_builder = layers_builder.values().as_any_mut().downcast_mut::<UInt32Builder>().unwrap();
|
|
|
|
|
layer_builder.append_slice(&ordered_layers);
|
|
|
|
|
layers_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_scan_ref(
|
|
|
|
|
refs_builder: &mut DListBuilder,
|
|
|
|
|
scan_ref: ScanRefRecord,
|
|
|
|
|
) {
|
|
|
|
|
let ref_builder = refs_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
let target_builder = ref_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
target_builder.append_value(scan_ref.target_id);
|
|
|
|
|
let invert_builder = ref_builder.field_builder::<BooleanBuilder>(1).unwrap();
|
|
|
|
|
invert_builder.append_value(scan_ref.invert_y);
|
|
|
|
|
let scale_builder = ref_builder.field_builder::<Float64Builder>(2).unwrap();
|
|
|
|
|
scale_builder.append_value(scan_ref.scale);
|
|
|
|
|
let angle_builder = ref_builder.field_builder::<Float64Builder>(3).unwrap();
|
|
|
|
|
angle_builder.append_value(scan_ref.angle_rad);
|
|
|
|
|
let xy_builder = ref_builder.field_builder::<UInt64Builder>(4).unwrap();
|
|
|
|
|
xy_builder.append_value(scan_ref.xy);
|
|
|
|
|
let xy0_builder = ref_builder.field_builder::<UInt64Builder>(5).unwrap();
|
|
|
|
|
xy0_builder.append_value(scan_ref.xy0);
|
|
|
|
|
let xy1_builder = ref_builder.field_builder::<UInt64Builder>(6).unwrap();
|
|
|
|
|
xy1_builder.append_value(scan_ref.xy1);
|
|
|
|
|
let counts_builder = ref_builder.field_builder::<UInt32Builder>(7).unwrap();
|
|
|
|
|
counts_builder.append_value(scan_ref.counts);
|
|
|
|
|
ref_builder.append(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn intern_name(names: &mut HashMap<String, u32>, name: String) -> u32 {
|
|
|
|
|
let next_id = names.len();
|
|
|
|
|
*names.entry(name).or_insert(next_id.try_into().unwrap())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn append_full_cell<'a>(
|
|
|
|
|
cells_builder: &mut DListBuilder,
|
|
|
|
|
names: &mut HashMap<String, u32>,
|
|
|
|
|
layers: &mut HashMap<u32, u32>,
|
|
|
|
|
struct_input: &'a [u8],
|
|
|
|
|
id: u32,
|
|
|
|
|
file_offset: u64,
|
|
|
|
|
) -> IResult<'a, ()> {
|
|
|
|
|
let cell_builder = cells_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
let id_builder = cell_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
id_builder.append_value(id);
|
|
|
|
|
|
|
|
|
|
let offset_builder = cell_builder.field_builder::<UInt64Builder>(1).unwrap();
|
|
|
|
|
offset_builder.append_value(file_offset);
|
|
|
|
|
|
|
|
|
|
let (next_input, _) = read_elements(struct_input, cell_builder, names, layers)?;
|
|
|
|
|
cell_builder.append(true);
|
|
|
|
|
Ok((next_input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn walk_structs<'a, F>(
|
|
|
|
|
input: &'a [u8],
|
|
|
|
|
base_offset: usize,
|
|
|
|
|
names: &mut HashMap<String, u32>,
|
|
|
|
|
mut on_struct: F,
|
|
|
|
|
) -> IResult<'a, ()>
|
|
|
|
|
where
|
|
|
|
|
F: FnMut(&'a [u8], usize, u32, &mut HashMap<String, u32>) -> IResult<'a, ()>,
|
|
|
|
|
{
|
|
|
|
|
let input_size = input.len();
|
|
|
|
|
let (mut input, mut header) = RecordHeader::read(input)?;
|
|
|
|
|
while header.tag != records::RTAG_ENDLIB {
|
|
|
|
|
let record_start = base_offset + input_size - input.len() - 4;
|
|
|
|
|
if header.tag == records::RTAG_BGNSTR {
|
2026-11-16 21:28:54 -08:00
|
|
|
(input, _) = records::BGNSTR::read_data(input, header.data_size)?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let name_bytes;
|
|
|
|
|
(input, name_bytes) = records::STRNAME::read(input)?;
|
2026-11-16 21:28:54 -08:00
|
|
|
let name = decode_utf8(name_bytes).map_err(|error| (input, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let id = intern_name(names, name);
|
|
|
|
|
let (next_input, ()) = on_struct(input, record_start, id, names)?;
|
|
|
|
|
input = next_input;
|
2026-11-16 21:28:54 -08:00
|
|
|
} else {
|
|
|
|
|
(input, _) = take_bytes(input, header.data_size)?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
}
|
|
|
|
|
(input, header) = RecordHeader::read(input)?;
|
|
|
|
|
}
|
|
|
|
|
Ok((input, ()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn read_library(input: &[u8]) -> IResult<'_, StructArray> {
|
|
|
|
|
let full_input_size = input.len();
|
|
|
|
|
let mut lib_builder = make_library_builder();
|
|
|
|
|
|
|
|
|
|
let (input, header) = FileHeader::read(input)?;
|
2026-11-16 21:28:54 -08:00
|
|
|
append_file_header(&mut lib_builder, &header).map_err(|error| (input, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let base_offset = full_input_size - input.len();
|
|
|
|
|
|
|
|
|
|
let mut names = HashMap::<String, u32>::new();
|
|
|
|
|
let mut layers = HashMap::<u32, u32>::new();
|
|
|
|
|
let cells_builder = lib_builder.field_builder::<DListBuilder>(5).unwrap();
|
|
|
|
|
|
|
|
|
|
let walk_input_size = input.len();
|
|
|
|
|
let (input, ()) = walk_structs(input, base_offset, &mut names, |struct_input, _record_start, id, names| {
|
|
|
|
|
let position = base_offset + walk_input_size - struct_input.len();
|
|
|
|
|
append_full_cell(
|
|
|
|
|
cells_builder,
|
|
|
|
|
names,
|
|
|
|
|
&mut layers,
|
|
|
|
|
struct_input,
|
|
|
|
|
id,
|
|
|
|
|
position.try_into().unwrap(),
|
|
|
|
|
)
|
|
|
|
|
})?;
|
|
|
|
|
cells_builder.append(true);
|
|
|
|
|
|
|
|
|
|
append_names(&mut lib_builder, 6, names);
|
|
|
|
|
append_layers(&mut lib_builder, layers);
|
|
|
|
|
|
|
|
|
|
lib_builder.append(true);
|
|
|
|
|
let lib = lib_builder.finish();
|
|
|
|
|
Ok((input, lib))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Scan cell byte ranges and references without decoding geometry.
|
|
|
|
|
pub fn scan_library(input: &[u8]) -> IResult<'_, StructArray> {
|
|
|
|
|
let full_input_size = input.len();
|
|
|
|
|
let mut lib_builder = make_scan_builder();
|
|
|
|
|
|
|
|
|
|
let (input, header) = FileHeader::read(input)?;
|
2026-11-16 21:28:54 -08:00
|
|
|
append_file_header(&mut lib_builder, &header).map_err(|error| (input, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let base_offset = full_input_size - input.len();
|
|
|
|
|
|
|
|
|
|
let mut names = HashMap::<String, u32>::new();
|
|
|
|
|
let cells_builder = lib_builder.field_builder::<DListBuilder>(5).unwrap();
|
|
|
|
|
|
|
|
|
|
let walk_input_size = input.len();
|
|
|
|
|
let (input, ()) = walk_structs(input, base_offset, &mut names, |struct_input, record_start, id, names| {
|
|
|
|
|
let (after_cell, refs) = scan_elements(struct_input, names)?;
|
|
|
|
|
let struct_end = base_offset + walk_input_size - after_cell.len();
|
|
|
|
|
let cell_builder = cells_builder.values().as_any_mut().downcast_mut::<StructBuilder>().unwrap();
|
|
|
|
|
let id_builder = cell_builder.field_builder::<UInt32Builder>(0).unwrap();
|
|
|
|
|
id_builder.append_value(id);
|
|
|
|
|
|
|
|
|
|
let start_builder = cell_builder.field_builder::<UInt64Builder>(1).unwrap();
|
|
|
|
|
start_builder.append_value(record_start.try_into().unwrap());
|
|
|
|
|
|
|
|
|
|
let end_builder = cell_builder.field_builder::<UInt64Builder>(2).unwrap();
|
|
|
|
|
end_builder.append_value(struct_end.try_into().unwrap());
|
|
|
|
|
|
|
|
|
|
let refs_builder = cell_builder.field_builder::<DListBuilder>(3).unwrap();
|
|
|
|
|
for scan_ref in refs {
|
|
|
|
|
append_scan_ref(refs_builder, scan_ref);
|
|
|
|
|
}
|
|
|
|
|
refs_builder.append(true);
|
|
|
|
|
cell_builder.append(true);
|
|
|
|
|
Ok((after_cell, ()))
|
|
|
|
|
})?;
|
|
|
|
|
cells_builder.append(true);
|
|
|
|
|
|
|
|
|
|
append_names(&mut lib_builder, 6, names);
|
|
|
|
|
|
|
|
|
|
lib_builder.append(true);
|
|
|
|
|
let lib = lib_builder.finish();
|
|
|
|
|
Ok((input, lib))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Read exact half-open cell ranges returned by `scan_library`, in caller order.
|
|
|
|
|
/// Each range includes BGNSTR through ENDSTR. Cell and layer IDs are local to
|
|
|
|
|
/// this result. This random-access operation returns the original input slice
|
|
|
|
|
/// as its remainder; it does not advance a sequential parsing cursor.
|
|
|
|
|
pub fn read_selected_library<'a>(input: &'a [u8], ranges: &[(u64, u64)]) -> IResult<'a, StructArray> {
|
|
|
|
|
let mut lib_builder = make_library_builder();
|
2026-11-16 21:28:54 -08:00
|
|
|
let (header_end, header) = FileHeader::read(input)?;
|
|
|
|
|
append_file_header(&mut lib_builder, &header).map_err(|error| (header_end, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
|
|
|
|
|
let mut names = HashMap::<String, u32>::new();
|
|
|
|
|
let mut layers = HashMap::<u32, u32>::new();
|
|
|
|
|
let cells_builder = lib_builder.field_builder::<DListBuilder>(5).unwrap();
|
|
|
|
|
|
|
|
|
|
for (start_u64, end_u64) in ranges {
|
|
|
|
|
if start_u64 >= end_u64 || *end_u64 > input.len() as u64 {
|
|
|
|
|
return fail(input, format!("Cell byte range out of bounds: [{start_u64}, {end_u64})"));
|
|
|
|
|
}
|
|
|
|
|
let start = usize::try_from(*start_u64).unwrap();
|
|
|
|
|
let end = usize::try_from(*end_u64).unwrap();
|
|
|
|
|
|
|
|
|
|
let struct_input = &input[start..end];
|
|
|
|
|
let (struct_input, _) = records::BGNSTR::read(struct_input)?;
|
|
|
|
|
let (struct_input, name_bytes) = records::STRNAME::read(struct_input)?;
|
2026-11-16 21:28:54 -08:00
|
|
|
let name = decode_utf8(name_bytes).map_err(|error| (struct_input, error))?;
|
Introduce Pheon GDSII parsing and layout review tools
Implement native GDSII reading and writing with Arrow interchange, hierarchy
scans and selective cell loading. Validate numeric packing and array pitches,
and preserve normalized REAL8 encodings exactly within the supported range.
Add standalone dump, structural diff, hierarchy, layer-name annotation and Git
diff commands. Provide scoped text and JSON reports, deterministic comparison,
and record-preserving metadata edits.
Package the shared library and optional Python Arrow readers as pheon using
CFFI ABI mode and Python-independent platform wheels. Include locked source
builds, native API checks, cross-platform artifact workflows, documentation
and regression coverage. Require Rust 1.88 or newer and Python 3.11 or newer.
Validation: 87 native tests, 14 binding tests on Python 3.11/3.13/3.14,
and 71 installed companion integration tests pass. Full, scanned and selected
Arrow layouts match the previous schemas.
2026-11-16 16:21:21 -08:00
|
|
|
let file_offset = end - struct_input.len();
|
|
|
|
|
|
|
|
|
|
let id = intern_name(&mut names, name);
|
|
|
|
|
let (remaining_struct, _) = append_full_cell(
|
|
|
|
|
cells_builder,
|
|
|
|
|
&mut names,
|
|
|
|
|
&mut layers,
|
|
|
|
|
struct_input,
|
|
|
|
|
id,
|
|
|
|
|
file_offset.try_into().unwrap(),
|
|
|
|
|
)?;
|
|
|
|
|
if !remaining_struct.is_empty() {
|
|
|
|
|
return fail(remaining_struct, "Cell byte range extends past ENDSTR".to_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cells_builder.append(true);
|
|
|
|
|
|
|
|
|
|
append_names(&mut lib_builder, 6, names);
|
|
|
|
|
append_layers(&mut lib_builder, layers);
|
|
|
|
|
|
|
|
|
|
lib_builder.append(true);
|
|
|
|
|
let lib = lib_builder.finish();
|
|
|
|
|
Ok((input, lib))
|
|
|
|
|
}
|