Skip to content

feat: Add SOR file writing to Python library#2

Merged
JamesHarrison merged 1 commit intomainfrom
feature/python-write-support
Aug 10, 2025
Merged

feat: Add SOR file writing to Python library#2
JamesHarrison merged 1 commit intomainfrom
feature/python-write-support

Conversation

@google-labs-jules
Copy link
Contributor

This change adds the ability to write OTDR SOR files from the Python library. It introduces two new methods on the SORFile object:

  • to_bytes(): Serializes the SORFile object into a Python bytes object.
  • write_file(path): Writes the serialized SORFile to a file on disk.

This functionality is crucial for users who want to programmatically modify SOR files and save their changes.

The implementation exposes the existing Rust-based serialization functionality to the Python bindings. A comprehensive round-trip test suite has been added to ensure that files can be read, written, and read back without data loss.

This commit extends the Python library to allow writing SOR files.
The following methods have been added to the `SORFile` class:

- `to_bytes() -> bytes`: Returns the SOR file as a Python bytes object.
- `write_file(path: str) -> None`: Writes the SOR file to the specified path.

The core serialization logic already existed in the Rust library, and this change exposes it to the Python bindings using `pyo3`.

A new test file has been added to verify the round-trip integrity of parsing a file, writing it back to bytes/file, and parsing it again. The tests confirm that all data blocks (except for the re-calculated MapBlock) are preserved correctly.
@JamesHarrison JamesHarrison marked this pull request as ready for review August 10, 2025 16:30
@JamesHarrison JamesHarrison merged commit fa7bfa7 into main Aug 10, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant