A python package designed to ease data manipulation tasks and improve efficiency when handling binary data.
> pip install byteclasses
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.
-
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
- Generic -
-
Collections
ByteArray
- ClassString
- Classstructure
- Class Decoratorunion
- Class Decorator
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()