def load(self, s: AbstractIO): self.clear() curblock = self left = s.get_uint() level = 0 stack = list() while level > -1: if left > 0: type = s.get_byte() name = s.get_widestr() if type == ElementKind.PARAM: curblock.add(name, s.get_widestr()) left -= 1 elif type == ElementKind.BLOCK: stack.append((curblock, left)) prevblock = curblock curblock = CacheData() prevblock.add(name, curblock) left = s.get_uint() level += 1 continue else: if level > 0: curblock, left = stack.pop() left -= 1 level -= 1
def load(self, s: AbstractIO): self.name = s.get_widestr() self.kind, compressed = get_kind(s.get_uint()) size = s.get_uint() if compressed: self.datatable = DataTable(get_size_by_kind(self.kind)) tempbuf = Buffer.from_bytes(s.decompress(size)) self.datatable.load(tempbuf, tempbuf.size()) tempbuf.close() del tempbuf else: self.datatable = DataTable(get_size_by_kind(self.kind)) self.datatable.load(s, size)
def load(self, s: AbstractIO): magic = s.get(4) if magic != b'STRG': s.close() raise Exception("Storage.load: wrong magic") version = s.get_uint() if version > 1: s.close() raise Exception("Storage.load: wrong version") if version == 1: tempbuf = Buffer.from_bytes(s.decompress()) s.close() s = tempbuf for i in range(s.get_uint()): record = StorageRecord() record.load(s) self.records.append(record)
def load(self, s: AbstractIO, *, new_format: bool = False): self.clear() curblock = self curblock.sorted = s.get_bool() left = s.get_uint() level = 0 stack = list() while level > -1: if left > 0: if new_format and curblock.sorted: s.get(8) type = s.get_byte() name = s.get_widestr() if type == ElementKind.PARAM: curblock.add(name, s.get_widestr()) left -= 1 elif type == ElementKind.BLOCK: stack.append((curblock, left)) prevblock = curblock curblock = BlockPar() prevblock.add(name, curblock) curblock.sorted = s.get_bool() left = s.get_uint() level += 1 continue else: if level > 0: curblock, left = stack.pop() left -= 1 level -= 1
def save(self, s: AbstractIO): initpos = s.pos() s.add_uint(0) s.add_int(len(self.entries)) s.add_int(self._el_size) datapos = s.pos() for entry in self.entries: s.add(entry) tablepos = s.pos() s.seek(initpos) s.add_uint(tablepos) s.seek(tablepos) for i in range(len(self.entries)): offset = 0 if i == 0 else len(self.entries[i - 1]) s.add_uint(datapos + offset) number = len(self.entries[i]) // self._el_size s.add_int(number) s.add_int(number)
def load(self, s: AbstractIO, size: int): initpos = s.pos() header = _header(s.get_uint(), s.get_int(), s.get_int()) for i in range(header.arrays_number): header_size = 4 * 3 # uint, uint, int offset = initpos + header.alloc_table_offset + i * header_size s.seek(offset) entry = _table_entry( s.get_uint(), s.get_int(), s.get_int(), ) start = initpos + entry.offset length = header.element_type_size * entry.number s.seek(start) self.entries.append(s.get(length)) endpos = initpos + size s.seek(endpos)
def load(self, s: AbstractIO): self.name = s.get_widestr() for i in range(s.get_uint()): item = StorageItem() item.load(s) self.items.append(item)
def save(self, s: AbstractIO): s.add_uint(len(self)) curblock = self._search_map.__iter__() left = len(self) index = 0 level = 0 stack = list() while level > -1: if left > 0: node = next(curblock) el = node.content if el.kind == ElementKind.PARAM: s.add_byte(int(ElementKind.PARAM)) s.add_widestr(el.name) s.add_widestr(el.content) left -= 1 elif el.kind == ElementKind.BLOCK: s.add_byte(int(ElementKind.BLOCK)) s.add_widestr(el.name) stack.append((curblock, left, index)) curblock = el.content._search_map.__iter__() left = len(el.content) s.add_uint(left) level += 1 else: if level > 0: curblock, left, index = stack.pop() left -= 1 level -= 1
def save(self, s: AbstractIO, *, new_format: bool = False): s.add_bool(self.sorted) s.add_uint(len(self)) is_sort = self.sorted if is_sort: curblock = self._search_map.__iter__() else: curblock = self._order_map.__iter__() left = len(self) count = 1 index = 0 level = 0 stack = list() while level > -1: if left > 0: node = next(curblock) el = node.content if new_format and is_sort: if node.count > 1: count = node.count index = 0 s.add_uint(index) if index == 0: s.add_uint(count) else: s.add_uint(0) if el.kind == ElementKind.PARAM: s.add_byte(int(ElementKind.PARAM)) s.add_widestr(el.name) s.add_widestr(el.content) left -= 1 index += 1 if index >= count: count = 1 index = 0 elif el.kind == ElementKind.BLOCK: s.add_byte(int(ElementKind.BLOCK)) s.add_widestr(el.name) stack.append((curblock, left, is_sort, count, index)) is_sort = el.content.sorted if is_sort: curblock = el.content._search_map.__iter__() else: curblock = el.content._order_map.__iter__() left = len(el.content) count = 1 index = 0 s.add_bool(is_sort) s.add_uint(left) level += 1 else: if level > 0: curblock, left, is_sort, count, index = stack.pop() left -= 1 index += 1 if index >= count: count = 1 index = 0 level -= 1