Skip to main content

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

Project description

StructOvO

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

Usage

from structovo import *


class PackA(Pack):
    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:

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:

from structovo import BaseType, Endianness


class MyDataType(BaseType):
    def encode(self, endianness: Endianness) -> bytes:
        return ...

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

structovo-0.2.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

structovo-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file structovo-0.2.0.tar.gz.

File metadata

  • Download URL: structovo-0.2.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for structovo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eefa51fba24357da89448cb40fc729fcb316c011fb59cb82181bbb58cbdc13b8
MD5 e45004d77dd31cb43f5213d360c7f3cc
BLAKE2b-256 dc89d149fbfa18496fe0d6083918a732280d78ec7982c7eda3087fa1f55a3bf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for structovo-0.2.0.tar.gz:

Publisher: release.yml on GuangChen2333/StructOvO

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file structovo-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: structovo-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for structovo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3eca15d4a1628347e9ae8c0306164c7752f324966483730f654e783198a28291
MD5 05501a18800e804d614b1807ea419077
BLAKE2b-256 7c5c2ae6105bbcbd8c5c8eade70f3188ce9658792020c953de9040ba36ddca94

See more details on using hashes here.

Provenance

The following attestation bundles were made for structovo-0.2.0-py3-none-any.whl:

Publisher: release.yml on GuangChen2333/StructOvO

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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