Пример #1
0
    def __init__(self, name, lengthfield, fieldtype):
        '''
        Initialize the array with the given *name*, a *lengthfield* for the
        counter field and *fieldtype* for a single argument function
        that will return a new array member. The single argument is a
        reference to the top-level root :mod:`Container` field where the
        array belongs to.
        '''
        Structure.__init__(self, name)

        self.__length = lengthfield
        self.__fieldtype = fieldtype

        Structure.append(self, self.__length)
Пример #2
0
    def __init__(self, name, lengthfield, fieldtype):
        '''
        Initialize the array with the given *name*, a *lengthfield* for the
        counter field and *fieldtype* for a single argument function
        that will return a new array member. The single argument is a
        reference to the top-level root :mod:`Container` field where the
        array belongs to.
        '''
        Structure.__init__(self, name)

        self.__length = lengthfield
        self.__fieldtype = fieldtype

        Structure.append(self, self.__length)
Пример #3
0
    def __init__(self, name, lengthfield, wordsize = 1):
        '''
        Initialize the field with the given *name* and a
        *lengthfield*. The *lengthfield* must be a numeric field
        instance. *wordsize* specifies how many bytes a word contains
        and it can be a numeric value or a unary function that knows
        where to get the word size, it has a default value of 1. So, the
        total length in bytes of a :mod:`Data` field is the length field
        multiplied by the word size. If *wordsize* is a function, it
        takes the top-level root :mod:`Container` field as a single
        argument. This way, it is possible to provide a word size that
        depends on the value of another field.
        '''
        Structure.__init__(self, name)
        self.__wordsize = wordsize

        wsizefunc = lambda root: \
            lengthfield.value() * param_call(wordsize, root)

        self.__length = lengthfield
        self.__data = String("Data", wsizefunc)

        Structure.append(self, self.__length)
        Structure.append(self, self.__data)