Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test v3.14 roundtrip #1

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 12 additions & 5 deletions src/rmscene/scene_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,30 @@ 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() else None
root_document_visible = stream.read_lww_bool(3) if stream.bytes_remaining_in_block() else None
paper_size = stream.read_two_int(5) if stream.bytes_remaining_in_block() else None

return SceneInfo(current_layer=current_layer,
background_visible=background_visible,
root_document_visible=root_document_visible)
root_document_visible=root_document_visible,
paper_size=paper_size)

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_two_int(5, self.paper_size)


@dataclass
Expand Down
8 changes: 8 additions & 0 deletions src/rmscene/tagged_block_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,11 @@ def read_string_with_format(self, index: int) -> tuple[str, tp.Optional[int]]:
fmt = None

return string, fmt

def read_two_int(self, index: int) -> tp.Optional[tuple[int, int]]:
"""Read a sub block containing two uint32"""
if self.bytes_remaining_in_block() > 0:
with self.read_subblock(index):
first = self.data.read_uint32()
second = self.data.read_uint32()
return first, second
6 changes: 6 additions & 0 deletions src/rmscene/tagged_block_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,9 @@ def write_string_with_format(self, index: int, text: str, fmt: int):
self.data.write_bool(is_ascii)
self.data.write_bytes(b)
self.write_int(2, fmt)

def write_two_int(self, index: int, value: tuple[int, int]):
"""Read a sub block containing two uint32"""
with self.write_subblock(index):
self.data.write_uint32(value[0])
self.data.write_uint32(value[1])
1 change: 1 addition & 0 deletions tests/test_scene_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _hex_lines(b, n=32):
("Wikipedia_highlighted_p1.rm", "3.1"),
("Wikipedia_highlighted_p2.rm", "3.1"),
("With_SceneInfo_Block.rm", "3.4"), # XXX version?
("Color_and_tool_v3.14.4.rm", "3.14"),
],
)
def test_full_roundtrip(test_file, version):
Expand Down
Loading