What is the difference between Serialization and Marshaling?

前端 未结 12 1498
忘了有多久
忘了有多久 2020-12-02 03:30

I know that in terms of several distributed techniques (such as RPC), the term "Marshaling" is used but don\'t understand how it differs from Serialization. Aren\'

相关标签:
12条回答
  • 2020-12-02 03:41

    From the Marshalling (computer science) Wikipedia article:

    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.

    So, marshalling also saves the codebase of an object in the byte stream in addition to its state.

    0 讨论(0)
  • 2020-12-02 03:43

    Both do one thing in common - that is serializing an Object. Serialization is used to transfer objects or to store them. But:

    • Serialization: When you serialize an object, only the member data within that object is written to the byte stream; not the code that actually implements the object.
    • Marshalling: Term Marshalling is used when we talk about passing Object to remote objects(RMI). In Marshalling Object is serialized(member data is serialized) + Codebase is attached.

    So Serialization is part of Marshalling.

    CodeBase is information that tells the receiver of Object where the implementation of this object can be found. Any program that thinks it might ever pass an object to another program that may not have seen it before must set the codebase, so that the receiver can know where to download the code from, if it doesn't have the code available locally. The receiver will, upon deserializing the object, fetch the codebase from it and load the code from that location.

    0 讨论(0)
  • 2020-12-02 03:48

    Think of them as synonyms, both have a producer that sends stuff over to a consumer... In the end fields of instances are written into a byte stream and the other end foes the reverse ands up with the same instances.

    NB - java RMI also contains support for transporting classes that are missing from the recipient...

    0 讨论(0)
  • 2020-12-02 03:49

    Marshalling is the rule to tell compiler how the data will be represented on another environment/system; For example;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
    public string cFileName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
    public string cAlternateFileName;
    

    as you can see two different string values represented as different value types.

    Serialization will only convert object content, not representation (will stay same) and obey rules of serialization, (what to export or no). For example, private values will not be serialized, public values yes and object structure will stay same.

    0 讨论(0)
  • 2020-12-02 03:50

    Marshaling refers to converting the signature and parameters of a function into a single byte array. Specifically for the purpose of RPC.

    Serialization more often refers to converting an entire object / object tree into a byte array Marshaling will serialize object parameters in order to add them to the message and pass it across the network. *Serialization can also be used for storage to disk.*

    0 讨论(0)
  • 2020-12-02 03:52

    My understanding of marshalling is different to the other answers.

    Serialization:

    To Produce or rehydrate a wire-format version of an object graph utilizing a convention.

    Marshalling:

    To Produce or rehydrate a wire-format version of an object graph by utilizing a mapping file, so that the results can be customized. The tool may start by adhering to a convention, but the important difference is the ability to customize results.

    Contract First Development:

    Marshalling is important within the context of contract first development.

    • Its possible to make changes to an internal object graph, while keeping the external interface stable over time. This way all of the service subscribers won't have to be modified for every trivial change.
    • Its possible to map the results across different languages. For example from the property name convention of one language ('property_name') to another ('propertyName').
    0 讨论(0)
提交回复
热议问题