序列化用例 [英] Serialization Use Cases

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

问题描述

我不清楚什么时候应该使用序列化/反序列化技术

It's not clear to me when should one use serialization / deserialization techniques

谁能给我提供一些基本的用例场景?

Can anybody provide me some basic use case scenarios?

推荐答案

序列化是将对象转换为某种编码表示以将其从一处移动到另一处的过程.通常,这是将对象转换为字节数组或 XML 字符串之类的过程,但如果您愿意,也可以序列化为其他格式.

Serialization is the process for turning an object into some kind of encoded representation to move it from one place to another. Usually, it's the process of turning an object into something like a byte array or XML string, though you could serialize to other formats if you wanted to.

序列化最常见的用途是当您需要跨进程、机器或更准确地跨 AppDomain 边界移动对象时.因此,如果您想将对象从服务器 A 发送到服务器 B,则必须在服务器 A 上序列化该对象,然后将该对象的编码表示发送到服务器 B,并让服务器 B 反序列化该对象以便使用它在另一端.

The most common use of serialization is when you need to move an object across process, machine, or, more precisely, AppDomain boundaries. So if you want to send an object from Server A to Server B, you'd have to serialize the object on Server A, then send that encoded representation of the object to Server B, and have Server B deserialize the object in order to use it on the other end.

并非所有对象都可以轻松序列化——例如,如果将指针发送到另一台服务器,则在内存中具有指向服务器上某个位置的指针的对象可能没有意义.在这种情况下,您必须编写自己的自定义逻辑来确定如何处理该指针.也许您根本不会序列化对象的该属性……也许您还会序列化指针指向的对象——这取决于您.这就是序列化并不总是容易或自动的原因.

Not all objects are easily serializable -- for example, objects which have pointers in memory to some location on a server probably won't make sense if the pointer is sent to another server. In a case like this, you would have to write your own custom logic to determine what to do with that pointer. Perhaps you wouldn't serialize that property of your object at all... Perhaps you'd also serialize what the object that the pointer points to -- it's going to be up to you. That's why serialization isn't always easy or automatic.

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

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