Skip to main content

Timeline for answer to Using c style structure in Python by maxy

Current License: CC BY-SA 4.0

Post Revisions

5 events
when toggle format what by license comment
Feb 3, 2019 at 19:49 comment added Ankit Duggal Hmm. I think i should just use a bytearray of 32 bytes and program my parameters into it as requested by caller. Then iterate over this bytearray and copy 32 bytes into the destination buffer. What doesn't look good here is that i am programming a well defined packet in a bytearray and not a user defined object type which resembles that packet. But i think that is all i can do in this case. Thanks for your help anyways.
Feb 3, 2019 at 19:21 comment added maxy In Python you don't have raw memory access. You cannot control the memory layout of Python objects. There is no pointer arithmetic, except through libraries that create a wrapper around a raw buffer, like numpy. Have a look how reference counting works in the API, this may clarify things for you.
Feb 3, 2019 at 18:42 comment added Ankit Duggal I think i haven't been able to clearly explain what my situation is. And apologise because i am coming from a C background. Let's take the following structure as an example. In my python script i want to form a struct of this format and then copy it byte by byte over to a buffer in memory. I am still not clear how this can be done in Python. struct pktdef { uint8_t opCode; uint8_t subOpCode; uint16_t paramList; uint32_t addr; uint32_t size; uint8_t flag1; uint8_t flag2; uint16_t debugInfo; };
Feb 3, 2019 at 14:31 history edited maxy CC BY-SA 4.0
added 4 characters in body
Feb 3, 2019 at 14:21 history answered maxy CC BY-SA 4.0