Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol Buffer better than serialization?

I have a large data-structure which i'm serializing.At certain times i need to edit the values in the data-structure.But just for changing a small value i'll have to re-serialize it again instead of updating the changed value in file.I've heard of Google protocol buffer's.Will using it solve my problem of rewriting the file ? Is it a better option for me to use protocol buffer instead of Java serialization ?

like image 312
Emil Avatar asked Dec 13 '22 19:12

Emil


2 Answers

Protocol buffers are themselves a serialization format, so they won't fundamentally change the picture (you'll still need to re-serialize after you change a value).

Google's docs claim that protocol buffers are more compact and faster to parse than XML (which seems plausible); don't know how they compare to native Java serialization.

Advantages of protocol buffers might be portability (if programs written in other languages need to read the file) and upgradability (you can add new fields to the data structure without breaking the file format).

like image 146
David Gelhar Avatar answered Dec 26 '22 16:12

David Gelhar


A couple of points

  1. There is an editor for Protocol Buffers binary format (http://code.google.com/p/protobufeditor/)
  2. Protocol buffers has a text format that looks like:
# Textual representation of a protocol buffer.
# This is *not* the binary format used on the wire.
person {
  name: "John Doe"
  email: "[email protected]"
}

See:

  • Discussion: http://groups.google.com/group/protobuf/browse_thread/thread/04fc478088137bf3
  • Class: http://code.google.com/apis/protocolbuffers/docs/reference/java/com/google/protobuf/TextForm

Having said that, I would use a technology (JSon, Xml etc) that is already in use unless one of the following applies

  1. You need the performance of protocol buffers
  2. You already / plan to use protocol buffers
like image 35
Bruce Martin Avatar answered Dec 26 '22 17:12

Bruce Martin