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 and emit an object like follows:

emitter   = ConstructEmitter(MyStruct)
emitter.a = 0xab
emitter.b = 0xcd
my_bytes  = emitter.emit() # "«Í"
__getattr__(name)[source]

Retrieves an emitter field, if possible.

__init__(struct)[source]
Parameters:

construct_format – The format for which to create an emitter.

__setattr__(name, value)[source]

Hook that we used to set our fields.

emit()[source]

Emits the stream of bytes associated with this object.

class usb_protocol.emitters.construct_interop.ConstructEmitterTest(methodName='runTest')[source]

Bases: TestCase

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

Creates a factory method for the relevant construct format.