Emitters

class usb_construct.emitters.descriptor.ComplexDescriptorEmitter(collection=None)

Base class for emitting complex descriptors, which contain nested subordinates.

add_subordinate_descriptor(subordinate) None

Adds a subordinate descriptor to the relevant descriptor.

Parameters:

subordinate – The subordinate descriptor to add; can be an emitter, or a bytes-like object.

emit(include_subordinates: bool = True) bytes

Emit our descriptor.

Parameters:

include_subordinates – If true or not provided, any subordinate descriptors will be included.

Helpers for creating construct-related emitters.

class usb_construct.emitters.construct_interop.ConstructEmitter(struct: Struct)

Class that creates a simple emitter based on a construct struct.

Examples

For example, if we have a construct format that looks like the following:

MyStruct = struct(
        'a' / Int8
        'b' / Int8
)

We could create emit an object like follows:

emitter   = ConstructEmitter(MyStruct)
emitter.a = 0xab
emitter.b = 0xcd
my_bytes  = emitter.emit() # '«Í'
emit() bytes

Emits the stream of bytes associated with this object.

usb_construct.emitters.construct_interop.emitter_for_format(construct_format: Struct)

Creates a factory method for the relevant construct format.