datastructclass


Namedatastructclass JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA DataStructClass is a dataclass with struct-like semantics for serialization.
upload_time2024-12-22 10:13:26
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords dataclass serialization struct
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```python
<class>.format
<class>.size
<class>.unpack
<instance>.pack
<instance.__bytes__>
```

Each member of a `DataStructClass` must provide struct metadata via `typing.Annotated`.

## Example

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "datastructclass",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "dataclass, serialization, struct",
    "author": null,
    "author_email": "Alexander Bessman <alexander.bessman@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ba/b9/66f13ccedab99d2d426d070166da2b03445ee9f48843b812db279c62093c/datastructclass-0.1.0.tar.gz",
    "platform": null,
    "description": "# datastructclass\n\nA `DataStructClass` is a `dataclass` with struct-like semantics. It can be\nserialized/deserialized to/from `bytes`.\n\nA subclass of `DataStructClass` is a `dataclass`, with the following additional\nfeatures:\n\n```python\n<class>.format\n<class>.size\n<class>.unpack\n<instance>.pack\n<instance.__bytes__>\n```\n\nEach member of a `DataStructClass` must provide struct metadata via `typing.Annotated`.\n\n## Example\n\n```python\nfrom struct import Struct\nfrom typing import Annotated\nfrom datastructclass import DataStructClass\n\nclass MyDSC(DataStructClass):\n    # Unsigned long:\n    member_a: Annotated[int, Struct(\"=L\")]\n    # Double:\n    member_b: Annotated[float, Struct(\"=d\")]\n    # Array of signed long with length 4.\n    member_c: Annotated[list[int], Struct(\"=4I\")]\n    # Array of char, aka. a string, with length 8:\n    member_d: Annotated[bytes, Struct(\"=8s\")]\n\n\ndata = MyDSC(4000, 3.14, [-2, -1, 0, 1], b\"charlie  \")\n# 'send_over_wire' could a network socket, a serial port, etc.\nsend_over_wire(data.pack())\n```\n\n## Limitations\n\n`DataStructClass` cannot contain variable-length members.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A DataStructClass is a dataclass with struct-like semantics for serialization.",
    "version": "0.1.0",
    "project_urls": {
        "Home": "https://github.com/bessman/datastructclass/"
    },
    "split_keywords": [
        "dataclass",
        " serialization",
        " struct"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "284bb5e35fb71099488fa6a297e3dffe68d9e87df1dec49d034ff26a0976d118",
                "md5": "b528e93217329841ecec5e900a03ece7",
                "sha256": "83e40e1f4c25cb0126be02a67061d5552b84dceaf91338e09df4894636dd8f82"
            },
            "downloads": -1,
            "filename": "datastructclass-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b528e93217329841ecec5e900a03ece7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 4029,
            "upload_time": "2024-12-22T10:13:23",
            "upload_time_iso_8601": "2024-12-22T10:13:23.169298Z",
            "url": "https://files.pythonhosted.org/packages/28/4b/b5e35fb71099488fa6a297e3dffe68d9e87df1dec49d034ff26a0976d118/datastructclass-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bab966f13ccedab99d2d426d070166da2b03445ee9f48843b812db279c62093c",
                "md5": "bcffbea5662d981e5eb525bc77b41788",
                "sha256": "6a2186f6d3bb90033155781c9954e8785936db5e93dd2de3ff470ab7597f66d3"
            },
            "downloads": -1,
            "filename": "datastructclass-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bcffbea5662d981e5eb525bc77b41788",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6030,
            "upload_time": "2024-12-22T10:13:26",
            "upload_time_iso_8601": "2024-12-22T10:13:26.036795Z",
            "url": "https://files.pythonhosted.org/packages/ba/b9/66f13ccedab99d2d426d070166da2b03445ee9f48843b812db279c62093c/datastructclass-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-22 10:13:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bessman",
    "github_project": "datastructclass",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "datastructclass"
}
        
Elapsed time: 0.39078s