pystructtype.structtypes

structtypes: Type system and helpers for pystructtype.

Attributes

T

Generic Data Type for TypeMeta Contents

int8_t

1 Byte Signed int Type

uint8_t

1 Byte Unsigned int Type

int16_t

2 Byte Signed int Type

uint16_t

2 Byte Unsigned int Type

int32_t

4 Byte Signed int Type

uint32_t

4 Byte Unsigned int Type

int64_t

8 Byte Signed int Type

uint64_t

8 Byte Unsigned int Type

bool_t

1 Byte bool Type

float_t

4 Byte float Type

double_t

8 Byte double Type

char_t

1 Byte char Type

string_t

1 Byte char[] Type

Classes

TypeMeta

Class used to define Annotated Type Metadata for

TypeInfo

Class used to define Annotated Type Metadata

TypeIterator

Contains all relevant type information for

Functions

iterate_types(→ collections.abc.Generator[TypeIterator])

Iterate through the given StructDataclass attributes type hints and yield

type_from_annotation(→ type[Any])

Find the base type from an Annotated type, or return it unchanged if not Annotated.

Module Contents

pystructtype.structtypes.T[source]

Generic Data Type for TypeMeta Contents

class pystructtype.structtypes.TypeMeta[T](size: int = 1, chunk_size: int = 1, default: T | None = None)[source]

Class used to define Annotated Type Metadata for size and default values

size = 1[source]
chunk_size = 1[source]
default = None[source]
__hash__() int[source]
__eq__(other: Any) bool[source]
class pystructtype.structtypes.TypeInfo[source]

Class used to define Annotated Type Metadata for format and byte size

format: str[source]
byte_size: int[source]
pystructtype.structtypes.int8_t[source]

1 Byte Signed int Type

pystructtype.structtypes.uint8_t[source]

1 Byte Unsigned int Type

pystructtype.structtypes.int16_t[source]

2 Byte Signed int Type

pystructtype.structtypes.uint16_t[source]

2 Byte Unsigned int Type

pystructtype.structtypes.int32_t[source]

4 Byte Signed int Type

pystructtype.structtypes.uint32_t[source]

4 Byte Unsigned int Type

pystructtype.structtypes.int64_t[source]

8 Byte Signed int Type

pystructtype.structtypes.uint64_t[source]

8 Byte Unsigned int Type

pystructtype.structtypes.bool_t[source]

1 Byte bool Type

pystructtype.structtypes.float_t[source]

4 Byte float Type

pystructtype.structtypes.double_t[source]

8 Byte double Type

pystructtype.structtypes.char_t[source]

1 Byte char Type

pystructtype.structtypes.string_t[source]

1 Byte char[] Type

class pystructtype.structtypes.TypeIterator[source]

Contains all relevant type information for an object in a StructDataclass.

Used as a container when iterating through StructDataclass attributes

key: str[source]
base_type: type[source]
type_info: TypeInfo | None[source]
type_meta: TypeMeta[Any] | None[source]
is_list: bool[source]
is_pystructtype: bool[source]
property size: int[source]

Return the size of the type. If this is not a list, this will default to 1, else this will return the size defined in the type_meta object if it exists.

Returns:

integer containing the size of the type

property chunk_size: int[source]

Return the chunk size of the type. Typically, this is used for char[]/string types as these are defined in chunks rather than in a size of individual values.

This defaults to 1, else this will return the size defined in the type_meta object if it exists.

Returns:

integer containing the chunk size of the type

pystructtype.structtypes.iterate_types(cls: type) collections.abc.Generator[TypeIterator][source]

Iterate through the given StructDataclass attributes type hints and yield a TypeIterator for each one.

Parameters:

cls – A StructDataclass class object (not an instantiated object)

Returns:

Yield a TypeIterator object

Raises:

TypeError – If cls is not a type

pystructtype.structtypes.type_from_annotation(_type: Any) type[Any][source]

Find the base type from an Annotated type, or return it unchanged if not Annotated.

Parameters:

_type – Type or Annotated Type to check

Returns:

Base type if Annotated, or the original passed in type otherwise