Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is serialization a must in order to transfer data across the wire?

Tags:

java

python

c

c#

Below is something I read and was wondering if the statement is true.

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be "resurrected" later in the same or another computer environment.[1] When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward.

like image 961
user770022 Avatar asked Nov 14 '10 03:11

user770022


2 Answers

The real problem here is not getting over the wire, the problem is ending up with the same semantic object on the other side of the wire. For properly transporting data between dissimilar systems -- whether via TCP/IP, floppy, or punch card -- the data must be encoded (serialized) into a platform independent representation.

Because of alignment and type-size issues, if you attempted to do a straight binary transfer of your object it would cause Undefined Behavior (to borrow the definition from the C/C++ standards).

For example the size and alignment of the long datatype can differ between architectures, platforms, languages, and even different builds of the same compiler.

like image 58
joshperry Avatar answered Oct 23 '22 03:10

joshperry


Serialization is just a fancy way of describing what you do when you want a certain data structure, class, etc to be transmitted.

For example, say I have a structure:

struct Color
{
    int R, G, B;
};

When you transmit this over a network you don't say send Color. You create a line of bits and send it. I could create an unsigned char* and concatenate R, G, and B and then send these. I just did serialization

like image 37
flumpb Avatar answered Oct 23 '22 04:10

flumpb