SlideShare a Scribd company logo
@mohsenoid
Using in an Android app
+ extra Kotlin flavor
@mohsenoid
2014 FIFA World Cup Brazil
A Short Story
@mohsenoid
@mohsenoid
In a single Text Message: 160 Char
W14(3)|Type*(1)|#ofGoals(128)|UserPoint(4)|Qualified(16)|Error**(1)|Checksum(1)
*Type: RESULT("R") / PREDICT("P") / STATES("S")
** Error: User last predict message error call back
@mohsenoid
The Automotive
Assistant
Germanautolabs.com
HelloChris.ai
@mohsenoid
* MTU: Maximum Transmission Unit
* Package/Sec: 7.5~1.25 milliseconds
https://punchthrough.com/blog/posts/maximizing-ble-throughput-on-ios-and-android
BLE Data Throughput
Best case MTU Worst case MTU
512 Bytes 20 Bytes!!!
@mohsenoid
Google developed Protocol Buffers for internal usage and
also provided a code generator for multiple languages.
https://github.com/google/protobuf
C++ / Java / Python / Objective-C / C# / JavaNano / JavaScript / Ruby / Go / PHP / Dart
@mohsenoid
● Protocol Buffers is a method of serializing structured data
● Useful in developing programs to communicate with each
other and also good for storing data
● interface description language: describes the structure of
some data
● a program that generates source code from description
for generating or parsing a stream of bytes that
represents the structured data
What is Protocol Buffers?
@mohsenoid
Setting up the Application project
@mohsenoid
top-level build.gradle
buildscript {
ext.protobufVersion = '0.8.3'
...
dependencies {
...
classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion"
}
...
@mohsenoid
creating a Java module
@mohsenoid
Java module build.gradle
apply plugin: 'com.google.protobuf'
…
// lite version is recommended for Android apps
implementation 'com.google.protobuf:protobuf-lite:3.0.0'
...
@mohsenoid
Protobuf plugin settings
protobuf {
protoc { // setting proto compiler
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins { // ask proto plugin to use java lite code generator
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
@mohsenoid
Protobuf plugin settings
generateProtoTasks {
all().each { task ->
task.builtins {
remove java // because of using javalite we should remove java outputs
}
task.plugins {
javalite {} // and use javalite
}
}
@mohsenoid
Protobuf plugin output
sourceSets {
main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite"
}
@mohsenoid
Default proto dir
src/main/proto
@mohsenoid
a sample proto file
syntax = "proto2";
package tutorial;
option java_package = "com.mohsenoid.tutorial";
option java_outer_classname = "AddressBookProtos";
@mohsenoid
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phones = 4;
@mohsenoid
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
}
message AddressBook {
repeated Person people = 1;
}
@mohsenoid
@mohsenoid
Kotlin reported issue
@mohsenoid
Kotlin reported issue #100:
https://github.com/google/protobuf-gradle-plugin/issues/100
compileKotlin {
dependsOn('generateProto')
}
compileTestKotlin {
dependsOn('generateProto')
}
@mohsenoid
Let’s finish it!
@mohsenoid
Protocol buffer is a useful way of
serializing and deserializing data
(also obfuscating!!!)
perfectly optimized in case of data transmission size and also avoiding all manual data typing
@mohsenoid
@mohsenoid
Google Project: https://developers.google.com/protocol-buffers
Definition: https://developers.google.com/protocol-buffers/docs/proto3
Sample Repo: https://github.com/mohsenoid/protobuf_android_sample
Article: https://proandroiddev.com/96132340de5c

More Related Content

PPTX
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
PDF
Developing better debug_components
ODP
Browser Exploitation Framework Tutorial
PDF
Testing PHP with Codeception
PPTX
Setting Apple's UI Automation Free with Appium
PPTX
Setting UIAutomation free with Appium
PDF
Flask Introduction - Python Meetup
PPTX
CI / CD w/ Codeception
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
Developing better debug_components
Browser Exploitation Framework Tutorial
Testing PHP with Codeception
Setting Apple's UI Automation Free with Appium
Setting UIAutomation free with Appium
Flask Introduction - Python Meetup
CI / CD w/ Codeception

Similar to Using protobuf in your android app (6)

PDF
Experience protocol buffer on android
ODP
Protocol Buffers
PPTX
Protocol buffers
PPTX
Protocol Buffers
PPTX
Golang proto buff_ixxo
PPTX
Protocol Buffer.ppt
Experience protocol buffer on android
Protocol Buffers
Protocol buffers
Protocol Buffers
Golang proto buff_ixxo
Protocol Buffer.ppt
Ad

More from Mohsen Mirhoseini (8)

PDF
Functional Programming in Kotlin for Android Developers
PDF
Top 10 Exception Handling best practices in Kotlin
PDF
Rise from the Ashes: A Developer’s Phoenix Story
PDF
How to set up Android Picture-in-picture mode? (a.k.a Floating window) + Best...
PPT
Introduction to Unity3D Game Engine
PPTX
Tehran's 2nd Android bootcamp
PPTX
Tehran's 1st Android bootcamp - Part2
PPTX
Tehran's 1st Android bootcamp - Part1
Functional Programming in Kotlin for Android Developers
Top 10 Exception Handling best practices in Kotlin
Rise from the Ashes: A Developer’s Phoenix Story
How to set up Android Picture-in-picture mode? (a.k.a Floating window) + Best...
Introduction to Unity3D Game Engine
Tehran's 2nd Android bootcamp
Tehran's 1st Android bootcamp - Part2
Tehran's 1st Android bootcamp - Part1
Ad

Recently uploaded (20)

PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Nekopoi APK 2025 free lastest update
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Cost to Outsource Software Development in 2025
PPTX
history of c programming in notes for students .pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
wealthsignaloriginal-com-DS-text-... (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Nekopoi APK 2025 free lastest update
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Reimagine Home Health with the Power of Agentic AI​
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Salesforce Agentforce AI Implementation.pdf
Autodesk AutoCAD Crack Free Download 2025
Odoo Companies in India – Driving Business Transformation.pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Why Generative AI is the Future of Content, Code & Creativity?
Cost to Outsource Software Development in 2025
history of c programming in notes for students .pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru

Using protobuf in your android app