| 785 | |
| 786 | class LongUtf(Utf): |
| 787 | def decode(self, io): |
| 788 | raw_length = io.read(8) |
| 789 | if not raw_length or len(raw_length) != 8: |
| 790 | raise Exception('Failed to unserialize LongUtf') |
| 791 | self.length = struct.unpack('>Q', raw_length)[0] |
| 792 | if self.length == 0: |
| 793 | self.contents = "" |
| 794 | else: |
| 795 | self.contents = io.read(self.length) |
| 796 | if not self.contents or len(self.contents) != self.length: |
| 797 | raise Exception('Failed to unserialize LongUtf') |
| 798 | return self |
| 799 | |
| 800 | def encode(self): |
| 801 | encoded = struct.pack('>Q', [self.length]) |