Google Protocol Buffers (Protobuf) - Coffee Serialization Alternative

If you lot create got done approximately serialization works inwards Java, in addition to thence you lot know that it's non that easy. Since default serialization machinery is non efficient in addition to has host of problems, come across custom serialization formats for all information types, which means, you lot don't involve to reinvent the wheel. It's likewise rattling productive, as a developer you lot merely involve to define message formats inwards a .proto file, in addition to the Google Protocol Buffers takes tending of balance of the work. Google likewise provides a protocol buffer compiler to generate beginning 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 involve to bother nearly whatsoever encoding, decoding detail, all you lot create got to specify is your data-structure, inwards a Java similar format. There are to a greater extent than reasons to role Google protocol buffer, which nosotros volition come across inwards side yesteryear side section.




Google Protocol Buffer vs Java Serialization vs XML vs JSON

You can't ignore protobuf if you lot tending for performance. I deal 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 create got approximately sort of serious limitation, when it comes to shop non footling objects. XML in addition to JSON are as characteristic rich, linguistic communication independent in addition to has lots of opened upwards beginning Java libraries to accept tending of encoding in addition to decoding. As you tin role Jackson to parse JSON object inwards Java, or you lot tin role XML parsers similar SAX or DOM to serialize information inwards XML format. It's skillful if you lot are sharing information amongst other applications as XML is i of the most used information transfer protocol, in addition to JSON is unopen second, but they has their ain problems e.g. XML is verbose, it takes lot of infinite to stand upwards for a minor sum of information in addition to XML parsing tin impose a huge functioning punishment on applications. Also, traversing an XML DOM is non as slowly as setting fields inwards a Java class, as you lot involve to create inwards Google protocol buffer. JSON is less verbose in addition to takes less infinite compared to XML, but all the same you lot involve to incur functioning punishment 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 come across an illustration protobuf object to stand upwards for 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. yesteryear merely 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, likewise allows you lot to compile .proto file into multiple target languages e.g. Java, C++, or Python.
 If you lot create got done approximately serialization works inwards Java Google Protocol Buffers (ProtoBuf) - Java Serialization Alternative

One of the most raw but skillful approach for functioning sensitive application is to invent their ain ad-hoc way to encode information structures. This is rather uncomplicated in addition to flexible but non skillful from maintenance betoken of view, as you lot involve to write your ain encoding in addition to decoding code, which is sort of reinventing wheel. In gild to teach inwards as characteristic rich as Google protobuf, you lot involve to pass considerable sum of time. So this approach exclusively works best for simplest of information structure, in addition to non productive for complex objects. If functioning is non your describe of piece of job concern than you lot tin all the same role 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 ii 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 amend 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 involve to create is write a .proto description of the object you lot want to store. From that, protocol buffer compiler creates a Java degree that implements automatic encoding in addition to parsing of the buffer information amongst 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 addition is that google protocol buffer format supports the thought of extending the format over fourth dimension inwards such a way that the code tin all the same rad information encoded amongst the onetime format, though you lot involve to follow sure rules to keep backward in addition to forrad compatibility.
 If you lot create got done approximately serialization works inwards Java Google Protocol Buffers (ProtoBuf) - Java Serialization Alternative


You tin come across protobuf has approximately serious things to offer, in addition to it's sure enough works life its house inwards fiscal information processing in addition to FinTech. Though XML in addition to JSON has their broad role in addition to I all the same recommend to them depending upon your scenario, as JSON is to a greater extent than suitable for spider web development, where i halt is Java in addition to other is browser which runs JavaScript. Protocol buffer likewise 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 tertiary 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 amongst legacy organization in addition to using spider web service, but for high functioning application, which are using their ain adhoc way for persisting data, google protocol buffer is a skillful choice. Google protocol buffer likewise 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 operate amongst protocol buffer, which provides syntax highlighting, content assist in addition to automatic generation of numeric types, as you lot type. There is likewise a Wireshark/Ethereal bundle sniffer plugin to monitor protobuf traffic.

That's all on this introduction of Google Protocol Buffer, inwards side yesteryear side article nosotros volition come across How to role google protocol buffer to encode Java objects.

If you lot similar this article in addition to interested to know to a greater extent than nearly Serialization inwards Java, I recommend you lot to banking venture check approximately of my before post service on same theme :
  • Top 10 Java Serialization Interview Questions in addition to Answers (list)
  • Difference betwixt Serializable in addition to Externalizable inwards Java? (answer)
  • Why role SerialVersionUID inwards Java? (answer)
  • How to operate amongst transient variable inwards Java? (answer)
  • How to serialize object inwards Java? (answer)

Sumber https://javarevisited.blogspot.com/

0 Response to "Google Protocol Buffers (Protobuf) - Coffee Serialization Alternative"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel