Serialization byte array vs XML file

前端 未结 7 1866
礼貌的吻别
礼貌的吻别 2021-01-06 08:42

I am heavily using byte array to transfer objects, primitive data, over the network and back. I adapt java\'s approach, by having a type implement ISerializable, which cont

7条回答
  •  心在旅途
    2021-01-06 09:04

    Regarding writing to file, generally you want to serialize an object to XML if you want to be able to read the serialization or perhaps alter it. If you have no desire for the serialization to be human readable, you might as well reuse your binary serialization.

    If you do want it to be human readable, then XML is something to consider, but it depends on the type of data you need to serialize. XML is inherently recursive and is therefore good for serializing likewise recursive data. It's less of a good fit on other types of data.

    In other words, pick a persistent serialization that suits your needs. There's no one-way-fits-all solution here.

    As for network, generally you'll want to keep size to a minimum, so XML is usually never a good choice due to its verbosity.

提交回复
热议问题