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

Consider using bytearray #58

Open
Poikilos opened this issue Jan 10, 2025 · 1 comment
Open

Consider using bytearray #58

Poikilos opened this issue Jan 10, 2025 · 1 comment

Comments

@Poikilos
Copy link
Contributor

Poikilos commented Jan 10, 2025

Maybe use bytearray in general (to replace int lists)

  • mutable alternative to bytes, similar functionality as int list
  • readable since is explicitly holding byte values and has related features, and for that reason also maps to other languages better (understandable example code; other languages have string features related to byte collections as well)
    • extend(ba: bytearray)
    • append(b: int) # no cast necessary
      • elements read as if it were list[int], but it has decode method like bytes
    • can cast directly from list[int] or bytes
    • cast cast directly to bytes
  • conversion is more direct (bytes(data[:byteCount]).decode("utf-8") or bytearray(data[:byteCount]).decode("utf-8") becomes data[:byteCount].decode("utf-8"))
    • slightly faster probably, or at least less code
@bobjacobsen
Copy link
Owner

I'm not familiar with bytearray. This definitely seems like a good idea!

Poikilos added a commit to Hierosoft/python-openlcb that referenced this issue Jan 27, 2025
Poikilos added a commit to Hierosoft/python-openlcb that referenced this issue Jan 27, 2025
Always use UTF-8 as per OpenLCB (Fix bobjacobsen#55). Use byetearray (Fix bobjacobsen#58).
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

No branches or pull requests

2 participants