我知道在一些分布式技术(如RPC)中,使用了术语“封送”,但不理解它与序列化有何不同。它们不是都在把对象转换成一系列的比特吗?
相关:
什么是序列化?
什么是对象编组?
我知道在一些分布式技术(如RPC)中,使用了术语“封送”,但不理解它与序列化有何不同。它们不是都在把对象转换成一系列的比特吗?
相关:
什么是序列化?
什么是对象编组?
当前回答
封送处理是指将函数的签名和参数转换为单字节数组。 专门用于RPC的目的。
序列化通常是指将整个对象/对象树转换为字节数组 封送处理将序列化对象参数,以便将它们添加到消息中并通过网络传递。 序列化也可以用于存储到磁盘
其他回答
在远程过程调用的上下文中,封送处理和序列化大体上是同义的,但在语义上就意图而言是不同的。
特别地,封送处理是关于从这里到那里获取参数,而序列化是关于将结构化数据复制到字节流等基本形式或从中复制。在这个意义上,序列化是执行封送处理的一种方法,通常实现值传递语义。
也可以通过引用封送对象,在这种情况下,“在线上”的数据只是原始对象的位置信息。但是,这样的对象仍然可以接受值序列化。
正如@Bill提到的,可能会有额外的元数据,比如代码基位置,甚至是对象实现代码。
来自编组(计算机科学)维基百科的文章:
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.
因此,编组除了保存对象的状态外,还在字节流中保存对象的代码库。
编组实际上使用序列化过程,但主要的区别是,它在序列化中只有数据成员和对象本身被序列化,而不是签名,但在编组对象+代码库(其实现)也将被转换为字节。
编组是使用JAXB将java对象转换为xml对象的过程,以便可以在web服务中使用它。
封送处理是指将函数的签名和参数转换为单字节数组。 专门用于RPC的目的。
序列化通常是指将整个对象/对象树转换为字节数组 封送处理将序列化对象参数,以便将它们添加到消息中并通过网络传递。 序列化也可以用于存储到磁盘
编组是告诉编译器数据将如何在另一个环境/系统上表示的规则; 例如;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string cFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
public string cAlternateFileName;
正如您可以看到的,两个不同的字符串值表示为不同的值类型。
序列化将只转换对象内容,而不是表示(将保持不变)并遵守序列化规则(导出什么或不导出什么)。例如,私有值将不会被序列化,公共值是,对象结构将保持不变。