Beispiel #1
0
class FormatArray(object):
    implements(IFormat, IStructEvaluateable)

    def __init__(self, format, repeat):
        self.format = IFormat(format)
        self.repeat = repeat

    def _read(self, bs, cursor):
        results = []
        for i in xrange(self.repeat):
            results.append(bs.read(self.format))
        return results

    def _write(self, bs, cursor, argument):
        if len(argument) != self.repeat:
            raise ValueError("This %s array is of length %d, you tried to wri"
                             "te an %s" % (self.format, self.repeat, argument))
        for i in argument:
            bs.write(i, self.format)

    def _pre_write(self, struct, field):
        self.format._pre_write(struct, field)

    def _evaluate(self, struct):
        return type(self)(self.format._evaluate(struct), self.repeat)

    def __str__(self):
        return "%s[%s]" % (self.format, self.repeat)
Beispiel #2
0
class FormatArray(object):
    implements(IFormat, IStructEvaluateable)
    def __init__(self, format, repeat):
        self.format = IFormat(format)
        self.repeat = repeat

    def _read(self, bs, cursor):
        results = []
        for i in xrange(self.repeat):
            results.append(bs.read(self.format))
        return results

    def _write(self, bs, cursor, argument):
        if len(argument) != self.repeat:
            raise ValueError("This %s array is of length %d, you tried to wri"
                             "te an %s" % (self.format, self.repeat, argument))
        for i in argument:
            bs.write(i, self.format)

    def _pre_write(self, struct, field):
        self.format._pre_write(struct, field)

    def _evaluate(self, struct):
        return type(self)(self.format._evaluate(struct), self.repeat)

    def __str__(self):
        return "%s[%s]" % (self.format, self.repeat)
Beispiel #3
0
 def _struct_read(self, struct, bitstream):
     format = IFormat(self.format)
     format = IStructEvaluateable(format)._evaluate(struct)
     value = bitstream.read(format)
     value = self._filter_read(struct, value)
     self._struct_set(struct, value)
     return value
Beispiel #4
0
 def __init__(self, format, repeat):
     self.format = IFormat(format)
     self.repeat = repeat
Beispiel #5
0
def sequence_to_iformat(obj):
    return IFormat(IBitStream(obj))
Beispiel #6
0
 def __init__(self, format, repeat):
     self.format = IFormat(format)
     self.repeat = repeat
Beispiel #7
0
 def write(self, argument, part=None):
     if part is None:
         part = argument
     IFormat(part)._write(self, self.tell(), argument)
Beispiel #8
0
 def read(self, part):
     return IFormat(part)._read(self, self.tell())
Beispiel #9
0
 def read(self, part):
     return IFormat(part)._read(self, self.cursor)
Beispiel #10
0
 def as_format(self):
     return IFormat(self.as_bitstream())
Beispiel #11
0
 def _struct_write(self, struct, bitstream):
     format = IFormat(self.format)
     format = IStructEvaluateable(format)._evaluate(struct)
     bitstream.write(self._filter_write(struct, self._struct_get(struct)),
                     format)
Beispiel #12
0
 def _pre_write(self, struct):
     IFormat(self.format)._pre_write(struct, self)