Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/object_pool/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,45 +291,45 @@ impl Object {
Object::Key(o) => extend_object_refs(&mut refs, &o.object_refs),
Object::Button(o) => extend_object_refs(&mut refs, &o.object_refs),
Object::InputBoolean(o) => {
refs.push(o.foreground_colour);
push_nullable_id(&mut refs, &o.foreground_colour);
push_nullable_id(&mut refs, &o.variable_reference);
}
Object::InputString(o) => {
refs.push(o.font_attributes);
push_nullable_id(&mut refs, &o.font_attributes);
push_nullable_id(&mut refs, &o.input_attributes);
push_nullable_id(&mut refs, &o.variable_reference);
}
Object::InputNumber(o) => {
refs.push(o.font_attributes);
push_nullable_id(&mut refs, &o.font_attributes);
push_nullable_id(&mut refs, &o.variable_reference);
}
Object::InputList(o) => {
push_nullable_id(&mut refs, &o.variable_reference);
extend_nullable_ids(&mut refs, &o.list_items);
}
Object::OutputString(o) => {
refs.push(o.font_attributes);
push_nullable_id(&mut refs, &o.font_attributes);
push_nullable_id(&mut refs, &o.variable_reference);
}
Object::OutputNumber(o) => {
refs.push(o.font_attributes);
push_nullable_id(&mut refs, &o.font_attributes);
push_nullable_id(&mut refs, &o.variable_reference);
}
Object::OutputList(o) => {
push_nullable_id(&mut refs, &o.variable_reference);
extend_nullable_ids(&mut refs, &o.list_items);
}
Object::OutputLine(o) => refs.push(o.line_attributes),
Object::OutputLine(o) => push_nullable_id(&mut refs, &o.line_attributes),
Object::OutputRectangle(o) => {
refs.push(o.line_attributes);
push_nullable_id(&mut refs, &o.line_attributes);
push_nullable_id(&mut refs, &o.fill_attributes);
}
Object::OutputEllipse(o) => {
refs.push(o.line_attributes);
push_nullable_id(&mut refs, &o.line_attributes);
push_nullable_id(&mut refs, &o.fill_attributes);
}
Object::OutputPolygon(o) => {
refs.push(o.line_attributes);
push_nullable_id(&mut refs, &o.line_attributes);
push_nullable_id(&mut refs, &o.fill_attributes);
}
Object::OutputMeter(o) => push_nullable_id(&mut refs, &o.variable_reference),
Expand Down Expand Up @@ -527,7 +527,7 @@ pub struct InputBoolean {
pub id: ObjectId,
pub background_colour: u8,
pub width: u16,
pub foreground_colour: ObjectId,
pub foreground_colour: NullableObjectId,
pub variable_reference: NullableObjectId,
pub value: bool,
pub enabled: bool,
Expand All @@ -550,7 +550,7 @@ pub struct InputString {
pub width: u16,
pub height: u16,
pub background_colour: u8,
pub font_attributes: ObjectId,
pub font_attributes: NullableObjectId,
pub input_attributes: NullableObjectId,
pub options: InputStringOptions,
pub variable_reference: NullableObjectId,
Expand All @@ -576,7 +576,7 @@ pub struct InputNumber {
pub width: u16,
pub height: u16,
pub background_colour: u8,
pub font_attributes: ObjectId,
pub font_attributes: NullableObjectId,
pub options: NumberOptions,
pub variable_reference: NullableObjectId,
pub value: u32,
Expand Down Expand Up @@ -629,7 +629,7 @@ pub struct OutputString {
pub width: u16,
pub height: u16,
pub background_colour: u8,
pub font_attributes: ObjectId,
pub font_attributes: NullableObjectId,
pub options: OutputStringOptions,
pub variable_reference: NullableObjectId,
pub justification: Alignment,
Expand All @@ -653,7 +653,7 @@ pub struct OutputNumber {
pub width: u16,
pub height: u16,
pub background_colour: u8,
pub font_attributes: ObjectId,
pub font_attributes: NullableObjectId,
pub options: NumberOptions,
pub variable_reference: NullableObjectId,
pub value: u32,
Expand Down Expand Up @@ -699,7 +699,7 @@ impl SizedObject for OutputList {
#[derive(Debug, PartialEq, Clone)]
pub struct OutputLine {
pub id: ObjectId,
pub line_attributes: ObjectId,
pub line_attributes: NullableObjectId,
pub width: u16,
pub height: u16,
pub line_direction: LineDirection,
Expand All @@ -719,7 +719,7 @@ impl SizedObject for OutputLine {
#[derive(Debug, PartialEq, Clone)]
pub struct OutputRectangle {
pub id: ObjectId,
pub line_attributes: ObjectId,
pub line_attributes: NullableObjectId,
pub width: u16,
pub height: u16,
pub line_suppression: u8,
Expand All @@ -740,7 +740,7 @@ impl SizedObject for OutputRectangle {
#[derive(Debug, PartialEq, Clone)]
pub struct OutputEllipse {
pub id: ObjectId,
pub line_attributes: ObjectId,
pub line_attributes: NullableObjectId,
pub width: u16,
pub height: u16,
pub ellipse_type: u8,
Expand All @@ -765,7 +765,7 @@ pub struct OutputPolygon {
pub id: ObjectId,
pub width: u16,
pub height: u16,
pub line_attributes: ObjectId,
pub line_attributes: NullableObjectId,
pub fill_attributes: NullableObjectId,
pub polygon_type: u8,
pub points: Vec<Point<u16>>,
Expand Down
37 changes: 35 additions & 2 deletions src/object_pool/object_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::object_pool::object::{
use crate::object_pool::object_id::ObjectId;
use crate::object_pool::vt_version::VtVersion;
use crate::object_pool::ObjectType;
use crate::object_pool::ParseError;

#[derive(Debug, Clone, PartialEq)]
pub struct ObjectPool {
Expand Down Expand Up @@ -76,18 +77,50 @@ impl ObjectPool {
op
}

/// Like [`from_iop`](Self::from_iop), but returns the first parse error
/// instead of silently keeping only the objects read before it.
///
/// `from_iop` cannot tell a pool that ended from a pool it could not
/// finish reading: both just stop. For a pool whose Working Set is not the
/// first object, an unreadable object anywhere before it makes the
/// lenient parse come back with no Working Set at all and no indication
/// why. Use this when that difference matters.
pub fn try_from_iop<I>(data: I) -> Result<Self, ParseError>
where
I: IntoIterator<Item = u8>,
{
let mut op = Self::new();
op.try_extend_with_iop(data)?;
Ok(op)
}

pub fn extend_with_iop<I>(&mut self, data: I)
where
I: IntoIterator<Item = u8>,
{
let mut data = data.into_iter();
// Lenient by design: keep whatever was readable, as this always has.
let _ = self.try_extend_with_iop(data);
}

/// Strict counterpart of [`extend_with_iop`](Self::extend_with_iop): stops
/// at, and returns, the first object that cannot be read. Objects read
/// before the failure have already been added.
pub fn try_extend_with_iop<I>(&mut self, data: I) -> Result<(), ParseError>
where
I: IntoIterator<Item = u8>,
{
let mut data = data.into_iter().peekable();

while let Ok(o) = Object::read(&mut data) {
// Running out of data *between* objects is the normal end of a pool;
// running out inside one is a truncated object and is reported.
while data.peek().is_some() {
let o = Object::read(&mut data)?;
// By the standard, if there already is an object with the same ID, the new object
// replaces the old one
self.objects.retain(|x| x.id() != o.id());
self.objects.push(o);
}
Ok(())
}

pub fn as_iop(&self) -> Vec<u8> {
Expand Down
Loading
Loading