Skip to content

Commit

Permalink
WIP: Dataclass (#31)
Browse files Browse the repository at this point in the history
Convert to dataclass in a few steps.
  • Loading branch information
JimmyHedman authored Mar 10, 2020
1 parent ab6ae2e commit fe96c69
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 297 deletions.
15 changes: 7 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
Class for go to and from binary data
Dataclass for go to and from binary data


It's designed to be easy to create mappings by just having a
``_datafields`` class attribute.

It follows dataclass pattern with typehinting as the binary format.
Temperature with one unsigned byte:

.. code-block:: python
class Temperature(Binmap):
_datafields = {"temp": "B"}
class Temperature(BinmapDataclass):
temp: unsignedchar = 0
t = Temperature()
t.temp = 22
Expand All @@ -25,8 +23,9 @@ one unsiged byte for humidity:

.. code-block:: python
class TempHum(Binmap):
_datafields = {"temp": "b", "hum": "B"}
class TempHum(BinmapDataclass):
temp: signedchar = 0
hum: unsignedchar = 0
th = TempHum()
th.temp = -10
Expand Down
Loading

0 comments on commit fe96c69

Please sign in to comment.