| 120 | |
| 121 | |
| 122 | class BlockDataLong(Element): |
| 123 | def __init__(self, stream=None, contents=''): |
| 124 | Element.__init__(self, stream) |
| 125 | self.contents = contents |
| 126 | self.length = len(contents) |
| 127 | |
| 128 | def decode(self, io): |
| 129 | raw_length = io.read(4) |
| 130 | if not raw_length or len(raw_length) != 4: |
| 131 | raise Exception('Failed to unserialize BlockDataLong') |
| 132 | self.length = struct.unpack('>i', raw_length)[0] |
| 133 | if self.length == 0: |
| 134 | self.contents = '' |
| 135 | else: |
| 136 | self.contents = io.read(self.length) |
| 137 | if not self.contents or len(self.contents) != self.length: |
| 138 | raise Exception('Failed to unserialize BlockDataLong') |
| 139 | return self |
| 140 | |
| 141 | def encode(self): |
| 142 | encoded = struct.pack(">I", [self.length]) |
| 143 | encoded += self.contents |
| 144 | return encoded |
| 145 | |
| 146 | def __str__(self): |
| 147 | return self.contents.__str__() |
| 148 | |
| 149 | |
| 150 | class ClassDesc(Element): |