runtimepy.primitives package

Contents

runtimepy.primitives package#

Subpackages#

Submodules#

runtimepy.primitives.base module#

A module implementing a base, primitive-type storage entity.

class runtimepy.primitives.base.Primitive(value: T = None, scaling: list[float | int] = None)[source]#

Bases: Generic[T]

A simple class for storing and underlying primitive value.

age_ns(now: int = None) int[source]#

Get the age of this primitive’s value in nanoseconds.

age_str(now: int = None) str[source]#

Get the age of this primitive’s value as a string.

binary(byte_order: ByteOrder = None) bytes[source]#

Convert this instance to a byte array.

byte_order: ByteOrder = 4#
copy() Primitive[T][source]#

A simple wrapper for copy.

classmethod decode(data: bytes, byte_order: ByteOrder = None) T[source]#

Decode a primitive of this type from provided data.

classmethod encode(value: T, byte_order: ByteOrder = None) bytes[source]#

Create a bytes instance based on this primitive type.

from_stream(stream: BinaryIO, byte_order: ByteOrder = None) T[source]#

Update this primitive from a stream and return the new value.

kind: Int8Type | Int16Type | Int32Type | Int64Type | Uint8Type | Uint16Type | Uint32Type | Uint64Type | HalfType | FloatType | DoubleType | BooleanType#
classmethod read(stream: BinaryIO, byte_order: ByteOrder = None) T[source]#

Read a primitive from the provided stream based on this primitive type.

register_callback(callback: Callable[[T, T], None], once: bool = False) int[source]#

Register a callback and return an identifier for it.

remove_callback(callback_id: int) bool[source]#

Remove a callback if one is registered with this identifier.

property scaled: float | int#

Get this primitive as a scaled value.

property size: int#

Get the size of this primitive.

to_stream(stream: BinaryIO, byte_order: ByteOrder = None) int[source]#

Write this primitive to a stream.

update(data: bytes, byte_order: ByteOrder = None) T[source]#

Update this primitive from a bytes object.

property value: T#

Obtain the underlying value.

classmethod write(value: T, stream: BinaryIO, byte_order: ByteOrder = None) int[source]#

Write a primitive to the stream based on this type.

runtimepy.primitives.bool module#

A module implementing a boolean-primitive interface.

runtimepy.primitives.bool.Bool#

alias of BooleanPrimitive

class runtimepy.primitives.bool.BooleanPrimitive(value: bool = False)[source]#

Bases: Primitive[bool]

A simple primitive class for booleans.

clear() None[source]#

Coerce the underlying value to false.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.bool.BooleanType object>#
set() None[source]#

Coerce the underlying value to true.

toggle() None[source]#

Toggle the underlying value.

runtimepy.primitives.byte_order module#

A module implementing an enumeration for byte ordering options.

