• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <android/log.h>
16 
17 #include "android_native_app_glue.h"
18 #include "animal_generated.h" // Includes "flatbuffers/flatbuffers.h".
19 
android_main(android_app *)20 void android_main(android_app *) {
21   flatbuffers::FlatBufferBuilder builder;
22   auto name = builder.CreateString("Dog");
23   auto sound = builder.CreateString("Bark");
24   auto animal_buffer = sample::CreateAnimal(builder, name, sound);
25   builder.Finish(animal_buffer);
26 
27   // We now have a FlatBuffer that can be stored on disk or sent over a network.
28 
29   // ...Code to store on disk or send over a network goes here...
30 
31   // Instead, we're going to access it immediately, as if we just recieved this.
32 
33   auto animal = sample::GetAnimal(builder.GetBufferPointer());
34 
35   assert(animal->name()->str() == "Dog");
36   assert(animal->sound()->str() == "Bark");
37   (void)animal; // To silence "Unused Variable" warnings.
38 
39   __android_log_print(ANDROID_LOG_INFO, "FlatBufferSample",
40       "FlatBuffer successfully created and verified.");
41 }
42