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 20 void android_main(android_app *app) { 21 app_dummy(); 22 23 flatbuffers::FlatBufferBuilder builder; 24 auto name = builder.CreateString("Dog"); 25 auto sound = builder.CreateString("Bark"); 26 auto animal_buffer = sample::CreateAnimal(builder, name, sound); 27 builder.Finish(animal_buffer); 28 29 // We now have a FlatBuffer that can be stored on disk or sent over a network. 30 31 // ...Code to store on disk or send over a network goes here... 32 33 // Instead, we're going to access it immediately, as if we just recieved this. 34 35 auto animal = sample::GetAnimal(builder.GetBufferPointer()); 36 37 assert(animal->name()->str() == "Dog"); 38 assert(animal->sound()->str() == "Bark"); 39 (void)animal; // To silence "Unused Variable" warnings. 40 41 __android_log_print(ANDROID_LOG_INFO, "FlatBufferSample", 42 "FlatBuffer successfully created and verified."); 43 } 44