marshalling
/ MAR-shul-ing /
Suppose you want to mail a friend a complicated Lego model. You cannot post the assembled model through a letterbox; you have to take it apart into a flat row of bricks, pack them in a box with instructions, and mail that. Your friend opens the box and rebuilds the model. Marshalling is the computing version of that flattening: it is the process of turning a piece of in-memory data — a number, a string, a list, a whole object — into a flat sequence of bytes that can travel over a network or be written to a file. Rebuilding it on the other side is called unmarshalling (or deserialization).
Why is flattening necessary? Inside a running program, data lives in memory with a rich shape: an object might contain pointers (memory addresses) to other objects scattered around. Those addresses are meaningless on another machine — address 0x7ffe1234 on your computer points to nothing on mine. So marshalling walks the data and writes out its actual contents in an agreed, self-contained format: the value 42 becomes specific bytes, a string becomes its length followed by its characters, a list becomes its count followed by each element marshalled in turn. The receiver reads that byte stream and reconstructs equivalent data in its own memory. Both sides must agree on the format, and they must also agree on details like byte order (which end of a multi-byte number comes first).
Why it matters: marshalling is the quiet workhorse under every remote procedure call, every web API, and every saved game. Whenever data crosses a boundary — between machines, between a program and a disk, between two languages — it almost certainly gets marshalled into bytes and unmarshalled back. The honest catch is that it has real costs and pitfalls: it takes CPU time, the two sides can disagree on the format (a classic source of bugs), and not everything flattens cleanly — an open file handle or a live network connection cannot simply be packed into a box and rebuilt elsewhere.
To send the list [1, "hi", true] over the network, marshalling might produce the bytes for: "a list of 3 items; item 1 is the integer 1; item 2 is the 2-character string h, i; item 3 is the boolean true". The receiver reads exactly that and rebuilds an equivalent list in its own memory. Formats like JSON, Protocol Buffers, and XML are different agreed languages for doing this.
Flatten structured data into bytes to send; rebuild it on the other side. Both ends must agree on the format.
Marshalling and serialization are usually used as synonyms. Watch out: some things cannot be meaningfully marshalled (a live socket, an OS handle), and version mismatches between sender and receiver formats are a frequent, sneaky bug.