def deserialize(self, reader: io.IOBase) -> 'ILTag': tag_offset = reader.tell() try: tag_id, _ = pyilint.ilint_decode_from_stream(reader) tag = self.create(tag_id) if tag is None: if self.strict or iltags_is_implicit(tag_id): raise ILTagUnknownError( f'Unknown tag with id {id} at {tag_offset}.') else: tag = ILRawTag(tag_id) if iltags_is_implicit(tag_id): tag_size = ILStandardTagFactory.ILTAG_IMPLICIT_SIZES[tag_id] else: tag_size, _ = pyilint.ilint_decode_from_stream(reader) if tag_id == ILTAG_ILINT64_ID: tag.deserialize_value(self, tag_size, reader) else: value_reader = io.BytesIO(read_bytes(tag_size, reader)) tag.deserialize_value(self, tag_size, value_reader) left_behind = tag_size - value_reader.tell() if left_behind != 0: raise ILTagCorruptedError( f'The tag at {tag_offset} with id {tag_id} and size {tag_size} could not be deserialized by the class {tag.__class__}. {left_behind} bytes were not used.' ) return tag except (ValueError, EOFError): raise ILTagCorruptedError(f'Corrupted tag at {tag_offset}.')
def deserialize_value(self, tag_factory: ILTagFactory, tag_size: int, reader: io.IOBase) -> None: if tag_size < 1: raise ILTagCorruptedError('Corrupted tag.') self.clear() count, _ = pyilint.ilint_decode_from_stream(reader) for i in range(count): v, _ = pyilint.ilint_decode_from_stream(reader) self.append(v)
def deserialize_value(self, tag_factory: ILTagFactory, tag_size: int, reader: io.IOBase) -> None: if tag_size < 3: raise ILTagCorruptedError('Corrupted range.') try: first, _ = pyilint.ilint_decode_from_stream(reader) count = read_int(2, False, reader) self.first = first self.count = count except ValueError: raise ILTagCorruptedError('Corrupted range.')
def deserialize_value(self, tag_factory: ILTagFactory, tag_size: int, reader: io.IOBase) -> None: if tag_size < 1: raise ILTagCorruptedError('Corrupted tag.') count, _ = pyilint.ilint_decode_from_stream(reader) self.clear() for i in range(count): key = tag_factory.deserialize(reader) if not ILStringTag.is_standard_string(key): raise ILTagCorruptedError( 'Corrupted tag. One of the keys is not a string.') value = tag_factory.deserialize(reader) self[key.value] = value
def deserialize_value(self, tag_factory: ILTagFactory, tag_size: int, reader: io.IOBase) -> None: if tag_size < 1: raise ILTagCorruptedError('Corrupted tag.') reader = LimitedReaderWrapper(reader, tag_size) self.clear() try: count, _ = pyilint.ilint_decode_from_stream(reader) except ValueError: raise ILTagCorruptedError('Corrupted tag.') for i in range(count): t = tag_factory.deserialize(reader) self.append(t)