Thursday, February 12, 2009

Google Protocol Buffer

Google Protocol Buffer can be used to serialise and deserialise structured data, either to/from a file, or to/from network. Protocol Buffer acts as a (network) protocol parser generator. It can generate a parser that understands a specific protocol format. Of course this can be implemented using a general purpose parser generator such as ANTLR.

Several existing solutions are available to address the same problem.
  • The problematic Java Serialization.
  • The DIY approach. It is surely painful in particular for complex data structure.
  • Serialise data to XML. In Java, this is supported by JAXB. The advantages of using XML as transmission format are that, XML is language independent, is platform independent, and is human readable. The disadvantage is the associated performance cost.
According to the Protocol Buffer's tutorial for Java, it has several selling points:
  • It has bindings for Java, C++, and Python. Thus the data can be transmitted between Java, C++, and Python applications.
  • Its performance is expected to be good, because not only it is not based on XML, but also it can boost the performance by not using Java reflection.
  • As long as following certain rules, when the protocol is updated, the new code is compatible with the old code.

No comments: