From a1de51a255fa26ef2c53b3c00de984d50849fd78 Mon Sep 17 00:00:00 2001 From: Seb-sti1 <65665540+seb-sti1@users.noreply.github.com> Date: Sun, 17 Nov 2024 18:32:20 +0100 Subject: [PATCH] fix: background_visible, root_document_visible can be None in SceneInfo --- src/rmscene/scene_stream.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rmscene/scene_stream.py b/src/rmscene/scene_stream.py index 7491614..30ca6e1 100644 --- a/src/rmscene/scene_stream.py +++ b/src/rmscene/scene_stream.py @@ -141,15 +141,15 @@ def version_info(self, _) -> tuple[int, int]: return (0, 1) current_layer: LwwValue[CrdtId] - background_visible: LwwValue[bool] - root_document_visible: LwwValue[bool] + background_visible: tp.Optional[LwwValue[bool]] + root_document_visible: tp.Optional[LwwValue[bool]] paper_size: tp.Optional[tuple[int, int]] @classmethod def from_stream(cls, stream: TaggedBlockReader) -> SceneInfo: current_layer = stream.read_lww_id(1) - background_visible = stream.read_lww_bool(2) - root_document_visible = stream.read_lww_bool(3) + background_visible = stream.read_lww_bool(2) if stream.bytes_remaining_in_block() > 0 else None + root_document_visible = stream.read_lww_bool(3) if stream.bytes_remaining_in_block() > 0 else None paper_size = stream.read_int_pair(5) if stream.bytes_remaining_in_block() > 0 else None return SceneInfo(current_layer=current_layer, @@ -159,8 +159,11 @@ def from_stream(cls, stream: TaggedBlockReader) -> SceneInfo: def to_stream(self, writer: TaggedBlockWriter): writer.write_lww_id(1, self.current_layer) + if not self.background_visible: return writer.write_lww_bool(2, self.background_visible) + if not self.root_document_visible: return writer.write_lww_bool(3, self.root_document_visible) + if not self.paper_size: return writer.write_int_pair(5, self.paper_size)