class runtimepy.primitives.byte_order.ByteOrder(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: RuntimeIntEnum

An enumeration for viable byte orders.

BIG_ENDIAN = 3#
LITTLE_ENDIAN = 2#
NATIVE = 1#
NETWORK = 4#
property fmt: str#

Get the struct formatter for this byte order.

runtimepy.primitives.float module#

A module implementing a floating-point primitive interface.

runtimepy.primitives.float.Double#

alias of DoublePrimitive

class runtimepy.primitives.float.DoublePrimitive(value: float = 0.0, scaling: list[float | int] = None)[source]#

Bases: Primitive[float]

A simple primitive class for double-precision floating-point.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.float.DoubleType object>#
runtimepy.primitives.float.Float#

alias of FloatPrimitive

class runtimepy.primitives.float.FloatPrimitive(value: float = 0.0, scaling: list[float | int] = None)[source]#

Bases: Primitive[float]

A simple primitive class for single-precision floating-point.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.float.FloatType object>#
runtimepy.primitives.float.Half#

alias of HalfPrimitive

class runtimepy.primitives.float.HalfPrimitive(value: float = 0.0, scaling: list[float | int] = None)[source]#

Bases: Primitive[float]

A simple primitive class for single-precision floating-point.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.float.HalfType object>#

runtimepy.primitives.int module#

A module implementing an integer-primitive interface.

runtimepy.primitives.int.Int16#

alias of Int16Primitive

class runtimepy.primitives.int.Int16Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Int16Type object>#
runtimepy.primitives.int.Int32#

alias of Int32Primitive

class runtimepy.primitives.int.Int32Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Int32Type object>#
runtimepy.primitives.int.Int64#

alias of Int64Primitive

class runtimepy.primitives.int.Int64Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Int64Type object>#
runtimepy.primitives.int.Int8#

alias of Int8Primitive

class runtimepy.primitives.int.Int8Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Int8Type object>#
runtimepy.primitives.int.Uint16#

alias of Uint16Primitive

class runtimepy.primitives.int.Uint16Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Uint16Type object>#
runtimepy.primitives.int.Uint32#

alias of Uint32Primitive

class runtimepy.primitives.int.Uint32Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Uint32Type object>#
runtimepy.primitives.int.Uint64#

alias of Uint64Primitive

class runtimepy.primitives.int.Uint64Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Uint64Type object>#
runtimepy.primitives.int.Uint8#

alias of Uint8Primitive

class runtimepy.primitives.int.Uint8Primitive(value: int = 0, scaling: list[float | int] = None)[source]#

Bases: Primitive[int]

A simple primitive class for integer primitives.

kind: _AnyPrimitiveType = <runtimepy.primitives.types.int.Uint8Type object>#

runtimepy.primitives.scaling module#

A module implementing interfaces for working with channel scaling polynomials.

runtimepy.primitives.scaling.apply(value: float | int, scaling: list[float | int] = None) float | int[source]#

Apply a scaling polynomial to a value.

runtimepy.primitives.scaling.invert(value: float | int, scaling: list[float | int] = None, should_round: bool = False) float | int[source]#

Apply a scaling polynomial to a value.

runtimepy.primitives.string module#

A module implementing integer-prefixed string reading and writing.

class runtimepy.primitives.string.StringPrimitive(value: str = '', kind: type[~runtimepy.primitives.base.Primitive[int]] = <class 'runtimepy.primitives.int.Uint16Primitive'>, byte_order: ~runtimepy.primitives.byte_order.ByteOrder = ByteOrder.NETWORK)[source]#

Bases: object

A class implementing a string-primitive interface.

static from_stream(stream: ~typing.BinaryIO, kind: type[~runtimepy.primitives.base.Primitive[int]] = <class 'runtimepy.primitives.int.Uint16Primitive'>, byte_order: ~runtimepy.primitives.byte_order.ByteOrder = ByteOrder.NETWORK) StringPrimitive[source]#

Create a new string primitive from a stream.

read(stream: BinaryIO) str[source]#

Read a string from the stream.

set(value: str) None[source]#

Set a new value for the underlying string.

property size: int#

Get the overall size of this string primitive.

property value: str#

Get the value of this string.

write(stream: BinaryIO) int[source]#

Write this string’s size and value to the stream.

Module contents#

A module implementing a primitive-type storage entity.

runtimepy.primitives.Bool#

alias of BooleanPrimitive

runtimepy.primitives.Double#

alias of DoublePrimitive

runtimepy.primitives.Float#

alias of FloatPrimitive

runtimepy.primitives.Half#

alias of HalfPrimitive

runtimepy.primitives.Int16#

alias of Int16Primitive

runtimepy.primitives.Int32#

alias of Int32Primitive

runtimepy.primitives.Int64#

alias of Int64Primitive

runtimepy.primitives.Int8#

alias of Int8Primitive

class runtimepy.primitives.Primitive(value: T = None, scaling: list[float | int] = None)[source]#

Bases: Generic[T]

A simple class for storing and underlying primitive value.

age_ns(now: int = None) int[source]#

Get the age of this primitive’s value in nanoseconds.

age_str(now: int = None) str[source]#

Get the age of this primitive’s value as a string.

binary(byte_order: ByteOrder = None) bytes[source]#

Convert this instance to a byte array.

byte_order: ByteOrder = 4#
callbacks: dict[int, tuple[Callable[[T, T], None], bool]]#
copy() Primitive[T][source]#

A simple wrapper for copy.

curr_callback: int#
classmethod decode(data: bytes, byte_order: ByteOrder = None) T[source]#

Decode a primitive of this type from provided data.

classmethod encode(value: T, byte_order: ByteOrder = None) bytes[source]#

Create a bytes instance based on this primitive type.

from_stream(stream: BinaryIO, byte_order: ByteOrder = None) T[source]#

Update this primitive from a stream and return the new value.

kind: Int8Type | Int16Type | Int32Type | Int64Type | Uint8Type | Uint16Type | Uint32Type | Uint64Type | HalfType | FloatType | DoubleType | BooleanType#
last_updated_ns: int#
classmethod read(stream: BinaryIO, byte_order: ByteOrder = None) T[source]#

Read a primitive from the provided stream based on this primitive type.

register_callback(callback: Callable[[T, T], None], once: bool = False) int[source]#

Register a callback and return an identifier for it.

remove_callback(callback_id: int) bool[source]#

Remove a callback if one is registered with this identifier.

property scaled: float | int#

Get this primitive as a scaled value.

property size: int#

Get the size of this primitive.

to_stream(stream: BinaryIO, byte_order: ByteOrder = None) int[source]#

Write this primitive to a stream.

update(data: bytes, byte_order: ByteOrder = None) T[source]#

Update this primitive from a bytes object.

property value: T#

Obtain the underlying value.

classmethod write(value: T, stream: BinaryIO, byte_order: ByteOrder = None) int[source]#

Write a primitive to the stream based on this type.

class runtimepy.primitives.StrToBool(result: bool, valid: bool)[source]#

Bases: NamedTuple

A container for results when converting strings to boolean.

static parse(data: str) StrToBool[source]#

Parse a string to boolean.

result: bool#

Alias for field number 0

valid: bool#

Alias for field number 1

runtimepy.primitives.Uint16#

alias of Uint16Primitive

runtimepy.primitives.Uint32#

alias of Uint32Primitive

runtimepy.primitives.Uint64#

alias of Uint64Primitive

runtimepy.primitives.Uint8#

alias of Uint8Primitive

runtimepy.primitives.create(value: type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str, **kwargs) Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive[source]#

Create an instance of a primitive.

runtimepy.primitives.normalize(value: type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str) type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive][source]#

Normalize a type of primitive or a string into a type of primitive.