什么是对象序列化和反序列化? [英] What are object serialization and deserialization?

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

问题描述

什么是对象序列化反序列化?

序列化与普通技术(例如读取对象的属性,然后用它们填充DataRow的列并最终将DataRow保存在DB中)有什么区别?

解决方案

串行化通常是指创建可用于存储(也许在文件中)的数据(而不是对象)的版本,以便通过网络,或者仅用于在单台计算机上的进程/AppDomain/etc之间进行传输.

串行化通常意味着将数据写为字符串(例如:xml/json)或原始二进制文件(byte[]等).反序列化是相反的过程.提取原始数据(从文件,传入的网络套接字等)并重建对象模型.

使用db的区别在于它没有固有的表格布局,也没有与数据库的真正联系.数据可以是任何形状,并且更倾向于映射到面向对象的布局,而不是映射到表的行/列性质.

大多数平台都有一系列的序列化工具.例如,听起来您在谈论.NET,因此BinaryFormatter(特定于.NET),XmlSerializerDataContractSerializer,Json.NET和protobuf-net/dotnet-protobufs都符合条件.

What are object serialization and deserialization?

What difference does serialization have with normal techniques like reading an object's properties and then filling a DataRow's columns with them and finally saving the DataRow in DB?

解决方案

Serialization generally refers to creating a version of the data (rather than the objects) that can be used for storage (perhaps in a file), for transfer over a network, or perhaps just for transfer between processes / AppDomains /etc on a single machine.

Serialization typically means writing the data as a string (think: xml / json) or as raw binary (a byte[] etc). Deserialization is the reverse process; taking the raw data (from a file, from an incoming network socket, etc) and reconstructing the object model.

The difference between using a db is that it has no intrinsic tabular layout, and no real tie to a database; the data can be any shape, and tends to map more closely to the object-oriented layout than to the rows/columns nature of tables.

Most platforms have a range of serialization tools. For example, it sounds like you're talking about .NET - so BinaryFormatter (.NET-specific), XmlSerializer, DataContractSerializer, Json.NET and protobuf-net / dotnet-protobufs would all qualify.

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

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