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

WIP: Dataclass #31

Merged
merged 18 commits into from
Mar 10, 2020
Merged
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
Loading