![](/uploads/1/2/6/4/126490163/670561661.jpg)
It supports many popular languages such as C, C#, Dart, Go, Java and Python. Although there. The answer is performance. Protobuf has many advantages for serialization that go beyond the capacity of XML. It allows you.
What is Protobuf?Developed by Google for object serialization, its an open source library, and available for multiple languages. It’s a fast buffer which does the object serialization, you can consider it the same as XML but faster, smaller, and finally both serialization and de-serialization are faster than any other available approach.What is the procedure?One needs to define the object structure, it can be done by defining the.proto file, which defines required and optional fields of the object.Once the proto file is generated, one needs to use supplied code generator, this utility is language specific and generates language specific code. If it’s used for Java then you can consider that this utility generates the Java pojo for serialization and de-serialization.Now using the supplied library, generated beans/models and.proto files, one can serialize or de- serialize the response.Why should I use it?. JSON and XML transmit data with metadata details, and which adds load on payload, requires more memory compared to Protobuf. Protobuf compresses the data and generates dense data.
If compared to XML Fast buffers it takes almost a 1/3rd of the size and if compared to JSON then its ½. JSON and XML are more readable and not secure to transmit data over the network.
If you want your response not to be readable by user then you can use Protobuf. The consumer of the service needs the.proto file to de-serialize the object stream. Less CPU and Memory will be consumed for serialization and de- serialization, so processing time on mobile devices is faster compared to JSON.ComparisonHere I considered a web application which sends data using REST service, and a web page which renders the data on screen. I have used the total time to render a page using JSON and Proto, end-to-end to make sure I am covering, serialization, data transmission, de- serialization and DOM rendering.
Stay up to date on releases
Create your free account today to subscribe to this repository for notifications about new releases, and build software alongside 40 million developers on GitHub.
Sign up for free See pricing for teams and enterprises - Choose a tag to compare
- Choose a tag to compare
liujisi released this Aug 15, 2017
Planned Future Changes
- Preserve unknown fields in proto3: We are going to bring unknown fields back into proto3. In this release, some languages start to support preserving unknown fields in proto3, controlled by flags/options. Some languages also introduce explicit APIs to drop unknown fields for migration. Please read the change log sections by languages for details. See general timeline and plan and issues and discussions
- Make C++ implementation C++11 only: we plan to require C++11 to build protobuf code starting from 3.5.0 or 3.6.0 release, after unknown fields semantic changes are finished. Please join this github issue to provide your feedback.
General
- Extension ranges now accept options and are customizable.
reserve
keyword now supportsmax
in field number ranges, e.g.reserve 1000 to max;
C++
- Proto3 messages are now able to preserve unknown fields. The default behavior is still to drop unknowns, which will be flipped in a future release. If you rely on unknowns fields being dropped. Please use
Message::DiscardUnknownFields()
explicitly. - Packable proto3 fields are now packed by default in serialization.
- Following C++11 features are introduced when C++11 is available:
- move-constructor and move-assignment are introduced to messages
- Repeated fields constructor now takes
std::initializer_list
- rvalue setters are introduced for string fields
- Experimental Table-Driven parsing and serialization available to test. To enable it, pass in table_driven_parsing table_driven_serialization protoc generator flags for C++
$ protoc --cpp_out=table_driven_parsing,table_driven_serialization:./ test.proto
- lite generator parameter supported by the generator. Once set, all generated files, use lite runtime regardless of the optimizer_for setting in the .proto file.
- Various optimizations to make C++ code more performant on PowerPC platform
- Fixed maps data corruption when the maps are modified by both reflection API and generated API.
- Deterministic serialization on maps reflection now uses stable sort.
- file() accessors are introduced to various *Descriptor classes to make writing template function easier.
ByteSize()
andSpaceUsed()
are deprecated.UseByteSizeLong()
andSpaceUsedLong()
instead- Consistent hash function is used for maps in DEBUG and NDEBUG build.
- 'using namespace std' is removed from stubs/common.h
- Various performance optimizations and bug fixes
Java
- Introduced new parser API DiscardUnknownFieldsParser in preparation of proto3 unknown fields preservation change. Users who want to drop unknown fields should migrate to use this new parser API.
For example: - Introduced new TextFormat API printUnicodeFieldValue() that prints field value without escaping unicode characters.
- Added
Durations.compare(Duration, Duration)
andTimestamps.compare(Timestamp, Timestamp)
. - JsonFormat now accepts base64url encoded bytes fields.
- Optimized CodedInputStream to do less copies when parsing large bytes fields.
- Optimized TextFormat to allocate less memory when printing.
Python
![Serialization Serialization](/uploads/1/2/6/4/126490163/340642524.png)
- SerializeToString API is changed to
SerializeToString(self, **kwargs)
, deterministic parameter is accepted for deterministic serialization. - Added sort_keys parameter in json format to make the output deterministic.
- Added indent parameter in json format.
- Added extension support in json format.
- Added
__repr__
support for repeated field in cpp implementation. - Added file in FieldDescriptor.
- Added pretty-print filter to text format.
- Services and method descriptors are always printed even if generic_service option is turned off.
- Note: AppEngine 2.5 is deprecated on June 2017 that AppEngine 2.5 will never update protobuf runtime. Users who depend on AppEngine 2.5 should use old protoc.
PHP
- Support PHP generic services. Specify file option
php_generic_service=true
to enable generating service interface. - Message, repeated and map fields setters take value instead of reference.
- Added map iterator in c extension.
- Support json encode/decode.
- Added more type info in getter/setter phpdoc
- Fixed the problem that c extension and php implementation cannot be used together.
- Added file option php_namespace to use custom php namespace instead of package.
- Added fluent setter.
- Added descriptor API in runtime for custom encode/decode.
- Various bug fixes.
Objective-C
- Fix for GPBExtensionRegistry copying and add tests.
- Optimize GPBDictionary.m codegen to reduce size of overall library by 46K per architecture.
- Fix some cases of reading of 64bit map values.
- Properly error on a tag with field number zero.
- Preserve unknown fields in proto3 syntax files.
- Document the exceptions on some of the writing apis.
C#
- Implemented
IReadOnlyDictionary<K,V>
inMapField<K,V>
- Added TryUnpack method for Any message in addition to Unpack.
- Converted C# projects to MSBuild (csproj) format.
Ruby
- Several bug fixes.
Javascript
- Added support of field option js_type. Now one can specify the JS type of a 64-bit integer field to be string in the generated code by adding option
[jstype = JS_STRING]
on the field.
Assets23
protobuf-cpp-3.4.0.zip5.02 MB
protobuf-csharp-3.4.0.zip5.47 MB
protobuf-java-3.4.0.zip5.68 MB
protobuf-js-3.4.0.zip5.27 MB
protobuf-objectivec-3.4.0.zip5.61 MB
protobuf-php-3.4.0.zip5.38 MB
protobuf-python-3.4.0.zip5.39 MB
protobuf-ruby-3.4.0.zip5.33 MB
protoc-3.4.0-linux-x86_64.zip1.33 MB
protoc-3.4.0-osx-x86_64.zip1.74 MB
![](/uploads/1/2/6/4/126490163/670561661.jpg)