c++ type structure example:
Struct xyz {
uint64_t a;
uint32_t b;
uint16_t c;
bool d;
char e;
} var;
where I can access it using var.a = 1; var.b = 2
, and so on...
Here I have a array to initialize this struct, like take a list of python:
values = [0x64, 0x32, 0x16, true, 'a'];
I need to map this list value to struct elements, So that it can be accessed using var.a if print var.a it should print 0x64
Kindly suggest how entire scenario can be implemented in python in most efficient way. What I have implemented is as like below:
Class xyz(Structure):
__field__ [
(a, c_uint64, 64),
(b, c_uint32, 32),
(c, c_uint16, 16),
(d, c_bool),
(e, c_char)
]
def __init__(self, p, q, r, s, t):
self.a = p
self.b = q
self.c = r
self.d = s
self.e = t
obj = xyz(10, 11, 12, True, 'R')
It works fine, whether this is the proper usage or Is there some better option. This also gives me privilege for bi fields might be the case where I need int of 14 bits.