Serialization and deserialization are probably familiar to the peers who engage in the underlying information communication. Out of many written standard concepts, the nature of serialization and deserialization is, in the sense of personal understanding, in order to find a common universal data format to reach an unbounded realm, just as dialects for Putonghua, languages for English. What we need to do is to find a specific format and complete a relatively symmetric feature, like compression and decompression.
Regular serialization and deserialization formats typically include the following: Binary,json, XML, SOAP, and so on. Of course there are other, this can only forgive me ignorant. Usually we choose short and short JSON and more general XML, and of course many peers will use soap. I will also use JSON, after all, Newtonsoft.json strong or self-evident, (for Ali Fastjson, I can only deep sympathy, elder brother know is not your fault, this is something). But not common binary figure, let me deeply surprised, perhaps I experience is not deep, hereby introspection. However, many communication underlying such as the socket or TCP or UDP above, only use binary as the basic format of communication, do not deny the use of other means to obtain binary data. However, it is not better to have a more generic direct binary serialization and deserialization class library or a rack package. So determined to make a binary serialization and deserialization of the class library, of course, for the needs of the work, for the code is now inconvenient to post out, out of professional ethics, so temporarily deeply sorry. First to share their own erection and the problems encountered during the period, of course, there is the right time, I still hope that this can become a part of open source, but also I hope that the next thing to do.
Before, I have to admit that this is not original, many design principles inspired by the design of similar software, after all, standing on the shoulders of giants to see farther. So before, I will take Newtonsoft.json for example, is also my current use of relatively more software, of course, this approximate universal Class library also has a lot of its own limitations, such as the one that does not support byte[] serialization and deserialization is very strange, do not know what is the mentality and consideration, It is probably the feeling that many people will turn the string into a repetition of the conversion of a byte, which is also a starting point for me to be my binary serialization class library. Of course, let's see how it's done.
JsonConvert is the entrance to the Newtonsoft.json, through the source analysis, you will indeed find in this as the entrance of the ecological park is a rich world, when you have a taste of the entrance after you look back, you will again find that the entrance is indeed appropriate, wonderful to the top. Perhaps slightly exaggerated, in my opinion, this application of a classic façade pattern, and this application is really very useful.
Let's start by looking at how it works. First when we use JsonConvert. SerializeObject (object), it first creates a temporary StringBuilder temporary data pool for the purpose of which I am not suing. and construct a data writer at the same time Jsonwriter is responsible for the sequential writing of the converted string fragment, here emphasizes the orderly writing, because this is very fastidious, This is also a relatively important reason why Newtonsoft.json does not adopt concurrent read and write, and of course it is more important that concurrent read and write is not controllable. After the preparation is done, it needs to describe the object as a file description, generating the corresponding jsoncontract to facilitate the control of subsequent encoding conversion behavior. The encoding conversion layer is the true completion of all types of conversions. According to Jsoncontract,newtonsoft.json, you can identify what kind of jsonconverter you need to handle. When a specific jsonconverter is found, it can be used to convert the target into a string written to the data pool via Jsonwriter. The same is the case with deserialization, just a process reversal.
Here we need to grasp a few key points and the difficulty, first how to define the Jasncontract, this class in my opinion is the whole class library core components, seemingly insignificant, but actually is very important, because the real scheduling is actually made by it. The second need to find a variety of basic types of conversion to the common type of path, the 3rd is to find a way to customize the type of conversion methods.
The next one should be a design for the specific custom binary serialization and deserialization process.