Beispiel #1
0
 def from_bitstream(cls, bitstream):
     instance = cls.__new__(cls)
     Struct.__init__(instance)
     instance.TEMP_FIELDS = {}
     statements = {}
     for statement in instance.create_fields():
         statement = IStructStatement(statement)
         statement._pre_read(instance)
         statements[statement] = statement
     instance.reading = True
     for statement in instance.create_fields():
         statement = IStructStatement(statements.get(statement, statement))
         statement._struct_read(instance, bitstream)
     del instance.TEMP_FIELDS
     instance.reading = False
     return instance
Beispiel #2
0
 def as_bitstream(self):
     bitstream = BitStream()
     bitstream.byte_aligned = getattr(self.create_fields, "byte_aligned",
                                      False)
     self.TEMP_FIELDS = {}
     statements = {}
     for statement in self.create_fields():
         statement = IStructStatement(statement)
         statement._pre_write(self)
         statements[statement] = statement
     self.writing = True
     for statement in self.create_fields():
         statement = IStructStatement(statements.get(statement, statement))
         statement._struct_write(self, bitstream)
     del self.TEMP_FIELDS
     self.writing = False
     bitstream.seek(0)
     return bitstream
Beispiel #3
0
 def from_bitstream(cls, bitstream):
     instance = cls.__new__(cls)
     Struct.__init__(instance)
     instance.TEMP_FIELDS = {}
     statements = {}
     for statement in instance.create_fields():
         statement = IStructStatement(statement)
         statement._pre_read(instance)
         statements[statement] = statement
     instance.reading = True
     for statement in instance.create_fields():
         statement = IStructStatement(statements.get(statement, statement))
         statement._struct_read(instance, bitstream)
     del instance.TEMP_FIELDS
     instance.reading = False
     return instance
Beispiel #4
0
 def as_bitstream(self):
     bitstream = BitStream()
     bitstream.byte_aligned = getattr(self.create_fields, "byte_aligned", False)
     self.TEMP_FIELDS = {}
     statements = {}
     for statement in self.create_fields():
         statement = IStructStatement(statement)
         statement._pre_write(self)
         statements[statement] = statement
     self.writing = True
     for statement in self.create_fields():
         statement = IStructStatement(statements.get(statement, statement))
         statement._struct_write(self, bitstream)
     del self.TEMP_FIELDS
     self.writing = False
     bitstream.seek(0)
     return bitstream