runtimepy.primitives.types package#

Submodules#

runtimepy.primitives.types.base module#

A module for implementing a base class for primitive types.

class runtimepy.primitives.types.base.PrimitiveType(struct_format: str, signed: bool = True)[source]#

Bases: Generic[T]

A simple wrapper around ctype primitives.

c_type: type[T]#
decode(data: bytes, byte_order: ByteOrder = ByteOrder.NETWORK) bool | int | float[source]#

Decode primitive based on this type.

encode(value: bool | int | float, byte_order: ByteOrder = ByteOrder.NETWORK) bytes[source]#

Encode a primitive value.

classmethod instance() T[source]#

Get an instance of this primitive type.

name: str#
python_type: type[bool | int | float]#
read(stream: BinaryIO, byte_order: ByteOrder = ByteOrder.NETWORK) bool | int | float[source]#

Read a primitive from a stream based on this type.

classmethod valid_primitive(primitive: bool | int | float) bool[source]#

Determine if a Python primitive is valid for this class.

write(value: bool | int | float, stream: BinaryIO, byte_order: ByteOrder = ByteOrder.NETWORK) int[source]#

Write a primitive to a stream based on this type.

runtimepy.primitives.types.bool module#

A module implementing a type interface for booleans.

class runtimepy.primitives.types.bool.BooleanType[source]#

Bases: PrimitiveType[c_bool]

A simple type interface for booleans.

c_type#

alias of c_bool

name: str = 'bool'#
python_type#

alias of bool

runtimepy.primitives.types.bounds module#

A module implementing an interface for keeping track of primitive-integer bounds (based on bit width).

class runtimepy.primitives.types.bounds.IntegerBounds(min: int, max: int)[source]#

Bases: NamedTuple

A container for integer bounds.

clamp(val: int) int[source]#

Ensure that ‘val’ is between min and max, use the min or max value instead of the provided value if it exceeds these bounds.

static create(byte_count: int, signed: bool) IntegerBounds[source]#

Compute maximum and minimum values given size and signedness.

max: int#

Alias for field number 1

min: int#

Alias for field number 0

random() int[source]#

Get a random integer.

validate(val: int) bool[source]#

Determine if the value is within bounds.

runtimepy.primitives.types.float module#

A module implementing a type interface for floating-point numbers.

class runtimepy.primitives.types.float.DoubleType[source]#

Bases: PrimitiveType[c_double]

A simple type interface for double-precision floating-point.

c_type#

alias of c_double

name: str = 'double'#
python_type#

alias of float

class runtimepy.primitives.types.float.FloatType[source]#

Bases: PrimitiveType[c_float]

A simple type interface for single-precision floating-point.

c_type#

alias of c_float

name: str = 'float'#
python_type#

alias of float

class runtimepy.primitives.types.float.HalfType[source]#

Bases: PrimitiveType[c_float]

A simple type interface for single-precision floating-point.

c_type#

alias of c_float

name: str = 'half'#
python_type#

alias of float

runtimepy.primitives.types.int module#

A module implementing a type interface for integers.

class runtimepy.primitives.types.int.Int16Type[source]#

Bases: PrimitiveType[c_short]

A simple type interface for int16’s.

c_type#

alias of c_short

name: str = 'int16'#
python_type#

alias of int

class runtimepy.primitives.types.int.Int32Type[source]#

Bases: PrimitiveType[c_int]

A simple type interface for int32’s.

c_type#

alias of c_int

name: str = 'int32'#
python_type#

alias of int

class runtimepy.primitives.types.int.Int64Type[source]#

Bases: PrimitiveType[c_long]

A simple type interface for int64’s.

c_type#

alias of c_long

name: str = 'int64'#
python_type#

alias of int

class runtimepy.primitives.types.int.Int8Type[source]#

Bases: PrimitiveType[c_byte]

A simple type interface for int8’s.

c_type#

alias of c_byte

name: str = 'int8'#
python_type#

alias of int

class runtimepy.primitives.types.int.Uint16Type[source]#

Bases: PrimitiveType[c_ushort]

A simple type interface for uint16’s.

c_type#

alias of c_ushort

name: str = 'uint16'#
python_type#

alias of int

class runtimepy.primitives.types.int.Uint32Type[source]#

Bases: PrimitiveType[c_uint]

A simple type interface for uint32’s.

c_type#

alias of c_uint

name: str = 'uint32'#
python_type#

alias of int

class runtimepy.primitives.types.int.Uint64Type[source]#

Bases: PrimitiveType[c_ulong]

A simple type interface for uint64’s.

c_type#

alias of c_ulong

name: str = 'uint64'#
python_type#

alias of int

class runtimepy.primitives.types.int.Uint8Type[source]#

Bases: PrimitiveType[c_ubyte]

A simple type interface for uint8’s.

c_type#

alias of c_ubyte

name: str = 'uint8'#
python_type#

alias of int

Module contents#

A module exposing primitive types.

runtimepy.primitives.types.normalize(value: str | Int8Type | Int16Type | Int32Type | Int64Type | Uint8Type | Uint16Type | Uint32Type | Uint64Type | HalfType | FloatType | DoubleType | BooleanType) Int8Type | Int16Type | Int32Type | Int64Type | Uint8Type | Uint16Type | Uint32Type | Uint64Type | HalfType | FloatType | DoubleType | BooleanType[source]#

Normalize a primitive type or string into a primitive type.