Search code examples
cipcstructvoid-pointerslcm

How to dereference multiple void pointers in structs into 1 piece of memory?


I am working on a project where I need to send over a certain IPC stack, (in my case, LCM), and the thing is I need to provide the IPC a variable length struct. I have

struct pack1 {int value1; int value2;};
struct pack2 {void *data; int data_size;}; 
//data won't always point to pack1 types

I have a pointer to pack2, and I need something like serialization, so I can send this pack2 over the network to another process.

Anyone knows how?


Solution

  • LCM supports variable length arrays, see the "Arrays" section in the reference manual: http://lcm.googlecode.com/svn-history/r401/www/reference/lcm/tutorial-lcm-language.html

    However, your data is accessed via void*, which is just a pointer to an "unknown" type. If your data is just bytes, then it might work to treat it as a byte array, like this in your LCM definition:

    struct pack2 {
      int32_t data_size;
      unsigned char data[data_size};
    }