Ported get_file_offset() and renamed to abs_offset()
This commit is contained in:
parent
aed1827ff7
commit
bce5f4b670
@ -372,15 +372,13 @@ class BlendFileBlock:
|
||||
sdna_index = self.bfile.sdna_index_from_id[dna_type_id]
|
||||
self.refine_type_from_index(sdna_index)
|
||||
|
||||
def get_file_offset(self, path: bytes) -> (int, int): # TODO(Sybren): port to BAT
|
||||
"""Return (offset, length)"""
|
||||
assert isinstance(path, bytes)
|
||||
def abs_offset(self, path: dna.FieldPath) -> (int, int):
|
||||
"""Compute the absolute file offset of the field.
|
||||
|
||||
# TODO: refactor to just return the length, and check whether this isn't actually
|
||||
# simply the same as self.size.
|
||||
ofs = self.file_offset
|
||||
field, _ = self.dna_type.field_from_path(self.bfile.header.pointer_size, path)
|
||||
return ofs, field.name.array_size
|
||||
:returns: tuple (offset in bytes, length of array in items)
|
||||
"""
|
||||
field, field_offset = self.dna_type.field_from_path(self.bfile.header.pointer_size, path)
|
||||
return self.file_offset + field_offset, field.name.array_size
|
||||
|
||||
def get(self,
|
||||
path: dna.FieldPath,
|
||||
|
||||
@ -206,6 +206,15 @@ class PointerTest(AbstractBlendFileTest):
|
||||
with self.assertRaises(exceptions.SegmentationFault):
|
||||
scene.get_pointer(b'ed')
|
||||
|
||||
def test_abs_offset(self):
|
||||
scene = self.bf.code_index[b'SC'][0]
|
||||
ed = scene.get_pointer(b'ed')
|
||||
assert isinstance(ed, blendfile.BlendFileBlock)
|
||||
|
||||
abs_offset, field_size = ed.abs_offset((b'seqbase', b'first'))
|
||||
self.assertEqual(ed.file_offset + 8, abs_offset)
|
||||
self.assertEqual(1, field_size)
|
||||
|
||||
|
||||
class LoadCompressedTest(AbstractBlendFileTest):
|
||||
def test_loading(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user