structovo


Namestructovo JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryA Python library offering a more concise syntax for data packing.
upload_time2025-02-07 11:47:39
maintainerNone
docs_urlNone
authorGuangChen23333
requires_python>=3.8
licenseMIT
keywords serialization network packet struct
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # StructOvO

![GitHub License](https://img.shields.io/github/license/GuangChen2333/StructOvO?style=flat-square)
![GitHub Repo stars](https://img.shields.io/github/stars/GuangChen2333/StructOvO?style=flat-square)
![PyPi](https://img.shields.io/pypi/v/structovo?style=flat-square)
![Downloads](https://img.shields.io/pypi/dm/structovo?style=flat-square)
![Python](https://img.shields.io/pypi/pyversions/structovo?style=flat-square)

A Python library offering a more concise syntax for data packing.

## Installation

- From `pypi`

```shell
pip install structovo
```

## Usage

```python
from structovo import *


class PackA(Packet):
    a: PADDING
    b: BYTE = b'A'
    c: CHAR = -1
    d: UCHAR = 1
    e: BOOL = False
    f: SHORT = -2
    g: USHORT = 2
    h: INT = -3
    i: UINT = 3
    j: LONG = -4
    k: ULONG = 4
    l: LONGLONG = -5
    m: ULONGLONG = 5
    n: SIZET = 12
    o: SSIZET = 34
    p: BINARY16 = 3.14
    q: FLOAT = 3.14
    r: DOUBLE = 3.14
    s: FixedString = (b"hello", 10)
    t: LengthPrefixedString = b"world"
    u: UnsignedPointer = 0x0d000721
    v: bytes = b'raw_bytes'


r = PackA.build(endianness=Endianness.NATIVE)
hex_list = [format(byte, '02x') for byte in r]
hex_str = ' '.join(hex_list)
print(hex_str)
```

And you will get:

```text
00 41 ff 01 00 fe ff 02 00 fd ff ff ff 03 00 00 00 fc ff ff ff 04 00 00 00 fb ff ff ff ff ff ff ff 05 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 22 00 00 00 00 00 00 00 48 42 c3 f5 48 40 1f 85 eb 51 b8 1e 09 40 68 65 6c 6c 6f 00 00 00 00 00 05 77 6f 72 6c 64 21 07 00 0d 00 00 00 00 72 61 77 5f 62 79 74 65 73
```

## Advance

### Supported Endianness

- `Endianness.BIG`: Big-endian
- `Endianness.LITTLE`: Little-endian
- `Endianness.NETWORK`: Big-endian
- `Endianness.NATIVE`: Depend on your device (Default)

### Custom Data Types

You can define your own data types by simply inheriting the `BaseType` class:

```python
from typing import Tuple, Type
from structovo import BaseType, Endianness


class MyDataType(BaseType):
    def check_validation(self) -> Tuple[bool, Type]:
        # Implement the validation of whether the self.value is valid.
        return ...

    def encode(self, endianness: Endianness) -> bytes:
        # Implement the operation of converting self.value to bytes.
        return ...    
```

Like this: 

```python
from typing import Tuple, Type
from structovo import BaseType, Endianness


class BYTE(BaseType):
    def check_validation(self) -> Tuple[bool, Type]:
        result = isinstance(self.value, bytes)
        return result, bytes

    def encode(self, endianness: Endianness) -> bytes:
        return self._pack('c', endianness)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "structovo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "serialization, network, packet, struct",
    "author": "GuangChen23333",
    "author_email": "guangchenworks@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/21/2f/8461762a146a625483add82bc24e3e9d466ff7907e569b70690f3ffcaa93/structovo-1.0.1.tar.gz",
    "platform": null,
    "description": "# StructOvO\n\n![GitHub License](https://img.shields.io/github/license/GuangChen2333/StructOvO?style=flat-square)\n![GitHub Repo stars](https://img.shields.io/github/stars/GuangChen2333/StructOvO?style=flat-square)\n![PyPi](https://img.shields.io/pypi/v/structovo?style=flat-square)\n![Downloads](https://img.shields.io/pypi/dm/structovo?style=flat-square)\n![Python](https://img.shields.io/pypi/pyversions/structovo?style=flat-square)\n\nA Python library offering a more concise syntax for data packing.\n\n## Installation\n\n- From `pypi`\n\n```shell\npip install structovo\n```\n\n## Usage\n\n```python\nfrom structovo import *\n\n\nclass PackA(Packet):\n    a: PADDING\n    b: BYTE = b'A'\n    c: CHAR = -1\n    d: UCHAR = 1\n    e: BOOL = False\n    f: SHORT = -2\n    g: USHORT = 2\n    h: INT = -3\n    i: UINT = 3\n    j: LONG = -4\n    k: ULONG = 4\n    l: LONGLONG = -5\n    m: ULONGLONG = 5\n    n: SIZET = 12\n    o: SSIZET = 34\n    p: BINARY16 = 3.14\n    q: FLOAT = 3.14\n    r: DOUBLE = 3.14\n    s: FixedString = (b\"hello\", 10)\n    t: LengthPrefixedString = b\"world\"\n    u: UnsignedPointer = 0x0d000721\n    v: bytes = b'raw_bytes'\n\n\nr = PackA.build(endianness=Endianness.NATIVE)\nhex_list = [format(byte, '02x') for byte in r]\nhex_str = ' '.join(hex_list)\nprint(hex_str)\n```\n\nAnd you will get:\n\n```text\n00 41 ff 01 00 fe ff 02 00 fd ff ff ff 03 00 00 00 fc ff ff ff 04 00 00 00 fb ff ff ff ff ff ff ff 05 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 22 00 00 00 00 00 00 00 48 42 c3 f5 48 40 1f 85 eb 51 b8 1e 09 40 68 65 6c 6c 6f 00 00 00 00 00 05 77 6f 72 6c 64 21 07 00 0d 00 00 00 00 72 61 77 5f 62 79 74 65 73\n```\n\n## Advance\n\n### Supported Endianness\n\n- `Endianness.BIG`: Big-endian\n- `Endianness.LITTLE`: Little-endian\n- `Endianness.NETWORK`: Big-endian\n- `Endianness.NATIVE`: Depend on your device (Default)\n\n### Custom Data Types\n\nYou can define your own data types by simply inheriting the `BaseType` class:\n\n```python\nfrom typing import Tuple, Type\nfrom structovo import BaseType, Endianness\n\n\nclass MyDataType(BaseType):\n    def check_validation(self) -> Tuple[bool, Type]:\n        # Implement the validation of whether the self.value is valid.\n        return ...\n\n    def encode(self, endianness: Endianness) -> bytes:\n        # Implement the operation of converting self.value to bytes.\n        return ...    \n```\n\nLike this: \n\n```python\nfrom typing import Tuple, Type\nfrom structovo import BaseType, Endianness\n\n\nclass BYTE(BaseType):\n    def check_validation(self) -> Tuple[bool, Type]:\n        result = isinstance(self.value, bytes)\n        return result, bytes\n\n    def encode(self, endianness: Endianness) -> bytes:\n        return self._pack('c', endianness)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library offering a more concise syntax for data packing.",
    "version": "1.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/GuangChen2333/StructOvO/issues",
        "Repository": "https://github.com/GuangChen2333/StructOvO"
    },
    "split_keywords": [
        "serialization",
        " network",
        " packet",
        " struct"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a31f5d95be8f2945b7caf938bb93b06feacdf5a315a33d7fdaacb4cfde42d315",
                "md5": "fe9af309ff8a568ba03140e2a1f381cf",
                "sha256": "5436ea2bdd357631e2e387ee3053dab555e62b97a46dce0c0805ac3e713f43fd"
            },
            "downloads": -1,
            "filename": "structovo-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fe9af309ff8a568ba03140e2a1f381cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5017,
            "upload_time": "2025-02-07T11:47:38",
            "upload_time_iso_8601": "2025-02-07T11:47:38.065980Z",
            "url": "https://files.pythonhosted.org/packages/a3/1f/5d95be8f2945b7caf938bb93b06feacdf5a315a33d7fdaacb4cfde42d315/structovo-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "212f8461762a146a625483add82bc24e3e9d466ff7907e569b70690f3ffcaa93",
                "md5": "7ff278ef35f748bf93e6d051c1677b6d",
                "sha256": "9d4c53dbf81df7b8af9d65c628ba4577feedc377dd42c8292fa67f8daad59031"
            },
            "downloads": -1,
            "filename": "structovo-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7ff278ef35f748bf93e6d051c1677b6d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3758,
            "upload_time": "2025-02-07T11:47:39",
            "upload_time_iso_8601": "2025-02-07T11:47:39.934904Z",
            "url": "https://files.pythonhosted.org/packages/21/2f/8461762a146a625483add82bc24e3e9d466ff7907e569b70690f3ffcaa93/structovo-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-07 11:47:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GuangChen2333",
    "github_project": "StructOvO",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "structovo"
}
        
Elapsed time: 1.52932s