The document introduces Protocol Buffers and how to use them on Android. It discusses the benefits of Protocol Buffers such as speed, size, and compatibility. It also provides a demo comparing the performance of Protocol Buffers to GSON, showing that Protocol Buffers are faster and produce smaller data sizes. The document concludes by mentioning some drawbacks of Protocol Buffers and providing references for further information.
5. Protocol buffers are Google's
language-neutral, platform-neutral,
extensible mechanism for serializing
structured data
From: https://developers.google.com/protocol-buffers/
9. Benefits
● Speed
○ Fast
● Size
○ Small
○ Serialize to binary-format stream
● Backward Compatible
● Multiple programming language support
○ C++ / Java / Python / C# / Go...etc
● Easy to define the data schema
11. Usages
● Install protoc (protocol buffer compiler) and related libs
○ steps
● Write a .proto file
● Use protoc to generate the Java/C++/Python... source code
○ protoc --cpp_out=./cpp --java_out=./java sample.proto
● Add related libs to your project
● Put the generated source code to your project
● writeTo() and parseFrom()
● Happy coding with Protocol Buffers!
13. Protocol Buffers meet Android
● AOSP/external/protobuf/
○ protoc => aprotoc
○ AOSP is not following the latest version
● Dex 65535 method count issue
● Apk size issue
14. Protocol Buffers for Java
Lite version Micro version Nano version
Lib size 128 KB 21 KB 43 KB
Generated Java
class size*
7~8x 1.2~1.3x 1x
Object creation Builder Constructor Constructor
Object
operations
Builder /
Setter / Getter
Setter / Getter public member
Repeated
objects
List List Array