"Fossies" - the Fresh Open Source Software Archive

Member "flatbuffers-23.1.21/android/app/src/main/cpp/animals.cpp" (21 Jan 2023, 1333 Bytes) of package /linux/misc/flatbuffers-23.1.21.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "animals.cpp" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright 2014 Google Inc. All rights reserved.
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * You may obtain a copy of the License at
    7  *
    8  *     http://www.apache.org/licenses/LICENSE-2.0
    9  *
   10  * Unless required by applicable law or agreed to in writing, software
   11  * distributed under the License is distributed on an "AS IS" BASIS,
   12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13  * See the License for the specific language governing permissions and
   14  * limitations under the License.
   15  */
   16 
   17 #include <jni.h>
   18 #include <string>
   19 #include <search.h>
   20 #include "generated/animal_generated.h"
   21 
   22 using namespace com::fbs::app;
   23 using namespace flatbuffers;
   24 
   25 extern "C" JNIEXPORT jbyteArray JNICALL Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(
   26         JNIEnv* env,
   27         jobject /* this */) {
   28     // create a new animal flatbuffers
   29     auto fb = FlatBufferBuilder(1024);
   30     auto tiger = CreateAnimalDirect(fb, "Tiger", "Roar", 300);
   31     fb.Finish(tiger);
   32 
   33     // copies it to a Java byte array.
   34     auto buf = reinterpret_cast<jbyte*>(fb.GetBufferPointer());
   35     int size = fb.GetSize();
   36     auto ret = env->NewByteArray(size);
   37     env->SetByteArrayRegion (ret, 0, fb.GetSize(), buf);
   38   return ret;
   39 }