Share GDSII reader logic and simplify review output
Share record framing, name decoding, payload validation, array reference decoding, and Arrow cell-header parsing. Accept trailing NUL padding in names and retain located diagnostics for malformed records. Summarize text diffs by cell, layer, and reference target. Show comparison and omission counts before detail. Compact canonical dumps while preserving exact fields and duplicate counts for Git textconv. Simplify hierarchy output and retain per-object evidence in JSON.
This commit is contained in:
parent
d95c378690
commit
15e8a3b7b5
1 changed files with 1717 additions and 828 deletions
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
use std::io::Write;
|
||||
|
||||
use crate::record::{RecordHeader, Record};
|
||||
use crate::record::{Record, RecordFrame};
|
||||
use crate::records;
|
||||
use crate::elements::{read_elements, scan_elements, DListBuilder, FListBuilder, ScanRefRecord};
|
||||
use crate::basic::{ErrType, IResult, OResult, decode_utf8, take_bytes, fail};
|
||||
use crate::basic::{ErrType, IResult, OResult, decode_name, fail};
|
||||
|
||||
use std::string::String;
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -325,7 +325,7 @@ fn append_file_header(
|
|||
lib_builder: &mut StructBuilder,
|
||||
header: &FileHeader,
|
||||
) -> Result<(), ErrType> {
|
||||
let name = decode_utf8(header.name.clone())?;
|
||||
let name = decode_name(&header.name).map_err(ErrType::Failed)?;
|
||||
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();
|
||||
|
|
@ -409,6 +409,24 @@ fn intern_name(names: &mut HashMap<String, u32>, name: String) -> u32 {
|
|||
}
|
||||
|
||||
|
||||
fn read_cell_header<'a>(begin: &RecordFrame<'a>, input: &'a [u8]) -> IResult<'a, String> {
|
||||
if begin.tag != records::RTAG_BGNSTR {
|
||||
return fail(
|
||||
begin.data,
|
||||
format!(
|
||||
"Unexpected record! Got tag 0x{:04x}, expected 0x{:04x}",
|
||||
begin.tag,
|
||||
records::RTAG_BGNSTR
|
||||
),
|
||||
);
|
||||
}
|
||||
begin.decode::<records::BGNSTR, _>()?;
|
||||
let (input, name_bytes) = records::STRNAME::read(input)?;
|
||||
let name = decode_name(&name_bytes).map_err(|error| (input, ErrType::Failed(error)))?;
|
||||
Ok((input, name.to_owned()))
|
||||
}
|
||||
|
||||
|
||||
fn append_full_cell<'a>(
|
||||
cells_builder: &mut DListBuilder,
|
||||
names: &mut HashMap<String, u32>,
|
||||
|
|
@ -440,23 +458,23 @@ 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 {
|
||||
(input, _) = records::BGNSTR::read_data(input, header.data_size)?;
|
||||
let name_bytes;
|
||||
(input, name_bytes) = records::STRNAME::read(input)?;
|
||||
let name = decode_utf8(name_bytes).map_err(|error| (input, error))?;
|
||||
let id = intern_name(names, name);
|
||||
let (next_input, ()) = on_struct(input, record_start, id, names)?;
|
||||
input = next_input;
|
||||
} else {
|
||||
(input, _) = take_bytes(input, header.data_size)?;
|
||||
let mut input = input;
|
||||
loop {
|
||||
let (remaining, record) = RecordFrame::read(input)?;
|
||||
match record.tag {
|
||||
records::RTAG_BGNSTR => {
|
||||
let record_start = base_offset + input_size - input.len();
|
||||
let (after_name, name) = read_cell_header(&record, remaining)?;
|
||||
let id = intern_name(names, name);
|
||||
(input, ()) = on_struct(after_name, record_start, id, names)?;
|
||||
}
|
||||
records::RTAG_ENDLIB => {
|
||||
record.decode::<records::ENDLIB, _>()?;
|
||||
return Ok((remaining, ()));
|
||||
}
|
||||
_ => input = remaining,
|
||||
}
|
||||
(input, header) = RecordHeader::read(input)?;
|
||||
}
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -559,10 +577,8 @@ pub fn read_selected_library<'a>(input: &'a [u8], ranges: &[(u64, u64)]) -> IRes
|
|||
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)?;
|
||||
let name = decode_utf8(name_bytes).map_err(|error| (struct_input, error))?;
|
||||
let (struct_input, begin) = RecordFrame::read(&input[start..end])?;
|
||||
let (struct_input, name) = read_cell_header(&begin, struct_input)?;
|
||||
let file_offset = end - struct_input.len();
|
||||
|
||||
let id = intern_name(&mut names, name);
|
||||
|
|
|
|||
Loading…
Reference in a new issue