[Bf-extensions-cvs] [ecf6619] master: blendfile.py: Add support reading single char DNA values as unsigned integer.
Bastien Montagne
noreply at git.blender.org
Thu Dec 1 13:02:07 CET 2016
Commit: ecf6619d82058d808a4c17629e96db6b02b29b80
Author: Bastien Montagne
Date: Thu Dec 1 13:00:30 2016 +0100
Branches: master
https://developer.blender.org/rBAecf6619d82058d808a4c17629e96db6b02b29b80
blendfile.py: Add support reading single char DNA values as unsigned integer.
A single char is nearly never a string or byte, but rather a small int
or bitflag value. ;)
===================================================================
M io_blend_utils/blend/blendfile.py
===================================================================
diff --git a/io_blend_utils/blend/blendfile.py b/io_blend_utils/blend/blendfile.py
index 012719f..c7a83c3 100644
--- a/io_blend_utils/blend/blendfile.py
+++ b/io_blend_utils/blend/blendfile.py
@@ -768,6 +768,7 @@ class DNAStruct:
dna_type = field.dna_type
dna_name = field.dna_name
+ dna_size = field.dna_size
if dna_name.is_pointer:
return DNA_IO.read_pointer(handle, header)
@@ -788,6 +789,9 @@ class DNAStruct:
return [DNA_IO.read_float(handle, header) for i in range(dna_name.array_size)]
return DNA_IO.read_float(handle, header)
elif dna_type.dna_type_id == b'char':
+ if dna_size == 1:
+ # Single char, assume it's bitflag or int value, and not a string/bytes data...
+ return DNA_IO.read_char(handle, header)
if use_str:
if use_nil:
return DNA_IO.read_string0(handle, dna_name.array_size)
@@ -882,6 +886,13 @@ class DNA_IO:
add = data.find(b'\0')
return data[:add]
+ UCHAR = struct.Struct(b'<b'), struct.Struct(b'>b')
+
+ @staticmethod
+ def read_char(handle, fileheader):
+ st = DNA_IO.UCHAR[fileheader.endian_index]
+ return st.unpack(handle.read(st.size))[0]
+
USHORT = struct.Struct(b'<H'), struct.Struct(b'>H')
@staticmethod
More information about the Bf-extensions-cvs
mailing list