Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 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; }; Commented Feb 3, 2019 at 18:42
  • 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. Commented Feb 3, 2019 at 19:21
  • 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. Commented Feb 3, 2019 at 19:49