runtimepy.primitives.array package#

Module contents#

A module for implementing arrays of arbitrary primitives.

class runtimepy.primitives.array.ArrayFragmentSpec(index_start: int, index_end: int, byte_start: int, byte_end: int)[source]#

Bases: NamedTuple

Information that can be used to construct an array fragment.

byte_end: int#

Alias for field number 3

byte_start: int#

Alias for field number 2

index_end: int#

Alias for field number 1

index_start: int#

Alias for field number 0

class runtimepy.primitives.array.PrimitiveArray(*primitives: Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive, byte_order: ByteOrder = ByteOrder.NETWORK, fragments: list[ArrayFragmentSpec] = None, chain: Serializable = None)[source]#

Bases: Serializable

A class for managing primitives as arrays.

add(primitive: Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive, array_length: int = None) list[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive][source]#

Add another primitive to manage.

add_primitive(kind: type[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive] | str, array_length: int = None) list[Int8Primitive | Int16Primitive | Int32Primitive | Int64Primitive | Uint8Primitive | Uint16Primitive | Uint32Primitive | Uint64Primitive | HalfPrimitive | FloatPrimitive | DoublePrimitive | BooleanPrimitive][source]#

Add to the array by specifying the type of element to add.

byte_at_index(index: int) int[source]#

Get the byte index that a primitive at the provided index starts at. This can also be thought of as the size of the array leading up to the element at this index.

fragment(index: int) PrimitiveArray[source]#

A simple accessor for fragments.

fragment_bytes(index: int) bytes[source]#

Get bytes from a fragment.

fragment_from_byte_indices(start: int, end: int = -1) int[source]#

Create a new array fragment from byte indices and return the fragment index.

fragment_from_indices(start: int, end: int = -1) int[source]#

Create a new array fragment from primitive-member indices and return the fragment index.

index_at_byte(count: int) int[source]#

Determine the array index that a byte index lands on.

property num_fragments: int#

Get the number of fragments belonging to this array.

randomize(timestamp_ns: int = None, chain: bool = True) None[source]#

Randomize array contents.

reset() None[source]#

Reset this array so it’s empty.

update(data: bytes, timestamp_ns: int = None) int[source]#

Update primitive values from a bytes instance.

update_fragment(index: int, data: bytes, timestamp_ns: int = None) None[source]#

Update a fragment by index.