Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between serializing and encoding?

What is the difference between serializing and encoding? When should I use each in a web service?

like image 841
Rodniko Avatar asked Sep 24 '10 04:09

Rodniko


People also ask

What does serializing mean in coding?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

What does serializing a model mean?

Serialization refers to the process of converting a data object (e.g., Python objects, Tensorflow models) into a format that allows us to store or transmit the data and then recreate the object when needed using the reverse process of deserialization.

What does serializing data do?

Data serialization is the process of converting structured data to a format that allows sharing or storage of the data in a form that allows recovery of its original structure.


2 Answers

Serializing is about moving structured data over a storage/transmission medium in a way that the structure can be maintained. Encoding is more broad, like about how said data is converted to different forms, etc. Perhaps you could think about serializing being a subset of encoding in this example.

With regard to a web service, you will probably be considering serializing/deserializing certain data for making/receiving requests/responses - effectively transporting "messages". Encoding is at a lower level, like how your messaging/web service type/serialization mechanism works under the hood.

like image 147
Matt Kocaj Avatar answered Oct 03 '22 04:10

Matt Kocaj


"Serialization" is the process of converting data (which may include arrays, objects and similar structures) into a single string so it can be stored or transmitted easily. For instance, a single database field can't store an array because database engines don't understand that concept. To be stored in a database, an array must either be broken down into individual elements and stored in multiple fields (which only works if none of the elements are themselves arrays or objects) or it must be serialized so it can be stored as a single string in a single field. Later, the string can be retrieved from the database and unserialized, yielding a copy of the original array.

"Encoding" is a very general term, referring to any format in which data can be represented, or the process of converting data into a particular representation.

For example, in most programming languages, a sequence of data elements can be encoded as an array. (Usually we call arrays "data structures" rather than "encodings", but technically all data structures are also encodings.) Likewise, the word "encoding" itself can be encoded as a sequence of English letters. Those letters themselves may be encoded as written symbols, or as bit patterns in a text encoding such as ASCII or UTF8.

The process of encoding converts a given piece of data into another representation (another encoding, if you want to be technical about it.)

As you may have already realized, serialization is an example of an encoding process; it transforms a complex data structure into a single sequence of text characters.

That sequence of characters can then be further encoded into some sort of binary representation for more compact storage or quicker transmission. I don't know what form of binary encoding is used in BSON, but presumably it is more efficient than the bit patterns used in text encodings.

like image 20
Manish Mehta Avatar answered Oct 03 '22 02:10

Manish Mehta