Google Protocol Buffers (Protobuf) - Coffee Serialization Alternative

If you lot induce got done approximately serialization industrial plant inwards Java, thence you lot know that it's non that easy. Since default serialization machinery is non efficient in addition to has host of problems, meet custom serialization formats for all information types, which means, you lot don't postulate to reinvent the wheel. It's besides really productive, as a developer you lot only postulate to define message formats inwards a .proto file, in addition to the Google Protocol Buffers takes tending of residuum of the work. Google besides provides a protocol buffer compiler to generate origin code from .proto file inwards Java programming linguistic communication in addition to an API to read in addition to write messages on protobuf object. You don't postulate to bother almost whatever encoding, decoding detail, all you lot induce got to specify is your data-structure, inwards a Java similar format. There are to a greater extent than reasons to purpose Google protocol buffer, which nosotros volition meet inwards adjacent section.




Google Protocol Buffer vs Java Serialization vs XML vs JSON

You can't ignore protobuf if you lot tending for performance. I concord that at that topographic point are lot of way to serialize information including JSON, XML in addition to your ain ad-hoc format, but they all induce got approximately sort of serious limitation, when it comes to shop non fiddling objects. XML in addition to JSON are every bit characteristic rich, linguistic communication independent in addition to has lots of opened upwards origin Java libraries to accept tending of encoding in addition to decoding. As you tin purpose Jackson to parse JSON object inwards Java, or you lot tin purpose XML parsers similar SAX or DOM to serialize information inwards XML format. It's skillful if you lot are sharing information alongside other applications as XML is i of the most used information transfer protocol, in addition to JSON is closed second, but they has their ain problems e.g. XML is verbose, it takes lot of infinite to correspond a modest sum of information in addition to XML parsing tin impose a huge surgery penalization on applications. Also, traversing an XML DOM is non as tardily as setting fields inwards a Java class, as you lot postulate to create inwards Google protocol buffer. JSON is less verbose in addition to takes less infinite compared to XML, but withal you lot postulate to incur surgery penalization on encoding/decoding. Also, approximately other create goodness of Google protocol buffer over JSON is that protobuf has strict messaging format defined using .proto files. Let's meet an event protobuf object to correspond an Order inwards .proto file.

message Order {   required int64 order_id = 1;   required string symbol  = 2;   required double quantity = 3;   required double cost = 4;   optional string text = 5; }

By using a grammer defined, strict schema, nosotros tin realize several benefits over something similar JSON, e.g. past times only looking at .proto file, nosotros know plain names, which fields are required in addition to which are optional, in addition to to a greater extent than importantly information type of unlike fields. Google Protocol buffer, besides allows you lot to compile .proto file into multiple target languages e.g. Java, C++, or Python.
 If you lot induce got done approximately serialization industrial plant inwards Java Google Protocol Buffers (ProtoBuf) - Java Serialization Alternative

One of the most raw but skillful approach for surgery sensitive application is to invent their ain ad-hoc way to encode information structures. This is rather unproblematic in addition to flexible but non skillful from maintenance betoken of view, as you lot postulate to write your ain encoding in addition to decoding code, which is sort of reinventing wheel. In guild to become far as characteristic rich as Google protobuf, you lot postulate to pass considerable sum of time. So this approach solely industrial plant best for simplest of information structure, in addition to non productive for complex objects. If surgery is non your trace of piece of occupation organisation than you lot tin withal purpose default serialization protocol built inwards Java itself, but as mentioned inwards Effective Java, it got of problems. Also it’s non skillful if you lot are sharing information betwixt 2 applications which are non written inwards Java e.g. native application written inwards C++.

Google protocol buffer provides a midway solution, they are non as infinite intensive as XML in addition to much improve than Java serialization, inwards fact they are much to a greater extent than flexible in addition to efficient. With Google protocol buffer, all you lot postulate to create is write a .proto description of the object you lot want to store. From that, protocol buffer compiler creates a Java shape that implements automatic encoding in addition to parsing of the buffer information alongside an efficient binary format. This generated class, known as protobuf object, provides getters in addition to setters for the fields that brand upwards a protocol buffer in addition to takes tending of the details of reading in addition to writing the protocol buffer as a unit. Another large summation is that google protocol buffer format supports the thought of extending the format over fourth dimension inwards such a way that the code tin withal rad information encoded alongside the former format, though you lot postulate to follow sure rules to hold backward in addition to frontward compatibility.
 If you lot induce got done approximately serialization industrial plant inwards Java Google Protocol Buffers (ProtoBuf) - Java Serialization Alternative


You tin meet protobuf has approximately serious things to offer, in addition to it's sure as shooting flora its house inwards fiscal information processing in addition to FinTech. Though XML in addition to JSON has their broad purpose in addition to I withal recommend to them depending upon your scenario, as JSON is to a greater extent than suitable for spider web development, where i goal is Java in addition to other is browser which runs JavaScript. Protocol buffer besides has express linguistic communication back upwards than XML or JSON, officially skillful provides compilers for C++, Java in addition to Python but at that topographic point are 3rd political party add-ons for Ruby in addition to other programming language, on the other manus JSON has almost ubiquitous linguistic communication support.

In short, XML is skillful to interact alongside legacy organisation in addition to using spider web service, but for high surgery application, which are using their ain adhoc way for persisting data, google protocol buffer is a skillful choice. Google protocol buffer besides has miscellaneous utilities which tin endure useful for you lot as protobuf developer, at that topographic point is plugin for Eclipse, NetBeans IDE in addition to IntelliJ IDEA to run alongside protocol buffer, which provides syntax highlighting, content assist in addition to automatic generation of numeric types, as you lot type. There is besides a Wireshark/Ethereal package sniffer plugin to monitor protobuf traffic.

That's all on this introduction of Google Protocol Buffer, inwards adjacent article nosotros volition meet How to purpose google protocol buffer to encode Java objects.

If you lot similar this article in addition to interested to know to a greater extent than almost Serialization inwards Java, I recommend you lot to banking concern check approximately of my before shipping on same topic :
  • Top 10 Java Serialization Interview Questions in addition to Answers (list)
  • Difference betwixt Serializable in addition to Externalizable inwards Java? (answer)
  • Why purpose SerialVersionUID inwards Java? (answer)
  • How to run alongside transient variable inwards Java? (answer)
  • How to serialize object inwards Java? (answer)

Belum ada Komentar untuk "Google Protocol Buffers (Protobuf) - Coffee Serialization Alternative"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel