usb_protocol.emitters.construct_interop module

Helpers for creating construct-related emitters.

class usb_protocol.emitters.construct_interop.ConstructEmitter(struct)[source]

Bases: object

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

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()[source]

Emits the stream of bytes associated with this object.

usb_protocol.emitters.construct_interop.emitter_for_format(construct_format)[source]

Creates a factory method for the relevant construct format.