Serialization


Serialization is the process of converting an object into a stream of data so that it can be made transmittable over the network

Serialization



Serialization is the process of converting an object into a stream of data so that it can be easily transmittable over the network

if you want to store an object (or multiple objects) in a file for later retrieval,
you store the output of serialization. The next time you want to read the objects, you
call the deserialization methods

To Serialize



* Create an object Stream
* Create a BinaryFormatter
* Call the BinaryFormatter.Serialize method to serialize


Dim data As String = "This must be stored in a file or folder"
Dim fs As FileStream = New FileStream("SerializedString.Data", _
FileMode.Create)
Dim bf As BinaryFormatter = New BinaryFormatter
bf.Serialize(fs, data)
fs.Close


If you open the file in a notepad you can notice the contents of your file surrounded by binary numbers

DeSerialiazation



Deserialization is the process of converting a previously serialized sequence of bytes into an object

To Deserialize



* Create an object Stream to read a serialized output
* Create a BinaryFormatter object
* Create an object to store a Deserialized data
* USE the BinaryFormatter.Deserialize method to deserialize the object


Dim fs As FileStream = New FileStream("SerializedString.Data", FileMode.Open)
Dim bf As BinaryFormatter = New BinaryFormatter
Dim data As String = ""
data = DirectCast(bf.Deserialize(fs), String)
fs.Close
Console.WriteLine(data)


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: