Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Structure padding

Tags:

c

I am learning structure padding and packing in C. I have this doubt, as I have read padding will depend on architecture, so does it affect inter machine communication?, ie. if data created on one machine is getting read on other machine. How this problem is avoided in this scenario.

like image 341
user2333014 Avatar asked May 07 '13 02:05

user2333014


1 Answers

Yes, you cannot send the binary data of a structure between platforms and expect it to look the same on the other side.

The way you solve it is you create a marshaller/demarshaller for your construct and pass it through on the way out of one system, and on the way in to the other system. This lets the compiler take care of the buffering for you on each system.

Each side knows how to take the data, as you've specified it will be sent, and deal with it for the local platform.

Platforms such as java handle this for you by creating serialization mechanisms for your classes. In C, you'll need to do this for yourself. How you do it depends on how you want to send your data. You could serialize to binary, XML, or anything else.

like image 151
xaxxon Avatar answered Sep 23 '22 01:09

xaxxon