开发者

What are the advantages of strings for serialization?

开发者 https://www.devze.com 2023-03-23 16:08 出处:网络
What are the advantages of strings for serialization? What\'s wrong withbinary files for serializati开发者_C百科on?

What are the advantages of strings for serialization?

What's wrong with binary files for serializati开发者_C百科on?


  • String data is human-readable, which is wonderful for troubleshooting. Binary data is not.
  • String data is easily parsed by systems on any platform. Binary data is not always, so if you need to pass data between a Windows and a Linux box, or maybe an IBM Mainframe, string data is simpler.
  • String data also is comprehensive enough to include XML, which brings even better features to the table.
  • It's easier to truly encrypt and decrypt, particularly if you're going cross-platform.

However, there are disadvantages to using string data as well.

  • It usually results in larger amounts of raw bits - larger files, more traffic on the network, etc.
  • It's human-readable which is not so wonderful if you need to protect it from being used in other systems or from prying eyes. (Although encryption helps with the prying eyes deal.)


Strings are simply more portable, and more forward and backward compatible. In binary formats, everything relies on offsets, known sizes, and expected fields. They're difficult to write parsers for, because basically you need to support every known "version" of the binary format. With text however (especially something flexible like XML) it's easy to find the fields you're looking for, and it's even easier to debug when something goes wrong (human readable makes everything better).

0

精彩评论

暂无评论...
验证码 换一张
取 消