Exemple #1
0
 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)
Exemple #2
0
 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)