From f70e295739436a6184232437c1eac196923bd92b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 15 Jun 2025 20:33:57 -0700 Subject: [PATCH] finished getting rid of textrecord some tests still fail --- rust/pspp/src/sys/cooked.rs | 4 +-- rust/pspp/src/sys/raw.rs | 55 +++++++++++++++---------------------- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/rust/pspp/src/sys/cooked.rs b/rust/pspp/src/sys/cooked.rs index aa7e65fbb3..d1ee09ebff 100644 --- a/rust/pspp/src/sys/cooked.rs +++ b/rust/pspp/src/sys/cooked.rs @@ -18,7 +18,7 @@ use crate::{ LongNamesRecord, LongStringMissingValueRecord, LongStringValueLabelRecord, MissingValues, MissingValuesError, MultipleResponseRecord, NumberOfCasesRecord, ProductInfoRecord, RawStrArray, RawString, RawWidth, ValueLabel, ValueLabelRecord, - VarDisplayRecord, VariableAttributeRecord, VariableRecord, VariableSetRecord, + VarDisplayRecord, VariableAttributesRecord, VariableRecord, VariableSetRecord, VeryLongStringsRecord, ZHeader, ZTrailer, }, }, @@ -215,7 +215,7 @@ pub struct Headers { pub long_names: Vec, pub very_long_strings: Vec, pub file_attributes: Vec, - pub variable_attributes: Vec, + pub variable_attributes: Vec, pub other_extension: Vec, pub end_of_headers: Option, pub z_header: Option, diff --git a/rust/pspp/src/sys/raw.rs b/rust/pspp/src/sys/raw.rs index 9c010ccbe9..7b8970a1af 100644 --- a/rust/pspp/src/sys/raw.rs +++ b/rust/pspp/src/sys/raw.rs @@ -292,7 +292,7 @@ pub enum Record { LongNames(RawLongNamesRecord), VeryLongStrings(RawVeryLongStringsRecord), FileAttributes(RawFileAttributesRecord), - Text(TextRecord), + VariableAttributes(RawVariableAttributesRecord), OtherExtension(Extension), EndOfHeaders(u32), ZHeader(ZHeader), @@ -319,7 +319,7 @@ pub enum DecodedRecord { LongNames(LongNamesRecord), VeryLongStrings(VeryLongStringsRecord), FileAttributes(FileAttributesRecord), - VariableAttributes(VariableAttributeRecord), + VariableAttributes(VariableAttributesRecord), OtherExtension(Extension), EndOfHeaders(u32), ZHeader(ZHeader), @@ -378,7 +378,9 @@ impl Record { DecodedRecord::VeryLongStrings(record.decode(decoder)) } Record::FileAttributes(record) => DecodedRecord::FileAttributes(record.decode(decoder)), - Record::Text(record) => record.decode(decoder), + Record::VariableAttributes(record) => { + DecodedRecord::VariableAttributes(record.decode(decoder)) + } Record::OtherExtension(record) => DecodedRecord::OtherExtension(record.clone()), Record::EndOfHeaders(record) => DecodedRecord::EndOfHeaders(record), Record::ZHeader(record) => DecodedRecord::ZHeader(record.clone()), @@ -2682,18 +2684,10 @@ impl RawLongNamesRecord { pub struct TextRecord { pub offsets: Range, - /// Type of record. - pub rec_type: TextRecordType, - /// The text content of the record. pub text: RawString, } -#[derive(Clone, Copy, Debug)] -pub enum TextRecordType { - VariableAttributes, -} - impl TextRecord { fn parse(extension: Extension, name: &str) -> Result { extension.check_size(&ExtensionRecord { @@ -2701,21 +2695,10 @@ impl TextRecord { count: None, name, })?; - Ok(Self::new(extension, TextRecordType::VariableAttributes)) - } - fn new(extension: Extension, rec_type: TextRecordType) -> Self { - Self { + Ok(Self { offsets: extension.offsets, - rec_type, text: extension.data.into(), - } - } - pub fn decode(self, decoder: &mut Decoder) -> DecodedRecord { - match self.rec_type { - TextRecordType::VariableAttributes => { - DecodedRecord::VariableAttributes(VariableAttributeRecord::decode(&self, decoder)) - } - } + }) } } @@ -2887,11 +2870,20 @@ impl VarAttributes { } #[derive(Clone, Debug)] -pub struct VariableAttributeRecord(pub Vec); +pub struct RawVariableAttributesRecord(TextRecord); + +#[derive(Clone, Debug)] +pub struct VariableAttributesRecord(pub Vec); -impl VariableAttributeRecord { - fn decode(source: &TextRecord, decoder: &mut Decoder) -> Self { - let decoded = decoder.decode(&source.text); +impl RawVariableAttributesRecord { + fn parse(extension: Extension) -> Result { + Ok(Record::VariableAttributes(Self(TextRecord::parse( + extension, + "variable attributes record", + )?))) + } + fn decode(self, decoder: &mut Decoder) -> VariableAttributesRecord { + let decoded = decoder.decode(&self.0.text); let mut input = decoded.as_ref(); let mut var_attribute_sets = Vec::new(); while !input.is_empty() { @@ -2903,7 +2895,7 @@ impl VariableAttributeRecord { var_attribute_sets.push(var_attribute); input = rest; } - VariableAttributeRecord(var_attribute_sets) + VariableAttributesRecord(var_attribute_sets) } } @@ -3075,10 +3067,7 @@ impl Extension { 13 => RawLongNamesRecord::parse(extension), 14 => RawVeryLongStringsRecord::parse(extension), 17 => RawFileAttributesRecord::parse(extension), - 18 => Ok(Record::Text(TextRecord::new( - extension, - TextRecordType::VariableAttributes, - ))), + 18 => RawVariableAttributesRecord::parse(extension), _ => Ok(Record::OtherExtension(extension)), }; match result { -- 2.30.2