feat(parser): add hierarchy scans and selective cell reads
Reuse library builders and cell traversal for full reads, lightweight hierarchy scans, and exact cell byte ranges. Preserve file offsets across readers and reject malformed ranges and FFI pointer/count inputs without aborting. Document scan schemas and ID assignment. Add regression coverage for Arrow round trips, transforms, subset ordering, empty selections, and invalid input.
This commit is contained in:
parent
24438c4840
commit
9643089f2d
1 changed files with 848 additions and 56 deletions
|
|
@ -71,6 +71,18 @@ struct ARefRecord {
|
|||
properties: Vec<PropertyRecord>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ScanRefRecord {
|
||||
pub target_id: u32,
|
||||
pub invert_y: bool,
|
||||
pub scale: f64,
|
||||
pub angle_rad: f64,
|
||||
pub xy: u64,
|
||||
pub xy0: u64,
|
||||
pub xy1: u64,
|
||||
pub counts: u32,
|
||||
}
|
||||
|
||||
enum RefRecord {
|
||||
SRef(SRefRecord),
|
||||
ARef(ARefRecord),
|
||||
|
|
@ -78,6 +90,7 @@ enum RefRecord {
|
|||
|
||||
|
||||
const UNIT_COUNTS: u32 = (1_u32 << 16) | 1_u32;
|
||||
const ZERO_XY: u64 = 0;
|
||||
|
||||
|
||||
fn layer_id_for(
|
||||
|
|
@ -280,6 +293,38 @@ pub fn read_elements<'a>(
|
|||
}
|
||||
|
||||
|
||||
pub fn scan_elements<'a>(
|
||||
input: &'a [u8],
|
||||
names: &mut HashMap<String, u32>,
|
||||
) -> IResult<'a, Vec<ScanRefRecord>> {
|
||||
let mut input = input;
|
||||
let mut refs = Vec::<ScanRefRecord>::new();
|
||||
let (_, mut header) = RecordHeader::read(input)?;
|
||||
while header.tag != records::RTAG_ENDSTR {
|
||||
(input, _) = match header.tag {
|
||||
records::RTAG_SREF | records::RTAG_AREF => {
|
||||
let (next_input, ref_record) = read_ref(input, header.tag, names)?;
|
||||
refs.push(scan_ref_from_record(ref_record));
|
||||
(next_input, ())
|
||||
},
|
||||
records::RTAG_BOUNDARY
|
||||
| records::RTAG_PATH
|
||||
| records::RTAG_NODE
|
||||
| records::RTAG_BOX
|
||||
| records::RTAG_TEXT => skip_element(input)?,
|
||||
_ => {
|
||||
let result = take_bytes(input, header.data_size + 4)?;
|
||||
(result.0, ())
|
||||
}
|
||||
};
|
||||
(_, header) = RecordHeader::read(input)?;
|
||||
}
|
||||
refs.sort_by_key(|scan_ref| scan_ref.target_id);
|
||||
(input, _) = take_bytes(input, 4_usize)?;
|
||||
Ok((input, refs))
|
||||
}
|
||||
|
||||
|
||||
fn append_sref(
|
||||
sref_builder: &mut DListBuilder,
|
||||
sref: SRefRecord,
|
||||
|
|
@ -301,6 +346,45 @@ fn append_sref(
|
|||
}
|
||||
|
||||
|
||||
fn scan_ref_from_record(ref_record: RefRecord) -> ScanRefRecord {
|
||||
match ref_record {
|
||||
RefRecord::SRef(sref) => ScanRefRecord {
|
||||
target_id: sref.target_id,
|
||||
invert_y: sref.invert_y,
|
||||
scale: sref.scale,
|
||||
angle_rad: sref.angle_rad,
|
||||
xy: sref.xy,
|
||||
xy0: ZERO_XY,
|
||||
xy1: ZERO_XY,
|
||||
counts: UNIT_COUNTS,
|
||||
},
|
||||
RefRecord::ARef(aref) => ScanRefRecord {
|
||||
target_id: aref.target_id,
|
||||
invert_y: aref.invert_y,
|
||||
scale: aref.scale,
|
||||
angle_rad: aref.angle_rad,
|
||||
xy: aref.xy,
|
||||
xy0: aref.xy0,
|
||||
xy1: aref.xy1,
|
||||
counts: aref.counts,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn skip_element<'a>(input: &'a [u8]) -> IResult<'a, ()> {
|
||||
let mut input = input;
|
||||
loop {
|
||||
let (next_input, header) = RecordHeader::read(input)?;
|
||||
let (next_input, _) = take_bytes(next_input, header.data_size)?;
|
||||
input = next_input;
|
||||
if header.tag == ENDEL::tag() {
|
||||
return Ok((input, ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn append_aref(
|
||||
aref_builder: &mut DListBuilder,
|
||||
aref: ARefRecord,
|
||||
|
|
|
|||
Loading…
Reference in a new issue