def __init__(self, basetype, *properties, **arguments):
        '''
        Initializer
        :param basetype: A integer primitive type to provide the bits
        
        :param properties: placed arguments, definitions of fields. Each argument is a tuple,
                           the first element is the bit-width, the second element is a field name.
                           If a third element appears, the field is an bit-field array; if the
                           second element does not appear, the field is some padding bits.
                           
        :param arguments: keyword options
        
                        name
                            the type name
                            
                        init
                            a initializer to initialize the struct
                            
                        extend
                            similar to *extend* option in nstruct
                            
                        formatter
                            similar to *formatter* option in nstruct
                        
                        prepack
                            similar to *prepack* option in nstruct
        '''
        params = ['name', 'init', 'extend', 'formatter', 'prepack']
        for k in arguments:
            if not k in params:
                warnings.warn(StructDefWarning('Parameter %r is not recognized, is there a spelling error?' % (k,)))
        self.basetype = basetype
        self.properties = properties
        self.readablename = arguments.get('name')
        self.initfunc = arguments.get('init')
        self.prepackfunc = arguments.get('prepack')
        fields = []
        start = 0
        for p in properties:
            if len(p) > 3 or len(p) < 1:
                raise ValueError('Unknown bit-field definition')
            elif len(p) == 3:
                # Bit-field array
                fields.append(((start, start + p[0] * p[2], p[0]), p[1]))
                start += p[0] * p[2]
            elif len(p) == 2:
                fields.append(((start, start + p[0]), p[1]))
                start += p[0]
            else:
                start += p[0]
        self.fields = fields
        minsize = (start + 7) // 8
        bs = basetype.parser().sizeof(0)
        if minsize > bs:
            raise ValueError('Bit-fields need %d bytes, underline type has only %d bytes' % (minsize, bs))
        self.formatters = {}
        self.listformatters = {}
        if 'extend' in arguments:
            for k,v in arguments['extend'].items():
                if isinstance(k, tuple):
                    if len(k) == 1:
                        k = k[0]
                    else:
                        raise ValueError('Cannot extend bitfield with property path')
                kt = k
                if hasattr(v, 'formatter'):
                    self.formatters[kt] = v.formatter
                if isinstance(v, arraytype):
                    t = v.innertype
                    if hasattr(t, 'formatter'):
                        self.listformatters[kt] = t.formatter
        if 'formatter' in arguments:
            self.extraformatter = arguments['formatter']
def __init__ ( self , basetype , * properties , ** arguments ) : params = [ 'name' , 'init' , 'extend' , 'formatter' , 'prepack' ] for k in arguments : if not k in params : warnings . warn ( StructDefWarning ( 'Parameter %r is not recognized, is there a spelling error?' % ( k , ) ) ) self . basetype = basetype self . properties = properties self . readablename = arguments . get ( 'name' ) self . initfunc = arguments . get ( 'init' ) self . prepackfunc = arguments . get ( 'prepack' ) fields = [ ] start = 0 for p in properties : if len ( p ) > 3 or len ( p ) < 1 : raise ValueError ( 'Unknown bit-field definition' ) elif len ( p ) == 3 : fields . append ( ( ( start , start + p [ 0 ] * p [ 2 ] , p [ 0 ] ) , p [ 1 ] ) ) start += p [ 0 ] * p [ 2 ] elif len ( p ) == 2 : fields . append ( ( ( start , start + p [ 0 ] ) , p [ 1 ] ) ) start += p [ 0 ] else : start += p [ 0 ] self . fields = fields minsize = ( start + 7 ) // 8 bs = basetype . parser ( ) . sizeof ( 0 ) if minsize > bs : raise ValueError ( 'Bit-fields need %d bytes, underline type has only %d bytes' % ( minsize , bs ) ) self . formatters = { } self . listformatters = { } if 'extend' in arguments : for k , v in arguments [ 'extend' ] . items ( ) : if isinstance ( k , tuple ) : if len ( k ) == 1 : k = k [ 0 ] else : raise ValueError ( 'Cannot extend bitfield with property path' ) kt = k if hasattr ( v , 'formatter' ) : self . formatters [ kt ] = v . formatter if isinstance ( v , arraytype ) : t = v . innertype if hasattr ( t , 'formatter' ) : self . listformatters [ kt ] = t . formatter if 'formatter' in arguments : self . extraformatter = arguments [ 'formatter' ]
Initializer
        :param basetype: A integer primitive type to provide the bits
        
        :param properties: placed arguments, definitions of fields. Each argument is a tuple,
                           the first element is the bit-width, the second element is a field name.
                           If a third element appears, the field is an bit-field array; if the
                           second element does not appear, the field is some padding bits.
                           
        :param arguments: keyword options
        
                        name
                            the type name
                            
                        init
                            a initializer to initialize the struct
                            
                        extend
                            similar to *extend* option in nstruct
                            
                        formatter
                            similar to *formatter* option in nstruct
                        
                        prepack
                            similar to *prepack* option in nstruct