Skip to content

A python package designed to ease data manipulation tasks and improve efficiency when handling binary data.

License

Notifications You must be signed in to change notification settings

thetacom/byteclasses

Repository files navigation

Byteclasses Python Package

Version Status Libraries.io dependency status for latest release Wheel Downloads License Python Implementation Python Version

Lint Test Release Publish

Pre-Commit Ruff

Logo

A python package designed to ease data manipulation tasks and improve efficiency when handling binary data.

Installation

> pip install byteclasses

Description

Byteclasses provides a variety of convenience wrapper classes to simplify data handling. These wrapper classes automatically pack and unpack data values.

Additionally, certains types, such as byteclass integers, impose type specific constraints. For example, assigning the value 256 to a UInt8 will raise an OverflowError exception.

This library contains a variety of fixed size primitive byteclasses. These primitive classes can be used in conjunction with the byteclass collections to build more complicated data elements.

Similiar to a Python dataclass, byteclass collections are constructured using the structure or union class decorators. Whereas dataclasses have fields, byteclass collections have members. Collection members must be a byteclass type and cannot have a default value unless using the member constructor function. Each member will be instantiated using its type hint as a factory.

A byteclass structure and union behaves similar to a C struct and union respectively.

The ByteArray and String collections can be instantiated directly using the provided classes.

Byteclasses

  • Primitives

    • Generic - BitField, Byte, Word,DWord, QWord
    • Characters - UChar (Char), SChar
    • Floats - Float16 (Half), Float32 (Float),Float64 (Double)
    • Integers - Int8, UInt8, Int16 (Short), UInt16 (UShort), Int32 (Int), UInt32 (UInt), Long, ULong, Int64 (LongLong), UInt64 (ULongLong)
    • Special - ByteEnum
  • Collections

    • ByteArray - Class
    • String - Class
    • structure - Class Decorator
    • union - Class Decorator

Simple Byteclass Structure Example

from byteclasses.types.collections import structure
from byteclasses.types.primitives.integer import UInt8, UInt32

@structure
class MyStruct:
  """My custom byteclass structure."""

  member1: UInt8
  member2: UInt32

my_var = MyStruct()

Docs

Byteclasses Documentation

References

C data types