datastructclass.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datastructclass-0.1.1.tar.gz.
File metadata
- Download URL: datastructclass-0.1.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3beb8caf5ecacbb085d2627e81414c4ed7cdfa48b2270d1c5101dbfcd7223220
|
|
| MD5 |
0f9931458263aed9a377deeaee36216d
|
|
| BLAKE2b-256 |
9dc7568b723b3a2ad8ede8f7f082468f8a038dd08085b624534f41701e8bd869
|
File details
Details for the file datastructclass-0.1.1-py3-none-any.whl.
File metadata
- Download URL: datastructclass-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da47b4e539c0cc66ddc8bd623924b7c6b709a11e8adda9aaf61f7592bd993d3f
|
|
| MD5 |
479b81d4edbe84a394eccf5d52e09913
|
|
| BLAKE2b-256 |
73d706f60fd3f2b98c66c5e8541b86f43c4b1517bd5c9312679e1a9d2717111f
|