I have created subtructure and structure in ctypes as below where I am defining a array of substructure inside structure with some predefined size. (As per requirement SIZE
may be set to 0
initially and can varies based on user input).
from ctypes import *
class MySubStructure(Structure):
_fields_ = [
("sub_field1", c_uint32),
("sub_field2", c_uint32)
]
class MyStructure(Structure):
SIZE = 2
_fields_ = [
("field1", c_uint32),
("field2", c_uint32),
("sub_structure_field", ARRAY(SubStructure, SIZE)),
]
My goal is to modify this substructure based on user input.
For achieving the same I have tried below options but had no success:
Defining a
__init__
method and updating_fields_
while initializing the instanceUpdating
_fields_
after initializing instance
For both of those options I tried to appending sub_structure_field
, updating only size value by accessing through index.
Finally I just want a workaround so that I can use array of structure inside another structure either initializing at runtime or modifying at runtime.