Unpack bytes containing packed C structure data
Parameters: |
-
buffer
(Optional[bytes] )
–
-
offset
(int , default:
0
)
–
-
flexible_array_length
(Optional[int] , default:
None
)
–
optional flexible array lenght (number of elements)
|
cstruct/cstruct.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 | def unpack_from(self, buffer: Optional[bytes], offset: int = 0, flexible_array_length: Optional[int] = None) -> bool:
"""
Unpack bytes containing packed C structure data
Args:
buffer: bytes to be unpacked
offset: optional buffer offset
flexible_array_length: optional flexible array lenght (number of elements)
"""
self.set_flexible_array_length(flexible_array_length)
if buffer is None:
buffer = CHAR_ZERO * self.size
for field, field_type in self.__fields_types__.items():
setattr(self, field, field_type.unpack_from(buffer, offset))
return True
|