Skip to content

QoL improvements for data stream handling#74

Merged
leif81 merged 2 commits intoopen-dis:masterfrom
ngjunsiang:qol-stream-improvements
Sep 23, 2025
Merged

QoL improvements for data stream handling#74
leif81 merged 2 commits intoopen-dis:masterfrom
ngjunsiang:qol-stream-improvements

Conversation

@ngjunsiang
Copy link
Copy Markdown
Contributor

@ngjunsiang ngjunsiang commented Sep 20, 2025

Proposal

Improve quality-of-life (QoL) by adding convenience methods to data-handling classes, and centralise them under a stream module.

Rationale

The interface for DataInputStream and DataOutputStream are inspired by the classes of the same name from Java (see https://docs.oracle.com/javase/8/docs/api/java/io/DataOutputStream.html). Java programmers would no doubt be more familiar with those method names and their uses.

However, their use in a Python package is less helpful, as Python generally does not use these names. Furthermore, IEEE1278.1-2012 also does not use those names, instead using 16-bit signed integer, 8-bit unsigned integer, etc.

Furthermore, a number of issues & PRs can be traced to use of the wrong method:

These bugs can be more easily avoided with names that align with the IEEE1278.1-2012 documentation, and with the type names that already exist in the types module.

Changes

This PR proposes a couple of QoL improvements to make bugs easier to catch and fix, and to lay the ground for further work on type validation. The changes in this PR do not break any existing code.

  • Add convenience methods (read_int8(), ... read_uint8(), ..., and the write_* equivalents) to the DataInputStream and DataOutputStream classes. These methods are aliases that call the appropriate read/write method.
  • Add a stream module from which to import the DataInputStream and DataOutputStream classes. Unlike in Java, Python does not have a convention of requiring classes to be in separate file. Furthermore, Python prefers lowercase module names. This naming aligns better with PEP8 and other Python conventions expected by Python programmers.

Future work (beyond this PR)

If this PR is approved, future work may include:

  • moving DataInputStream.py and DataOutputStream.py under stream altogether, simplifying the directory structure
  • gradually switching usage of legacy methods to the convenience methods for clarity
  • applying type annotations more consistently to facilitate the use of static checkers to catch type errors before runtime.

@ngjunsiang ngjunsiang marked this pull request as ready for review September 20, 2025 12:49
@leif81 leif81 merged commit cc3a4e0 into open-dis:master Sep 23, 2025
0 of 2 checks passed
@leif81
Copy link
Copy Markdown
Member

leif81 commented Sep 23, 2025

Thank-you @ngjunsiang

@ngjunsiang ngjunsiang deleted the qol-stream-improvements branch September 25, 2025 11:14
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.

2 participants