-
-
Save mkaarthick/724f29140517bb7d380d to your computer and use it in GitHub Desktop.
FlatBuffs source files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply plugin: 'com.jakewharton.hugo' | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "23.0.0 rc2" | |
defaultConfig { | |
applicationId "frogermcs.io.flatbuffs" | |
minSdkVersion 15 | |
targetSdkVersion 22 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
compile 'com.android.support:appcompat-v7:22.2.1' | |
compile 'com.google.code.gson:gson:2.3.1' | |
compile 'com.jakewharton:butterknife:7.0.1' | |
compile 'io.reactivex:rxjava:1.0.10' | |
compile 'io.reactivex:rxandroid:1.0.0' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Bind(R.id.tvFlat) | |
TextView tvFlat; | |
@Bind(R.id.tvJson) | |
TextView tvJson; | |
private RawDataReader rawDataReader; | |
private ReposListJson reposListJson; | |
private ReposList reposListFlat; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
ButterKnife.bind(this); | |
rawDataReader = new RawDataReader(this); | |
} | |
@OnClick(R.id.btnJson) | |
public void onJsonClick() { | |
rawDataReader.loadJsonString(R.raw.repos_json).subscribe(new SimpleObserver<String>() { | |
@Override | |
public void onNext(String reposStr) { | |
parseReposListJson(reposStr); | |
} | |
}); | |
} | |
private void parseReposListJson(String reposStr) { | |
long startTime = System.currentTimeMillis(); | |
reposListJson = new Gson().fromJson(reposStr, ReposListJson.class); | |
for (int i = 0; i < reposListJson.repos.size(); i++) { | |
RepoJson repo = reposListJson.repos.get(i); | |
Log.d("FlatBuffers", "Repo #" + i + ", id: " + repo.id); | |
} | |
long endTime = System.currentTimeMillis() - startTime; | |
tvJson.setText("Elements: " + reposListJson.repos.size() + ": load time: " + endTime + "ms"); | |
} | |
@OnClick(R.id.btnFlatBuffers) | |
public void onFlatBuffersClick() { | |
rawDataReader.loadBytes(R.raw.repos_flat).subscribe(new SimpleObserver<byte[]>() { | |
@Override | |
public void onNext(byte[] bytes) { | |
loadFlatBuffer(bytes); | |
} | |
}); | |
} | |
private void loadFlatBuffer(byte[] bytes) { | |
long startTime = System.currentTimeMillis(); | |
ByteBuffer bb = ByteBuffer.wrap(bytes); | |
reposListFlat = frogermcs.io.flatbuffs.model.flat.ReposList.getRootAsReposList(bb); | |
for (int i = 0; i < reposListFlat.reposLength(); i++) { | |
Repo repos = reposListFlat.repos(i); | |
Log.d("FlatBuffers", "Repo #" + i + ", id: " + repos.id()); | |
} | |
long endTime = System.currentTimeMillis() - startTime; | |
tvFlat.setText("Elements: " + reposListFlat.reposLength() + ": load time: " + endTime + "ms"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"repos": [ | |
{ | |
"id": 27149168, | |
"name": "acai", | |
"full_name": "google/acai", | |
"owner": { | |
"login": "google", | |
"id": 1342004, | |
... | |
"type": "Organization", | |
"site_admin": false | |
}, | |
"private": false, | |
"html_url": "https://github.com/google/acai", | |
"description": "Testing library for JUnit4 and Guice.", | |
... | |
"watchers": 21, | |
"default_branch": "master" | |
}, | |
... | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table ReposList { | |
repos : [Repo]; | |
} | |
table Repo { | |
id : long; | |
name : string; | |
full_name : string; | |
owner : User; | |
//... | |
labels_url : string (deprecated); | |
releases_url : string (deprecated); | |
} | |
table User { | |
login : string; | |
id : long; | |
avatar_url : string; | |
gravatar_id : string; | |
//... | |
site_admin : bool; | |
} | |
root_type ReposList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment