datastructclass
A DataStructClass is a dataclass with struct-like semantics. It can be
serialized/deserialized to/from bytes.
A subclass of DataStructClass is a dataclass, with the following additional
features:
<class>.format
<class>.size
<class>.unpack
<instance>.pack
<instance.__bytes__>
Each member of a DataStructClass must provide struct metadata via typing.Annotated.
Example
from struct import Struct
from typing import Annotated
from datastructclass import DataStructClass
class MyDSC(DataStructClass):
# Unsigned long:
member_a: Annotated[int, Struct("=L")]
# Double:
member_b: Annotated[float, Struct("=d")]
# Array of signed long with length 4.
member_c: Annotated[list[int], Struct("=4I")]
# Array of char, aka. a string, with length 8:
member_d: Annotated[bytes, Struct("=8s")]
data = MyDSC(4000, 3.14, [-2, -1, 0, 1], b"charlie ")
# 'send_over_wire' could a network socket, a serial port, etc.
send_over_wire(data.pack())
Limitations
DataStructClass cannot contain variable-length members.
Metadata
Release files for datastructclass 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| datastructclass-0.1.1.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| datastructclass-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / datastructclass-0.1.1.tar.gz
| Download URL | datastructclass-0.1.1.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3beb8caf5ecacbb085d2627e81414c4ed7cdfa48b2270d1c5101dbfcd7223220
|
|
BLAKE2b-256 checksum How to use checksums |
9dc7568b723b3a2ad8ede8f7f082468f8a038dd08085b624534f41701e8bd869
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|
Release files / datastructclass-0.1.1-py3-none-any.whl
| Download URL | datastructclass-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da47b4e539c0cc66ddc8bd623924b7c6b709a11e8adda9aaf61f7592bd993d3f
|
|
BLAKE2b-256 checksum How to use checksums |
73d706f60fd3f2b98c66c5e8541b86f43c4b1517bd5c9312679e1a9d2717111f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.3
|