dtfabric.runtime package

Submodules

dtfabric.runtime.byte_operations module

Byte stream operations.

class dtfabric.runtime.byte_operations.ByteStreamOperation[source]

Bases: object

Byte stream operation.

abstract ReadFrom(byte_stream)[source]

Read values from a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

values copies from the byte stream.

Return type

tuple[object, …]

abstract WriteTo(values)[source]

Writes values to a byte stream.

Parameters

values (tuple[object, ...]) – values to copy to the byte stream.

Returns

byte stream.

Return type

bytes

class dtfabric.runtime.byte_operations.StructOperation(format_string)[source]

Bases: ByteStreamOperation

Python struct-base byte stream operation.

ReadFrom(byte_stream)[source]

Read values from a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

values copies from the byte stream.

Return type

tuple[object, …]

Raises
  • IOError – if byte stream cannot be read.

  • OSError – if byte stream cannot be read.

WriteTo(values)[source]

Writes values to a byte stream.

Parameters

values (tuple[object, ...]) – values to copy to the byte stream.

Returns

byte stream.

Return type

bytes

Raises
  • IOError – if byte stream cannot be written.

  • OSError – if byte stream cannot be read.

dtfabric.runtime.data_maps module

Data type maps.

class dtfabric.runtime.data_maps.BooleanMap(data_type_definition)[source]

Bases: PrimitiveDataTypeMap

Boolean data type map.

FoldValue(value)[source]

Folds the data type into a value.

Parameters

value (object) – value.

Returns

folded value.

Return type

object

Raises

ValueError – if the data type definition cannot be folded into the value.

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

MapValue(value)[source]

Maps the data type on a value.

Parameters

value (object) – value.

Returns

mapped value.

Return type

bool

Raises

ValueError – if the data type definition cannot be mapped on the value.

class dtfabric.runtime.data_maps.CharacterMap(data_type_definition)[source]

Bases: PrimitiveDataTypeMap

Character data type map.

FoldValue(value)[source]

Folds the data type into a value.

Parameters

value (object) – value.

Returns

folded value.

Return type

object

Raises

ValueError – if the data type definition cannot be folded into the value.

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

MapValue(value)[source]

Maps the data type on a value.

Parameters

value (object) – value.

Returns

mapped value.

Return type

str

Raises

ValueError – if the data type definition cannot be mapped on the value.

class dtfabric.runtime.data_maps.ConstantMap(data_type_definition)[source]

Bases: SemanticDataTypeMap

Constant data type map.

class dtfabric.runtime.data_maps.DataTypeMap(data_type_definition)[source]

Bases: object

Data type map.

abstract FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

GetByteSize(**kwargs)

Retrieves the byte size of the data type map.

This method is deprecated use GetSizeHint instead.

Returns

data type size in bytes or None if size cannot be determined.

Return type

int

GetSizeHint(**unused_kwargs)[source]

Retrieves a hint about the size.

Returns

hint of the number of bytes needed from the byte stream or None.

Return type

int

