Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gson vs protocol buffer

What are the pros and cons of protocol buffer (protobuf) over GSON?

In what situation protobuf is more appropriate than GSON?

I am sorry for a very generic question.

like image 901
user614431 Avatar asked Feb 12 '11 18:02

user614431


1 Answers

Both json (via the gson library) and protobuf are portable between platorms; but

  • protobuf is smaller (bandwidth) and cheaper (CPU) to read/write
  • json is human readable / editable (protobuf is binary; hard to parse without library support)
  • protobuf is trivial to merge fragments - just concatenate
  • json is easily passed to web page clients
  • the main java version of protobuf needs contract-definition (.proto) and code-generation; gson seems to allow arbitrary pojo usage (there are protobuf implementations that work on such objects, but not for java afaik)

If performance is key : protubuf

For use with a web page (JavaScript), or human readable: json (perhaps via gson)

like image 153
Marc Gravell Avatar answered Sep 22 '22 08:09

Marc Gravell