Chapter 4: Serialization


Overview

Serialization is the process of packaging data structures into a format that can be easily transported. Typically, an instance of a class in one process is taken and sent to another process over some kind of streaming mechanism such that the remote process can reconstruct an instance of the same class with the same member values. This chapter will discuss the process of serialization as well as the different types of serialization available.

Serialization is a very powerful and useful mechanism for sharing data. If you ve ever had to send all the properties or data or both associated with a data structure to another process, say on another machine, you re familiar with the difficulty. The challenge is that a class or other data structure can reference memory and pointers that are valid only in the context of the current process. Implementing your own scheme for packaging complex structures can be extremely cumbersome, especially if the members are variable-length arrays or arbitrary string values. Fortunately, the Microsoft Windows .NET Framework offers built-in support for serialization.

Note  

In our scenario, we transport the structure across process boundaries, but with the .NET Framework, serialization can occur over application domains. An application domain can be a process boundary, but it can also be an application running in a sandbox in a process with other applications. Application domains will be covered in more detail in Chapter 12.

In the .NET Framework, objects are serialized onto a stream and deserialized from a stream. As we saw in Chapter 2, a stream can take many forms ” network, memory, file, and so on. In this chapter, we ll concentrate on the process of serialization and deserialization and not the medium over which it is transported. Before getting into the details of serialization, we ll first look at the different formats that data can be serialized into. Then we ll have a detailed discussion of each type of serialization.




Network Programming for the Microsoft. NET Framework
Network Programming for the MicrosoftВ® .NET Framework (Pro-Developer)
ISBN: 073561959X
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net