abstract MapByteStream(byte_stream, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

property name

name of the data type definition or None if not available.

Type

str

class dtfabric.runtime.data_maps.DataTypeMapContext(values=None)[source]

Bases: object

Data type map context.

byte_size

byte size.

Type

int

requested_size

requested size.

Type

int

state

state values per name.

Type

dict[str, object]

values

values per name.

Type

dict[str, object]

class dtfabric.runtime.data_maps.DataTypeMapFactory(definitions_registry)[source]

Bases: object

Factory for data type maps.

CreateDataTypeMap(definition_name)[source]

Creates a specific data type map by name.

Parameters

definition_name (str) – name of the data type definition.

Returns

data type map or None if the date type definition

is not available.

Return type

DataTypeMap

classmethod CreateDataTypeMapByType(data_type_definition)[source]

Creates a specific data type map by type indicator.

Parameters

data_type_definition (DataTypeDefinition) – data type definition.

Returns

data type map or None if the date type definition

is not available.

Return type

DataTypeMap

GetDataTypeDefinition(definition_name)[source]

Retrieves a specific data type definition by name.

Parameters

definition_name (str) – name of the data type definition.

Returns

data type definition or None if the date type

definition is not available.

Return type

DataTypeDefinition

class dtfabric.runtime.data_maps.DataTypeMapSizeHint(byte_size, is_complete=False)[source]

Bases: object

Data type map size hint.

byte_size

byte size.

Type

int

is_complete

True if the size is the complete size of the data type.

Type

bool

class dtfabric.runtime.data_maps.ElementSequenceDataTypeMap(data_type_definition)[source]

Bases: StorageDataTypeMap

Element sequence data type map.

abstract FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

GetSizeHint(context=None, **unused_kwargs)[source]

Retrieves a hint about the size.

Parameters

context (Optional[DataTypeMapContext]) – data type map context, used to determine the size hint.

Returns

hint of the number of bytes needed from the byte stream or None.

Return type

int

GetStructByteOrderString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

abstract MapByteStream(byte_stream, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

class dtfabric.runtime.data_maps.EnumerationMap(data_type_definition)[source]

Bases: SemanticDataTypeMap

Enumeration data type map.

GetName(number)[source]

Retrieves the name of an enumeration value by number.

Parameters

number (int) – number.

Returns

name of the enumeration value or None if no corresponding

enumeration value was found.

Return type

str

class dtfabric.runtime.data_maps.FloatingPointMap(data_type_definition)[source]

Bases: PrimitiveDataTypeMap

Floating-point data type map.

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

class dtfabric.runtime.data_maps.FormatMap(data_type_definition)[source]

Bases: LayoutDataTypeMap

Format data type map.

MapByteStream(byte_stream, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

property layout

layout element definitions.

Type

list[LayoutElementDefinition]

class dtfabric.runtime.data_maps.IntegerMap(data_type_definition)[source]

Bases: PrimitiveDataTypeMap

Integer data type map.

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

class dtfabric.runtime.data_maps.LayoutDataTypeMap(data_type_definition)[source]

Bases: DataTypeMap

Layout data type map.

FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

abstract MapByteStream(byte_stream, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

class dtfabric.runtime.data_maps.PaddingMap(data_type_definition)[source]

Bases: DataTypeMap

Padding data type map.

FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

FoldValue(value)[source]

Folds the data type into a value.

Parameters

value (object) – value.

Returns

folded value.

Return type

object

Raises

ValueError – if the data type definition cannot be folded into the value.

GetSizeHint(byte_offset=0, context=None, **unused_kwargs)[source]

Retrieves a hint about the size.

Parameters
  • byte_offset (Optional[int]) – offset into the byte stream where to start.

  • context (Optional[DataTypeMapContext]) – data type map context, used to determine the size hint.

Returns

hint of the number of bytes needed from the byte stream or None.

Return type

int

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

MapByteStream(byte_stream, byte_offset=0, context=None, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters
  • byte_stream (bytes) – byte stream.

  • byte_offset (Optional[int]) – offset into the byte stream where to start.

  • context (Optional[DataTypeMapContext]) – data type map context.

Returns

mapped value.

Return type

object

Raises

ByteStreamTooSmallError – if the byte stream is too small.

MapValue(value)[source]

Maps the data type on a value.

Parameters

value (object) – value.

Returns

mapped value.

Return type

object

Raises

ValueError – if the data type definition cannot be mapped on the value.

class dtfabric.runtime.data_maps.PrimitiveDataTypeMap(data_type_definition)[source]

Bases: StorageDataTypeMap

Primitive data type map.

FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

FoldValue(value)[source]

Folds the data type into a value.

Parameters

value (object) – value.

Returns

folded value.

Return type

object

Raises

ValueError – if the data type definition cannot be folded into the value.

MapByteStream(byte_stream, byte_offset=0, context=None, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters
  • byte_stream (bytes) – byte stream.

  • byte_offset (Optional[int]) – offset into the byte stream where to start.

  • context (Optional[DataTypeMapContext]) – data type map context.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

MapValue(value)[source]

Maps the data type on a value.

Parameters

value (object) – value.

Returns

mapped value.

Return type

object

Raises

ValueError – if the data type definition cannot be mapped on the value.

class dtfabric.runtime.data_maps.SemanticDataTypeMap(data_type_definition)[source]

Bases: DataTypeMap

Semantic data type map.

FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

MapByteStream(byte_stream, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

class dtfabric.runtime.data_maps.SequenceMap(data_type_definition)[source]

Bases: ElementSequenceDataTypeMap

Sequence data type map.

FoldByteStream(mapped_value, **kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

MapByteStream(byte_stream, **kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped values.

Return type

tuple[object, …]

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

class dtfabric.runtime.data_maps.StorageDataTypeMap(data_type_definition)[source]

Bases: DataTypeMap

Storage data type map.

abstract FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

GetStructByteOrderString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

abstract MapByteStream(byte_stream, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

class dtfabric.runtime.data_maps.StreamMap(data_type_definition)[source]

Bases: ElementSequenceDataTypeMap

Stream data type map.

FoldByteStream(mapped_value, context=None, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters
  • mapped_value (object) – mapped value.

  • context (Optional[DataTypeMapContext]) – data type map context.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

MapByteStream(byte_stream, byte_offset=0, context=None, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters
  • byte_stream (bytes) – byte stream.

  • byte_offset (Optional[int]) – offset into the byte stream where to start.

  • context (Optional[DataTypeMapContext]) – data type map context.

Returns

mapped values.

Return type

tuple[object, …]

Raises
class dtfabric.runtime.data_maps.StringMap(data_type_definition)[source]

Bases: StreamMap

String data type map.

FoldByteStream(mapped_value, **kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

MapByteStream(byte_stream, byte_offset=0, **kwargs)[source]

Maps the data type on a byte stream.

Parameters
  • byte_stream (bytes) – byte stream.

  • byte_offset (Optional[int]) – offset into the byte stream where to start.

Returns

mapped values.

Return type

str

Raises
class dtfabric.runtime.data_maps.StructureGroupMap(data_type_definition)[source]

Bases: LayoutDataTypeMap

Structure group data type map.

GetByteSize(**kwargs)

Retrieves the byte size of the data type map.

This method is deprecated use GetSizeHint instead.

Returns

data type size in bytes or None if size cannot be determined.

Return type

int

GetSizeHint(context=None, **kwargs)[source]

Retrieves a hint about the size.

Parameters

context (Optional[DataTypeMapContext]) – data type map context, used to determine the size hint.

Returns

hint of the number of bytes needed from the byte stream or None.

Return type

int

MapByteStream(byte_stream, context=None, **kwargs)[source]

Maps the data type on a byte stream.

Parameters
  • byte_stream (bytes) – byte stream.

  • context (Optional[DataTypeMapContext]) – data type map context.

Returns

mapped value.

Return type

object

Raises
class dtfabric.runtime.data_maps.StructureMap(data_type_definition)[source]

Bases: StorageDataTypeMap

Structure data type map.

CreateStructureValues(*args, **kwargs)[source]

Creates a structure values object.

Returns

structure values.

Return type

object

FoldByteStream(mapped_value, **kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

GetSizeHint(context=None, **unused_kwargs)[source]

Retrieves a hint about the size.

Parameters

context (Optional[DataTypeMapContext]) – data type map context, used to determine the size hint.

Returns

hint of the number of bytes needed from the byte stream or None.

Return type

int

GetStructFormatString()[source]

Retrieves the Python struct format string.

Returns

format string as used by Python struct or None if format string

cannot be determined.

Return type

str

MapByteStream(byte_stream, **kwargs)[source]

Maps the data type on a byte stream.

Parameters

byte_stream (bytes) – byte stream.

Returns

mapped value.

Return type

object

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

class dtfabric.runtime.data_maps.UUIDMap(data_type_definition)[source]

Bases: StorageDataTypeMap

UUID (or GUID) data type map.

FoldByteStream(mapped_value, **unused_kwargs)[source]

Folds the data type into a byte stream.

Parameters

mapped_value (object) – mapped value.

Returns

byte stream.

Return type

bytes

Raises

FoldingError – if the data type definition cannot be folded into the byte stream.

MapByteStream(byte_stream, byte_offset=0, context=None, **unused_kwargs)[source]

Maps the data type on a byte stream.

Parameters
  • byte_stream (bytes) – byte stream.

  • byte_offset (Optional[int]) – offset into the byte stream where to start.

  • context (Optional[DataTypeMapContext]) – data type map context.

Returns

mapped value.

Return type

uuid.UUID

Raises

MappingError – if the data type definition cannot be mapped on the byte stream.

dtfabric.runtime.fabric module

dtFabric helper objects.

class dtfabric.runtime.fabric.DataTypeFabric(yaml_definition=None)[source]

Bases: DataTypeMapFactory

Data type fabric.

GetDefinitionByName(name: str) Union[data_types.DataTypeDefinition, None][source]

Retrieves a specific data type definition by name.

Parameters

name (str) – name of the data type definition.

Returns

data type definition or None if not available.

Return type

DataTypeDefinition

dtfabric.runtime.runtime module

Run-time objects.

class dtfabric.runtime.runtime.StructureValuesClassFactory[source]

Bases: object

Structure values class factory.

classmethod CreateClass(data_type_definition)[source]

Creates a new structure values class.

Parameters

data_type_definition (DataTypeDefinition) – data type definition.

Returns

structure values class.

Return type

class

Module contents