Skip to main content

A base class for creating binary parsing and packing classes

Project description

Dataclass for go to and from binary data

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

class Temperature(BinmapDataclass):
    temp: unsignedchar = 0

t = Temperature()
t.temp = 22
print(bytes(t))
b'\x16'

t2 = Temperature(b'\x20')
print(t2.temp)
32

Temperature and humidity consisting of one signed byte for temperature and one unsiged byte for humidity:

class TempHum(BinmapDataclass):
    temp: signedchar = 0
    hum: unsignedchar = 0

th = TempHum()
th.temp = -10
th.humidity = 60
print(bytes(th))
b'\xfc<'

th2 = TempHum(b'\xea\x41')
print(th2.temp)
-22
print(th2.hum)
65

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binmap-1.0.1.linux-x86_64.tar.gz (7.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page