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]
|
sdna_index = self.bfile.sdna_index_from_id[dna_type_id]
|
||||||
self.refine_type_from_index(sdna_index)
|
self.refine_type_from_index(sdna_index)
|
||||||
|
|
||||||
def get_file_offset(self, path: bytes) -> (int, int): # TODO(Sybren): port to BAT
|
def abs_offset(self, path: dna.FieldPath) -> (int, int):
|
||||||
"""Return (offset, length)"""
|
"""Compute the absolute file offset of the field.
|
||||||
assert isinstance(path, bytes)
|
|
||||||
|
|
||||||
# TODO: refactor to just return the length, and check whether this isn't actually
|
:returns: tuple (offset in bytes, length of array in items)
|
||||||
# simply the same as self.size.
|
"""
|
||||||
ofs = self.file_offset
|
field, field_offset = self.dna_type.field_from_path(self.bfile.header.pointer_size, path)
|
||||||
field, _ = self.dna_type.field_from_path(self.bfile.header.pointer_size, path)
|
return self.file_offset + field_offset, field.name.array_size
|
||||||
return ofs, field.name.array_size
|
|
||||||
|
|
||||||
def get(self,
|
def get(self,
|
||||||
path: dna.FieldPath,
|
path: dna.FieldPath,
|
||||||
|
|||||||
@ -206,6 +206,15 @@ class PointerTest(AbstractBlendFileTest):
|
|||||||
with self.assertRaises(exceptions.SegmentationFault):
|
with self.assertRaises(exceptions.SegmentationFault):
|
||||||
scene.get_pointer(b'ed')
|
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):
|
class LoadCompressedTest(AbstractBlendFileTest):
|
||||||
def test_loading(self):
|
def test_loading(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user