Hello, I need a little help with void pointers. Say I read a packet into this:
void *packet = malloc( msgSize );
I'll know from how I sent it that the first integer will be a packet ID. From that ID, I'll know what I can do with it.
The main thing I'll need is to copy it to a struct but i don't know how to do that with memcpy. There will be different sized structs for player, enemy, projectile but a simple example should help.
Also, how can I "traverse" the memory to look for something, assuming there are different sized data in the packet. For example, if I know that the first item is an int, then a char, then another int, then float, etc., how do I get the value of the float? I assume this involves the use of sizeof but I'm not good with pointers. Then I read that sometimes structures are padded so maybe this is impossible - though I'll have the structure declarations I sent (if that makes sense) so maybe I could use that to determine how many bytes in the float starts.
Thanks for reading and any help.