From: Ben Pfaff Date: Sat, 18 Oct 2025 15:17:23 +0000 (-0700) Subject: work on reading binary legacy member X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=392a35f949659ee0ca57f5daffa8d1ab52188b76;p=pspp work on reading binary legacy member --- diff --git a/rust/pspp/src/output/spv.rs b/rust/pspp/src/output/spv.rs index 1e9d6d377c..cff19a88a2 100644 --- a/rust/pspp/src/output/spv.rs +++ b/rust/pspp/src/output/spv.rs @@ -40,6 +40,7 @@ use crate::output::{ mod css; pub mod html; mod legacy_xml; +mod legacy_bin; mod light; #[derive(Debug, Display, thiserror::Error)] diff --git a/rust/pspp/src/output/spv/legacy_bin.rs b/rust/pspp/src/output/spv/legacy_bin.rs new file mode 100644 index 0000000000..bcaabdd404 --- /dev/null +++ b/rust/pspp/src/output/spv/legacy_bin.rs @@ -0,0 +1,76 @@ +use std::io::{Read, Seek, SeekFrom}; + +use binrw::{BinRead, binread}; + +#[binread] +#[br(little)] +#[derive(Debug)] +pub struct LegacyBin { + #[br(magic(0u8))] + version: Version, + #[br(temp)] + n_sources: u16, + member_size: u32, + #[br(count(n_sources), args { inner: (version,) })] + metadata: Vec, + #[br(count(n_sources), args { inner: metadata.as_slice() })] + data: Vec, +} + +#[binread] +#[br(little)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +enum Version { + #[br(magic = 0xafu8)] + Vaf, + #[br(magic = 0xb0u8)] + Vb0, +} + +#[binread] +#[br(little, import(version: Version))] +#[derive(Debug)] +struct Metadata { + n_values: u32, + n_variables: u32, + data_offset: u32, + #[br(count(if version == Version::Vaf { 28 } else { 64 }))] + source_name: Vec, + #[br(if(version == Version::Vb0), temp)] + _x: u32, +} + +#[derive(Debug)] +struct Data { + variables: Vec, +} + +impl BinRead for Data { + type Args<'a> = &'a [Metadata]; + + fn read_options( + reader: &mut R, + endian: binrw::Endian, + metadata: Self::Args<'_>, + ) -> binrw::BinResult { + let mut variables = Vec::with_capacity(metadata.len()); + for metadata in metadata { + reader.seek(SeekFrom::Start(metadata.data_offset as u64))?; + variables.push(Variable::read_options( + reader, + endian, + (metadata.n_values,), + )?); + } + Ok(Self { variables }) + } +} + +#[binread] +#[br(little, import(n_values: u32))] +#[derive(Debug)] +struct Variable { + variable_name: [u8; 288], + #[br(count(n_values))] + values: Vec, +}