usb_protocol.types.descriptor module

Type elements for defining USB descriptors.

class usb_protocol.types.descriptor.BCDFieldAdapter(subcon)[source]

Bases: Adapter

Construct adapter that dynamically parses BCD fields.

class usb_protocol.types.descriptor.DescriptorField(description='', default=None, *, length=None)[source]

Bases: Subconstruct

Construct field definition that automatically adds fields of the proper size to Descriptor definitions.

LENGTH_TYPES = {1: <FormatField>, 2: <FormatField>, 3: <BytesInteger>, 4: <FormatField>, 8: <FormatField>}
USB_TYPES = {'b': <FormatField>, 'bcd': <BCDFieldAdapter <FormatField>>, 'bm': <FormatField>, 'i': <FormatField>, 'id': <FormatField>, 'w': <FormatField>}
class usb_protocol.types.descriptor.DescriptorFormat(*subcons, _create_partial=True, **subconskw)[source]

Bases: Struct

Creates a Construct structure for a USB descriptor, and a corresponding version that supports parsing incomplete binary as DescriptorType.Partial, e.g. DeviceDescriptor.Partial.

parse(data, **context_keywords)[source]

Hook on the parent parse() method which attaches a few methods.

class usb_protocol.types.descriptor.DescriptorNumber(const)[source]

Bases: Const

Trivial wrapper class that denotes a particular Const as the descriptor number.

get_descriptor_number()[source]

Returns this constant’s associated descriptor number.