我知道在一些分布式技术(如RPC)中,使用了术语“封送”,但不理解它与序列化有何不同。它们不是都在把对象转换成一系列的比特吗?
相关:
什么是序列化?
什么是对象编组?
我知道在一些分布式技术(如RPC)中,使用了术语“封送”,但不理解它与序列化有何不同。它们不是都在把对象转换成一系列的比特吗?
相关:
什么是序列化?
什么是对象编组?
当前回答
来自编组(计算机科学)维基百科的文章:
The term "marshal" is considered to be synonymous with "serialize" in the Python standard library1, but the terms are not synonymous in the Java-related RFC 2713: To "marshal" an object means to record its state and codebase(s) in such a way that when the marshalled object is "unmarshalled", a copy of the original object is obtained, possibly by automatically loading the class definitions of the object. You can marshal any object that is serializable or remote. Marshalling is like serialization, except marshalling also records codebases. Marshalling is different from serialization in that marshalling treats remote objects specially. (RFC 2713) To "serialize" an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.
因此,编组除了保存对象的状态外,还在字节流中保存对象的代码库。
其他回答
我认为主要的区别在于编组应该也涉及到代码库。换句话说,您将无法将对象编组或反编组到不同类的状态等效实例中。
序列化只是意味着您可以存储对象并重新获得等效的状态,即使它是另一个类的实例。
也就是说,它们通常是同义词。
来自编组(计算机科学)维基百科的文章:
The term "marshal" is considered to be synonymous with "serialize" in the Python standard library1, but the terms are not synonymous in the Java-related RFC 2713: To "marshal" an object means to record its state and codebase(s) in such a way that when the marshalled object is "unmarshalled", a copy of the original object is obtained, possibly by automatically loading the class definitions of the object. You can marshal any object that is serializable or remote. Marshalling is like serialization, except marshalling also records codebases. Marshalling is different from serialization in that marshalling treats remote objects specially. (RFC 2713) To "serialize" an object means to convert its state into a byte stream in such a way that the byte stream can be converted back into a copy of the object.
因此,编组除了保存对象的状态外,还在字节流中保存对象的代码库。
封送处理是指将函数的签名和参数转换为单字节数组。 专门用于RPC的目的。
序列化通常是指将整个对象/对象树转换为字节数组 封送处理将序列化对象参数,以便将它们添加到消息中并通过网络传递。 序列化也可以用于存储到磁盘
编组通常在相对紧密关联的进程之间进行;序列化不一定有这种期望。因此,当在进程之间编组数据时,例如,您可能希望仅发送一个引用到可能昂贵的数据以进行恢复,而使用序列化时,您可能希望保存所有数据,以便在反序列化时正确地重新创建对象。
在远程过程调用的上下文中,封送处理和序列化大体上是同义的,但在语义上就意图而言是不同的。
特别地,封送处理是关于从这里到那里获取参数,而序列化是关于将结构化数据复制到字节流等基本形式或从中复制。在这个意义上,序列化是执行封送处理的一种方法,通常实现值传递语义。
也可以通过引用封送对象,在这种情况下,“在线上”的数据只是原始对象的位置信息。但是,这样的对象仍然可以接受值序列化。
正如@Bill提到的,可能会有额外的元数据,比如代码基位置,甚至是对象实现代码。