编程语言中的序列化是什么意思? [英] What is the meaning of serialization in programming languages?

查看:58
本文介绍了编程语言中的序列化是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编程语言中的序列化概念是什么意思?

What is the meaning of serialization concept in programming languages?

当我们在类上方使用 Serializable 属性时,这是什么意思?

when we use Serializable attribute above a class, what is the meaning?

推荐答案

假设您有两个在两个不同的物理计算机上运行的应用程序.两个应用程序都需要交换两个应用程序通常使用的数据.这些应用程序互相交谈以与某些介质共享数据,这些介质可以是文件系统,tcp或udp连接或任何其他合适的网络协议,或者可以是内存中的直接数据交换.这些介质中的任何一种都只能理解以一系列比特形式描述的数据.因此,当一个应用程序需要将值10发送给另一个应用程序时,该值10将以其二进制表示形式1010发送,并且您还将传递一些描述1010的信息.此元信息还将是其他应用程序可以使用的一系列位容易理解.不过那很容易.

Say you have two applications that run on two different physical machines. Both of the applications need to exchange data that is commonly used by both applications. These application talk to each other to share the data with some mediums, these mediums could be a file-system, tcp or udp connections or any other suitable network protocol or may be direct in-memory data exchange. Any of these mediums would only understand data that is described in the form of a series of bits. So when one application needs to send a value 10 to another, the value 10 would be sent as its binary representation 1010 and you would also pass some information that describes 1010. This meta information will also be a series of bits that the other application can easily understand. That was easy though.

再举一个例子,其中这两个应用程序需要交换更复杂的非原始数据类型.假设他们需要交换Book类型的对象,其中Book是应用程序中的一个自定义类,并且两个应用程序都具有Book类型的定义.

Lets take another example, wherein these two apps need to exchange a more complex, non primitive data-type. Lets say they need to exchange the objects of type Book where Book is a custom defined class in your application and both the applications have the definition of type Book.

public class Book
{
    Book() { }

    public long BookId { get;set; }
    public string Author { get;set; }
    public string Title { get;set; }
}

您将如何在两个应用程序之间交换book类型的对象?为了能够在两个应用程序之间共享对象,您将需要能够将Book对象转换为二进制表示形式.这是序列化的体现.

How will you exchange the objects of type book between the two applications? To be able to share the object between two apps, you will need to be able to convert the Book objects into binary representation. This is where serialization comes into the picture.

借助序列化,您可以定义如何将对象转换为其二进制表示形式.接收应用程序将执行相反的过程,即反序列化,该过程会从二进制表示形式构造Book对象.

With the help of Serialization you can define how an object can be converted into its binary representation. The receiving application would do the reverse process, that is De-Serialization, that constructs a Book object from its binary representation.

这篇关于编程语言中的序列化是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