├── python ├── __init__.py ├── .gitignore ├── setup.cfg └── flatbuffers │ ├── __init__.py │ └── packer.py ├── tests ├── MyGame │ ├── __init__.py │ ├── Example │ │ ├── __init__.py │ │ ├── TestEnum.py │ │ ├── Race.py │ │ ├── Race.lua │ │ ├── AnyUniqueAliases.lua │ │ ├── Any.lua │ │ ├── AnyAmbiguousAliases.lua │ │ ├── Color.py │ │ ├── TestEnum.cs │ │ ├── Race.cs │ │ ├── Color.lua │ │ ├── TestEnum.java │ │ ├── TestEnum.kt │ │ ├── Race.java │ │ ├── AnyUniqueAliases.java │ │ ├── AnyAmbiguousAliases.java │ │ ├── AnyUniqueAliases.kt │ │ ├── Race.kt │ │ ├── AnyAmbiguousAliases.kt │ │ ├── Color.cs │ │ ├── Any.java │ │ ├── Any.kt │ │ ├── Race.php │ │ ├── AnyUniqueAliases.php │ │ ├── Color.java │ │ ├── AnyAmbiguousAliases.php │ │ ├── Race.go │ │ ├── Any.php │ │ ├── Color.php │ │ ├── Color.kt │ │ ├── Color.go │ │ ├── Test.lua │ │ ├── Ability.lua │ │ ├── AnyAmbiguousAliases.py │ │ ├── AnyUniqueAliases.py │ │ ├── Any.py │ │ ├── Test.kt │ │ ├── Ability.kt │ │ ├── Referrable.lua │ │ ├── Ability.php │ │ ├── Test.php │ │ ├── Test.java │ │ ├── TestSimpleTableWithEnum.lua │ │ ├── Ability.java │ │ ├── Test.go │ │ └── Stat.lua │ ├── Example2 │ │ ├── __init__.py │ │ ├── Monster.lua │ │ ├── Monster.kt │ │ ├── Monster.go │ │ └── Monster.java │ ├── InParentNamespace.lua │ ├── InParentNamespace.kt │ ├── InParentNamespace.go │ └── InParentNamespace.java ├── FlatBuffers.Test │ ├── Resources │ │ └── .gitkeep │ ├── packages.config │ ├── FlatBuffersTestMethodAttribute.cs │ ├── FlatBuffersTestClassAttribute.cs │ ├── Lcg.cs │ └── NetTest.sh ├── namespace_test │ ├── NamespaceA │ │ ├── __init__.py │ │ ├── NamespaceB │ │ │ ├── __init__.py │ │ │ ├── EnumInNestedNS.py │ │ │ ├── EnumInNestedNS.lua │ │ │ ├── EnumInNestedNS.cs │ │ │ ├── EnumInNestedNS.java │ │ │ ├── EnumInNestedNS.kt │ │ │ ├── EnumInNestedNS.php │ │ │ ├── EnumInNestedNS.go │ │ │ ├── StructInNestedNS.lua │ │ │ ├── StructInNestedNS.kt │ │ │ ├── TableInNestedNS.lua │ │ │ ├── StructInNestedNS.php │ │ │ └── StructInNestedNS.java │ │ ├── SecondTableInA.lua │ │ ├── TableInC.py │ │ └── TableInC.go │ ├── NamespaceC │ │ └── __init__.py │ ├── namespace_test1.fbs │ ├── namespace_test2.fbs │ └── namespace_test1_generated.lobster ├── docker │ ├── TODO.Dockerfile.testing.python.cpython_with_conda │ ├── TODO.Dockerfile.testing.python.cpython_with_numpy │ ├── languages │ │ ├── Dockerfile.testing.golang.1_11 │ │ ├── Dockerfile.testing.rust.1_37_0 │ │ ├── Dockerfile.testing.java.openjdk_10_0_2 │ │ ├── Dockerfile.testing.java.openjdk_11_0_1 │ │ ├── Dockerfile.testing.swift_5_1 │ │ ├── Dockerfile.testing.csharp.mono_5_18 │ │ ├── Dockerfile.testing.php.zend_7_3 │ │ ├── Dockerfile.testing.python.cpython_2_7_15 │ │ ├── Dockerfile.testing.python.cpython_3_7_1 │ │ ├── Dockerfile.testing.python.numpy.cpython_3_7_1 │ │ ├── Dockerfile.testing.python.numpy.cpython_2_7_15 │ │ ├── Dockerfile.testing.node.10_13_0 │ │ ├── Dockerfile.testing.node.11_2_0 │ │ └── Dockerfile.testing.rust.big_endian.1_37_0 │ ├── TODO.Dockerfile.testing.python.pypy_6_0_0_py2 │ ├── TODO.Dockerfile.testing.python.pypy_6_0_0_py3 │ ├── Dockerfile.testing.build_flatc_debian_stretch │ ├── Dockerfile.testing.cpp.debian_buster │ ├── build_flatc.run.sh │ ├── cpp_test.run.sh │ └── TODO.Dockerfile.testing.php.hhvm_2019_01_16 ├── javatest.bin ├── arrays_test.bfbs ├── monster_test.bfbs ├── monsterdata_test.mon ├── monsterdata_python_wire.mon ├── prototest │ ├── imported.proto │ ├── test_include.golden │ ├── test.golden │ ├── test_union_include.golden │ ├── test_union.golden │ ├── test_suffix.golden │ └── test_union_suffix.golden ├── FlatBuffers.GRPC.Swift │ ├── README.md │ ├── Sources │ │ └── Model │ │ │ └── greeter.fbs │ └── Package.swift ├── FlatBuffers.Test.Swift │ ├── monsterdata_test.mon │ ├── Tests │ │ └── LinuxMain.swift │ ├── SwiftTest.sh │ └── Package.swift ├── LuaTest.bat ├── phpUnionVectorTest.sh ├── include_test │ ├── include_test1.fbs │ └── sub │ │ └── include_test2.fbs ├── native_type_test.fbs ├── fuzzer │ ├── fuzzer_assert.h │ └── flatbuffers_verifier_fuzzer.cc ├── evolution_test │ ├── evolution_v1.json │ ├── evolution_v1.fbs │ ├── evolution_v2.json │ └── evolution_v2.fbs ├── native_type_test_impl.cpp ├── union_vector │ ├── union_vector.json │ ├── Character.java │ ├── Character.kt │ ├── union_vector.fbs │ ├── Character.php │ ├── Rapunzel.kt │ ├── BookReader.kt │ ├── Rapunzel.php │ ├── BookReader.php │ ├── Rapunzel.java │ ├── BookReader.java │ └── Rapunzel.cs ├── arrays_test.fbs ├── monsterdata_extra.json ├── arrays_test.golden ├── unicode_test.json ├── FlatBuffers.Benchmarks.swift │ └── Package.swift ├── monster_extra.fbs ├── rust_usage_test │ ├── Cargo.toml │ └── bin │ │ └── monster_example.rs ├── native_type_test_impl.h ├── JavaScriptTest.sh ├── LuaTest.sh ├── FlatBuffers.Benchmarks │ ├── FlatBuffers.Benchmarks.csproj │ └── Program.cs ├── RustTest.bat ├── JavaTest.bat ├── TestAll.sh ├── JavaTest.sh ├── DartTest.sh ├── RustTest.sh ├── monsterdata_test.golden ├── TypeScriptTest.sh ├── monsterdata_test.json └── KotlinTest.sh ├── docs ├── source │ ├── CONTRIBUTING.md │ ├── groups │ ├── gRPC │ │ └── CppUsage.md │ ├── README_TO_GENERATE_DOCS.md │ └── GoApi.md ├── images │ ├── ftv2mnode.png │ ├── ftv2pnode.png │ └── fpl_logo_small.png └── footer.html ├── samples ├── monster.bfbs ├── android │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── jni │ │ ├── schemas │ │ │ └── animal.fbs │ │ └── Application.mk │ └── res │ │ └── values │ │ └── strings.xml ├── lua │ └── MyGame │ │ └── Sample │ │ ├── Equipment.lua │ │ ├── Color.lua │ │ ├── Vec3.lua │ │ └── Weapon.lua ├── monsterdata.json ├── monster.fbs ├── android_sample.sh └── sample_text.lobster ├── .gitattributes ├── go ├── doc.go ├── struct.go ├── lib.go ├── BUILD.bazel └── grpc.go ├── android ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── jni │ ├── main.cpp │ └── Application.mk ├── .project └── res │ └── values │ └── strings.xml ├── grpc ├── tests │ └── java-grpc-test.sh ├── samples │ └── greeter │ │ ├── greeter.fbs │ │ └── Makefile ├── build_grpc.sh ├── src │ └── compiler │ │ └── python_generator.h ├── README.md └── flatbuffers-java-grpc │ └── pom.xml ├── lua ├── flatbuffers.lua └── flatbuffers │ └── compat.lua ├── conan ├── appveyor │ ├── build.py │ └── install.py ├── travis │ ├── build.sh │ └── install.sh ├── test_package │ ├── CMakeLists.txt │ ├── conanfile.py │ └── test_package.cpp └── CMakeLists.txt ├── CMake ├── FlatbuffersConfig.cmake ├── DESCRIPTION.txt ├── FlatbuffersConfigVersion.cmake.in ├── Version.cmake └── PackageRedhat.cmake ├── .editorconfig ├── src ├── clang-format-all.sh └── clang-format-git.sh ├── dart ├── CHANGELOG.md ├── pubspec.yaml ├── README.md └── publish.sh ├── swift ├── README.md ├── Sources │ └── FlatBuffers │ │ ├── Offset.swift │ │ ├── Struct.swift │ │ ├── FlatBuffersUtils.swift │ │ └── Int+extension.swift ├── Package.swift └── FlatBuffers.podspec ├── .bazelci └── presubmit.yml ├── .clang-format ├── .travis ├── deploy-python.sh ├── check-sources.sh ├── check-sources.sh.py └── check-generate-code.sh ├── composer.json ├── net └── FlatBuffers │ ├── FlatBuffers.Core.csproj │ ├── IFlatbufferObject.cs │ ├── Struct.cs │ ├── ByteBufferUtil.cs │ ├── Offset.cs │ └── FlatBufferConstants.cs ├── rust └── flatbuffers │ └── Cargo.toml ├── .github ├── ISSUE_TEMPLATE.md ├── stale.yml └── PULL_REQUEST_TEMPLATE.md ├── WORKSPACE ├── php ├── Constants.php └── Struct.php ├── reflection ├── generate_code.bat └── generate_code.sh ├── snap └── snapcraft.yaml └── package.json /python/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/MyGame/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/MyGame/Example/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/Resources/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceC/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/source/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ../../CONTRIBUTING.md -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | /dist/ 2 | /*.egg-info/ 3 | -------------------------------------------------------------------------------- /python/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal=1 3 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/docker/TODO.Dockerfile.testing.python.cpython_with_conda: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/docker/TODO.Dockerfile.testing.python.cpython_with_numpy: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /samples/monster.bfbs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/samples/monster.bfbs -------------------------------------------------------------------------------- /tests/javatest.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/tests/javatest.bin -------------------------------------------------------------------------------- /tests/arrays_test.bfbs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/tests/arrays_test.bfbs -------------------------------------------------------------------------------- /docs/images/ftv2mnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/docs/images/ftv2mnode.png -------------------------------------------------------------------------------- /docs/images/ftv2pnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/docs/images/ftv2pnode.png -------------------------------------------------------------------------------- /tests/monster_test.bfbs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/tests/monster_test.bfbs -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | -------------------------------------------------------------------------------- /tests/monsterdata_test.mon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/tests/monsterdata_test.mon -------------------------------------------------------------------------------- /docs/images/fpl_logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/docs/images/fpl_logo_small.png -------------------------------------------------------------------------------- /tests/monsterdata_python_wire.mon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/tests/monsterdata_python_wire.mon -------------------------------------------------------------------------------- /go/doc.go: -------------------------------------------------------------------------------- 1 | // Package flatbuffers provides facilities to read and write flatbuffers 2 | // objects. 3 | package flatbuffers 4 | -------------------------------------------------------------------------------- /tests/prototest/imported.proto: -------------------------------------------------------------------------------- 1 | package proto.test; 2 | 3 | message ImportedMessage { 4 | optional int32 a = 26; 5 | } 6 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /grpc/tests/java-grpc-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # NOTE: make sure `mvn install` in /gprc is executed before running this test 4 | mvn test 5 | -------------------------------------------------------------------------------- /samples/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/samples/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tests/FlatBuffers.GRPC.Swift/README.md: -------------------------------------------------------------------------------- 1 | # FlatBuffers.GRPC.Swift 2 | 3 | The following is Swift example on how GRPC would be with Swift Flatbuffers 4 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test.Swift/monsterdata_test.mon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LUX/flatbuffers/master/tests/FlatBuffers.Test.Swift/monsterdata_test.mon -------------------------------------------------------------------------------- /tests/LuaTest.bat: -------------------------------------------------------------------------------- 1 | set buildtype=Release 2 | if "%1"=="-b" set buildtype=%2 3 | 4 | ..\%buildtype%\flatc.exe --lua -I include_test monster_test.fbs 5 | 6 | lua53.exe luatest.lua -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /go/struct.go: -------------------------------------------------------------------------------- 1 | package flatbuffers 2 | 3 | // Struct wraps a byte slice and provides read access to its data. 4 | // 5 | // Structs do not have a vtable. 6 | type Struct struct { 7 | Table 8 | } 9 | -------------------------------------------------------------------------------- /tests/phpUnionVectorTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | ../flatc --php -o php union_vector/union_vector.fbs 6 | php phpUnionVectorTest.php 7 | 8 | echo 'PHP union vector test passed' 9 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.golang.1_11: -------------------------------------------------------------------------------- 1 | FROM golang:1.11-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN go version 7 | RUN ./GoTest.sh 8 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestEnum.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | class TestEnum(object): 6 | A = 0 7 | B = 1 8 | C = 2 9 | 10 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test.Swift/Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import FlatBuffers_Test_SwiftTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += FlatBuffers_Test_SwiftTests.__allTests() 7 | 8 | XCTMain(tests) 9 | -------------------------------------------------------------------------------- /tests/docker/TODO.Dockerfile.testing.python.pypy_6_0_0_py2: -------------------------------------------------------------------------------- 1 | FROM pypy:2-6.0.0-slim as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN pypy --version 7 | RUN ./PythonTest.sh 8 | -------------------------------------------------------------------------------- /tests/docker/TODO.Dockerfile.testing.python.pypy_6_0_0_py3: -------------------------------------------------------------------------------- 1 | FROM pypy:3-6.0.0-slim as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN pypy --version 7 | RUN ./PythonTest.sh 8 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.rust.1_37_0: -------------------------------------------------------------------------------- 1 | FROM rust:1.37.0-slim-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN rustc --version 7 | RUN ./RustTest.sh 8 | -------------------------------------------------------------------------------- /lua/flatbuffers.lua: -------------------------------------------------------------------------------- 1 | local m = {} 2 | 3 | m.Builder = require("flatbuffers.builder").New 4 | m.N = require("flatbuffers.numTypes") 5 | m.view = require("flatbuffers.view") 6 | m.binaryArray = require("flatbuffers.binaryarray") 7 | 8 | return m -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.java.openjdk_10_0_2: -------------------------------------------------------------------------------- 1 | FROM openjdk:10.0.2-jdk-slim-sid as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN java -version 7 | RUN ./JavaTest.sh 8 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.java.openjdk_11_0_1: -------------------------------------------------------------------------------- 1 | FROM openjdk:11.0.1-jdk-slim-sid as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN java -version 7 | RUN ./JavaTest.sh 8 | -------------------------------------------------------------------------------- /conan/appveyor/build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import os 4 | 5 | if os.getenv("APPVEYOR_REPO_TAG") != "true": 6 | print("Skip build step. It's not TAG") 7 | else: 8 | os.system("python conan/build.py") 9 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | class Race(object): 6 | None_ = -1 7 | Human = 0 8 | Dwarf = 1 9 | Elf = 2 10 | 11 | -------------------------------------------------------------------------------- /conan/appveyor/install.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import os 4 | 5 | if os.getenv("APPVEYOR_REPO_TAG") != "true": 6 | print("Skip step. It's not TAG") 7 | else: 8 | os.system("pip install conan conan-package-tools") 9 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.swift_5_1: -------------------------------------------------------------------------------- 1 | FROM swift:5.1 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN swift --version 7 | WORKDIR /code/tests/FlatBuffers.Test.Swift 8 | RUN sh SwiftTest.sh 9 | -------------------------------------------------------------------------------- /tests/include_test/include_test1.fbs: -------------------------------------------------------------------------------- 1 | include "sub/include_test2.fbs"; 2 | include "sub/include_test2.fbs"; // should be skipped 3 | include "include_test1.fbs"; // should be skipped 4 | 5 | table TableA { 6 | b:MyGame.OtherNameSpace.TableB; 7 | } 8 | -------------------------------------------------------------------------------- /CMake/FlatbuffersConfig.cmake: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/FlatbuffersTargets.cmake" OPTIONAL) 2 | include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL) 3 | include("${CMAKE_CURRENT_LIST_DIR}/FlatbuffersSharedTargets.cmake" OPTIONAL) 4 | 5 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.csharp.mono_5_18: -------------------------------------------------------------------------------- 1 | FROM mono:5.18 as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN mono --version 7 | WORKDIR /code/tests/FlatBuffers.Test 8 | RUN sh NetTest.sh 9 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.php.zend_7_3: -------------------------------------------------------------------------------- 1 | FROM php:7.3-cli-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN php --version 7 | RUN php phpTest.php 8 | RUN sh phpUnionVectorTest.sh 9 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: NamespaceB 4 | 5 | class EnumInNestedNS(object): 6 | A = 0 7 | B = 1 8 | C = 2 9 | 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | # Don't set line endings to avoid conflict with core.autocrlf flag. 3 | # Line endings on checkout/checkin are controlled by .gitattributes file. 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | insert_final_newline = true 8 | -------------------------------------------------------------------------------- /samples/lua/MyGame/Sample/Equipment.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Sample 4 | 5 | local Equipment = { 6 | NONE = 0, 7 | Weapon = 1, 8 | } 9 | 10 | return Equipment -- return the module -------------------------------------------------------------------------------- /samples/lua/MyGame/Sample/Color.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Sample 4 | 5 | local Color = { 6 | Red = 0, 7 | Green = 1, 8 | Blue = 2, 9 | } 10 | 11 | return Color -- return the module -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.python.cpython_2_7_15: -------------------------------------------------------------------------------- 1 | FROM python:2.7.15-slim-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN python --version 7 | RUN pip install coverage 8 | RUN ./PythonTest.sh 9 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.python.cpython_3_7_1: -------------------------------------------------------------------------------- 1 | FROM python:3.7.1-slim-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN python --version 7 | RUN pip install coverage 8 | RUN ./PythonTest.sh 9 | -------------------------------------------------------------------------------- /CMake/DESCRIPTION.txt: -------------------------------------------------------------------------------- 1 | FlatBuffers is a cross platform serialization library architected for 2 | maximum memory efficiency. It allows you to directly access serialized 3 | data without parsing/unpacking it first, while still having great 4 | forwards/backwards compatibility. 5 | -------------------------------------------------------------------------------- /tests/namespace_test/namespace_test1.fbs: -------------------------------------------------------------------------------- 1 | namespace NamespaceA.NamespaceB; 2 | 3 | table TableInNestedNS 4 | { 5 | foo:int; 6 | } 7 | 8 | enum EnumInNestedNS:byte 9 | { 10 | A, B, C 11 | } 12 | 13 | struct StructInNestedNS 14 | { 15 | a:int; 16 | b:int; 17 | } -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local Race = { 6 | None = -1, 7 | Human = 0, 8 | Dwarf = 1, 9 | Elf = 2, 10 | } 11 | 12 | return Race -- return the module -------------------------------------------------------------------------------- /conan/travis/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [[ "$(uname -s)" == 'Darwin' ]]; then 7 | if which pyenv > /dev/null; then 8 | eval "$(pyenv init -)" 9 | fi 10 | pyenv activate conan 11 | fi 12 | 13 | conan user 14 | python conan/build.py 15 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 19 11:54:59 PDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jun 19 11:54:59 PDT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: NamespaceB 4 | 5 | local EnumInNestedNS = { 6 | A = 0, 7 | B = 1, 8 | C = 2, 9 | } 10 | 11 | return EnumInNestedNS -- return the module -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyUniqueAliases.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local AnyUniqueAliases = { 6 | NONE = 0, 7 | M = 1, 8 | TS = 2, 9 | M2 = 3, 10 | } 11 | 12 | return AnyUniqueAliases -- return the module -------------------------------------------------------------------------------- /tests/docker/Dockerfile.testing.build_flatc_debian_stretch: -------------------------------------------------------------------------------- 1 | FROM debian:9.6-slim as base 2 | RUN apt -qq update >/dev/null 3 | RUN apt -qq install -y cmake make build-essential >/dev/null 4 | FROM base 5 | WORKDIR /code 6 | ADD . . 7 | RUN cmake -G "Unix Makefiles" 8 | RUN make flatc 9 | RUN ls flatc 10 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.python.numpy.cpython_3_7_1: -------------------------------------------------------------------------------- 1 | FROM python:3.7.1-slim-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN python --version 7 | RUN pip install numpy 8 | RUN pip install coverage 9 | RUN ./PythonTest.sh 10 | -------------------------------------------------------------------------------- /tests/include_test/sub/include_test2.fbs: -------------------------------------------------------------------------------- 1 | include "include_test1.fbs"; 2 | include "sub/include_test2.fbs"; // should be skipped 3 | 4 | namespace MyGame.OtherNameSpace; 5 | 6 | enum FromInclude:long { IncludeVal } 7 | 8 | struct Unused { a:int; } 9 | 10 | table TableB { 11 | a:TableA; 12 | } 13 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local Any = { 6 | NONE = 0, 7 | Monster = 1, 8 | TestSimpleTableWithEnum = 2, 9 | MyGame_Example2_Monster = 3, 10 | } 11 | 12 | return Any -- return the module -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.python.numpy.cpython_2_7_15: -------------------------------------------------------------------------------- 1 | FROM python:2.7.15-slim-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN python --version 7 | RUN pip install numpy 8 | RUN pip install coverage 9 | RUN ./PythonTest.sh 10 | -------------------------------------------------------------------------------- /src/clang-format-all.sh: -------------------------------------------------------------------------------- 1 | # Running it twice corrects some bugs in clang-format. 2 | for run in {1..2} 3 | do 4 | clang-format -i -style=file include/flatbuffers/* src/*.cpp tests/*.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp 5 | done 6 | git checkout include/flatbuffers/reflection_generated.h 7 | -------------------------------------------------------------------------------- /src/clang-format-git.sh: -------------------------------------------------------------------------------- 1 | # Running it twice corrects some bugs in clang-format. 2 | for run in {1..2} 3 | do 4 | git clang-format HEAD^ -- include/flatbuffers/* src/*.cpp tests/*.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp 5 | done 6 | git checkout include/flatbuffers/reflection_generated.h 7 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyAmbiguousAliases.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local AnyAmbiguousAliases = { 6 | NONE = 0, 7 | M1 = 1, 8 | M2 = 2, 9 | M3 = 3, 10 | } 11 | 12 | return AnyAmbiguousAliases -- return the module -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.node.10_13_0: -------------------------------------------------------------------------------- 1 | FROM node:10.13.0-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN node --version 7 | RUN ../flatc -b -I include_test monster_test.fbs unicode_test.json 8 | RUN node JavaScriptTest ./monster_test_generated 9 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.node.11_2_0: -------------------------------------------------------------------------------- 1 | FROM node:11.2.0-stretch as base 2 | WORKDIR /code 3 | ADD . . 4 | RUN cp flatc_debian_stretch flatc 5 | WORKDIR /code/tests 6 | RUN node --version 7 | RUN ../flatc -b -I include_test monster_test.fbs unicode_test.json 8 | RUN node JavaScriptTest ./monster_test_generated 9 | -------------------------------------------------------------------------------- /tests/native_type_test.fbs: -------------------------------------------------------------------------------- 1 | native_include "native_type_test_impl.h"; 2 | 3 | namespace Geometry; 4 | 5 | struct Vector3D (native_type:"Native::Vector3D") { 6 | x:float; 7 | y:float; 8 | z:float; 9 | } 10 | 11 | table ApplicationData { 12 | vectors:[Vector3D]; 13 | } 14 | 15 | root_type ApplicationData; 16 | -------------------------------------------------------------------------------- /tests/fuzzer/fuzzer_assert.h: -------------------------------------------------------------------------------- 1 | #ifndef FUZZER_ASSERT_IMPL_H_ 2 | #define FUZZER_ASSERT_IMPL_H_ 3 | 4 | // Declare Debug/Release independed assert macro. 5 | #define fuzzer_assert_impl(x) (!!(x) ? static_cast(0) : __builtin_trap()) 6 | 7 | extern "C" void __builtin_trap(void); 8 | 9 | #endif // !FUZZER_ASSERT_IMPL_H_ 10 | -------------------------------------------------------------------------------- /dart/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 1.9.2 4 | 5 | - Ensure `_writeString` adds enough padding to null terminate strings. 6 | 7 | ## 1.9.1 8 | 9 | - Changed constant identifiers to be compatible with Dart 2.x 10 | - No longer supports Dart 1.x 11 | 12 | ## 1.9.0 13 | 14 | - Initial release, supports Dart 1.x and many dev versions of Dart 2.x -------------------------------------------------------------------------------- /swift/README.md: -------------------------------------------------------------------------------- 1 | FlatBuffers swift can be found in both SPM 2 | 3 | `.package(url: "https://github.com/mustiikhalil/flatbuffers.git", .branch("swift"))` 4 | 5 | and Cocoapods 6 | 7 | `pod 'FlatBuffers', :git => 'https://github.com/mustiikhalil/flatbuffers.git' :branch => 'swift'` 8 | 9 | To report any error please use the main repository. 10 | 11 | -------------------------------------------------------------------------------- /.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | buildifier: latest 3 | platforms: 4 | ubuntu1604: 5 | build_targets: 6 | - "..." 7 | test_targets: 8 | - "..." 9 | ubuntu1804: 10 | build_targets: 11 | - "..." 12 | test_targets: 13 | - "..." 14 | macos: 15 | build_targets: 16 | - "..." 17 | test_targets: 18 | - "..." 19 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | DerivePointerAlignment: false 5 | PointerAlignment: Right 6 | IndentPPDirectives: AfterHash 7 | Cpp11BracedListStyle: false 8 | AlwaysBreakTemplateDeclarations: false 9 | AllowShortCaseLabelsOnASingleLine: true 10 | SpaceAfterTemplateKeyword: false 11 | AllowShortBlocksOnASingleLine: true 12 | ... 13 | 14 | -------------------------------------------------------------------------------- /conan/test_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(test_package CXX) 2 | cmake_minimum_required(VERSION 2.8.11) 3 | 4 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 5 | conan_basic_setup() 6 | 7 | add_executable(${PROJECT_NAME} test_package.cpp) 8 | target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) 9 | set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) 10 | -------------------------------------------------------------------------------- /grpc/samples/greeter/greeter.fbs: -------------------------------------------------------------------------------- 1 | table HelloReply { 2 | message:string; 3 | } 4 | 5 | table HelloRequest { 6 | name:string; 7 | } 8 | 9 | table ManyHellosRequest { 10 | name:string; 11 | num_greetings:int; 12 | } 13 | 14 | rpc_service Greeter { 15 | SayHello(HelloRequest):HelloReply; 16 | SayManyHellos(ManyHellosRequest):HelloReply (streaming: "server"); 17 | } 18 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | # Composite components of Monster color. 6 | class Color(object): 7 | Red = 1 8 | # \brief color Green 9 | # Green is bit_flag with value (1u << 1) 10 | Green = 2 11 | # \brief color Blue (1u << 3) 12 | Blue = 8 13 | 14 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test.Swift/SwiftTest.sh: -------------------------------------------------------------------------------- 1 | swift_dir=`pwd` 2 | cd .. 3 | test_dir=`pwd` 4 | 5 | ${test_dir}/../flatc --swift --gen-mutable -I ${test_dir}/include_test ${test_dir}/monster_test.fbs ${test_dir}/union_vector/union_vector.fbs 6 | cd ${test_dir} 7 | mv *_generated.swift ${swift_dir}/Tests/FlatBuffers.Test.SwiftTests 8 | cd ${swift_dir} 9 | swift build --build-tests 10 | swift test -------------------------------------------------------------------------------- /.travis/deploy-python.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | PROD_REPOSITORY="https://upload.pypi.org/legacy/" 5 | TEST_REPOSITORY="https://test.pypi.org/legacy/" 6 | 7 | twine upload \ 8 | --username "$PYPI_USERNAME" \ 9 | --password "$PYPI_PASSWORD" \ 10 | --repository-url "$PROD_REPOSITORY" \ 11 | "$DIR/../python/dist/"* 12 | 13 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestEnum.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 9 | public enum TestEnum : sbyte 10 | { 11 | A = 0, 12 | B = 1, 13 | C = 2, 14 | }; 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /samples/monsterdata.json: -------------------------------------------------------------------------------- 1 | { 2 | pos: { 3 | x: 1.0, 4 | y: 2.0, 5 | z: 3.0 6 | }, 7 | hp: 300, 8 | name: "Orc", 9 | weapons: [ 10 | { 11 | name: "axe", 12 | damage: 100 13 | }, 14 | { 15 | name: "bow", 16 | damage: 90 17 | } 18 | ], 19 | equipped_type: "Weapon", 20 | equipped: { 21 | name: "bow", 22 | damage: 90 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.fbs: -------------------------------------------------------------------------------- 1 | table HelloReply { 2 | message:string; 3 | } 4 | 5 | table HelloRequest { 6 | name:string; 7 | } 8 | 9 | table ManyHellosRequest { 10 | name:string; 11 | num_greetings:int; 12 | } 13 | 14 | rpc_service Greeter { 15 | SayHello(HelloRequest):HelloReply; 16 | SayManyHellos(ManyHellosRequest):HelloReply (streaming: "server"); 17 | } 18 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 9 | public enum Race : sbyte 10 | { 11 | None = -1, 12 | Human = 0, 13 | Dwarf = 1, 14 | Elf = 2, 15 | }; 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tests/evolution_test/evolution_v1.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": 42, 3 | "b": true, 4 | "c_type": "TableB", 5 | "c": { 6 | "a": 15 7 | }, 8 | "d": "King", 9 | "e": { 10 | "a": 3.1452, 11 | "b": 325 12 | }, 13 | "f":{ 14 | "a": 16, 15 | "b": 243.980943 16 | }, 17 | "g": [ 7, 8, 9], 18 | "h": [ 19 | { 20 | "a": 212 21 | }, 22 | { 23 | "a": 459 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /conan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | message(STATUS "Conan FlatBuffers Wrapper") 4 | 5 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 6 | conan_basic_setup() 7 | 8 | if (WIN32 AND MSVC AND FLATBUFFERS_BUILD_SHAREDLIB) 9 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) 10 | endif(WIN32 AND MSVC AND FLATBUFFERS_BUILD_SHAREDLIB) 11 | 12 | include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt) 13 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | -- Composite components of Monster color. 6 | local Color = { 7 | Red = 1, 8 | -- \brief color Green 9 | -- Green is bit_flag with value (1u << 1) 10 | Green = 2, 11 | -- \brief color Blue (1u << 3) 12 | Blue = 8, 13 | } 14 | 15 | return Color -- return the module -------------------------------------------------------------------------------- /tests/docker/Dockerfile.testing.cpp.debian_buster: -------------------------------------------------------------------------------- 1 | FROM debian:10.1-slim as base 2 | RUN apt -qq update >/dev/null 3 | RUN apt -qq install -y cmake make build-essential >/dev/null 4 | RUN apt -qq install -y autoconf git libtool >/dev/null 5 | RUN apt -qq install -y clang >/dev/null 6 | FROM base 7 | # Travis machines have 2 cores. Can be redefined with 'run --env PAR_JOBS=N'. 8 | ENV JOBS=2 9 | WORKDIR /flatbuffers 10 | ADD . . 11 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace NamespaceA.NamespaceB 6 | { 7 | 8 | [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 9 | public enum EnumInNestedNS : sbyte 10 | { 11 | A = 0, 12 | B = 1, 13 | C = 2, 14 | }; 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /tests/native_type_test_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "native_type_test_impl.h" 2 | 3 | #include "native_type_test_generated.h" 4 | 5 | namespace flatbuffers { 6 | Geometry::Vector3D Pack(const Native::Vector3D &obj) { 7 | return Geometry::Vector3D(obj.x, obj.y, obj.z); 8 | } 9 | 10 | const Native::Vector3D UnPack(const Geometry::Vector3D &obj) { 11 | return Native::Vector3D(obj.x(), obj.y(), obj.z()); 12 | } 13 | } // namespace flatbuffers 14 | -------------------------------------------------------------------------------- /go/lib.go: -------------------------------------------------------------------------------- 1 | package flatbuffers 2 | 3 | // FlatBuffer is the interface that represents a flatbuffer. 4 | type FlatBuffer interface { 5 | Table() Table 6 | Init(buf []byte, i UOffsetT) 7 | } 8 | 9 | // GetRootAs is a generic helper to initialize a FlatBuffer with the provided buffer bytes and its data offset. 10 | func GetRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) { 11 | n := GetUOffsetT(buf[offset:]) 12 | fb.Init(buf, n+offset) 13 | } 14 | -------------------------------------------------------------------------------- /swift/Sources/FlatBuffers/Offset.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// Offset object for all the Objects that are written into the buffer 4 | public struct Offset { 5 | /// Offset of the object in the buffer 6 | public var o: UOffset 7 | /// Returns false if the offset is equal to zero 8 | public var isEmpty: Bool { return o == 0 } 9 | 10 | public init(offset: UOffset) { o = offset } 11 | public init() { o = 0 } 12 | } 13 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google/flatbuffers", 3 | "type": "library", 4 | "description": "FlatBuffers for PHP", 5 | "keywords": ["google", "flatbuffers", "serialization"], 6 | "homepage": "https://github.com/google/flatbuffers", 7 | "license": "Apache-2.0", 8 | "require": { 9 | "php": ">=5.4" 10 | }, 11 | "require-dev": { 12 | }, 13 | "autoload": { 14 | "psr-4": { 15 | "Google\\FlatBuffers\\": "php" 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /tests/docker/build_flatc.run.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | JOBS=${JOBS:-1} 4 | config=$1 5 | echo "" 6 | echo "Build 'flatc' compiler for '$config'" 7 | 8 | cmake . -DCMAKE_BUILD_TYPE=$config \ 9 | -DFLATBUFFERS_BUILD_FLATC=1 -DFLATBUFFERS_STATIC_FLATC=1 \ 10 | -DFLATBUFFERS_BUILD_TESTS=0 -DFLATBUFFERS_INSTALL=0 11 | cmake --build . --target flatc --clean-first -- -j$JOBS 12 | 13 | echo "Check generated code" 14 | .travis/check-generate-code.sh 15 | echo "Done" 16 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestEnum.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | public final class TestEnum { 6 | private TestEnum() { } 7 | public static final byte A = 0; 8 | public static final byte B = 1; 9 | public static final byte C = 2; 10 | 11 | public static final String[] names = { "A", "B", "C", }; 12 | 13 | public static String name(int e) { return names[e]; } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestEnum.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | @Suppress("unused") 6 | class TestEnum private constructor() { 7 | companion object { 8 | const val A: Byte = 0 9 | const val B: Byte = 1 10 | const val C: Byte = 2 11 | val names : Array = arrayOf("A", "B", "C") 12 | fun name(e: Int) : String = names[e] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CMake/FlatbuffersConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /net/FlatBuffers/FlatBuffers.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/docker/languages/Dockerfile.testing.rust.big_endian.1_37_0: -------------------------------------------------------------------------------- 1 | FROM rust:1.37.0-slim-stretch as base 2 | RUN apt -qq update -y && apt -qq install -y \ 3 | gcc-mips-linux-gnu \ 4 | libexpat1 \ 5 | libmagic1 \ 6 | libmpdec2 \ 7 | libreadline7 \ 8 | qemu-user 9 | RUN rustup target add mips-unknown-linux-gnu 10 | WORKDIR /code 11 | ADD . . 12 | RUN cp flatc_debian_stretch flatc 13 | WORKDIR /code/tests 14 | RUN rustc --version 15 | RUN ./RustTest.sh mips-unknown-linux-gnu 16 | -------------------------------------------------------------------------------- /tests/union_vector/union_vector.json: -------------------------------------------------------------------------------- 1 | { 2 | "main_character_type": "Rapunzel", 3 | "main_character": { 4 | "hair_length": 6 5 | }, 6 | "characters_type": [ 7 | "Belle", 8 | "MuLan", 9 | "BookFan", 10 | "Other", 11 | "Unused" 12 | ], 13 | "characters": [ 14 | { 15 | "books_read": 7 16 | }, 17 | { 18 | "sword_attack_damage": 5 19 | }, 20 | { 21 | "books_read": 2 22 | }, 23 | "Other", 24 | "Unused" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/arrays_test.fbs: -------------------------------------------------------------------------------- 1 | namespace MyGame.Example; 2 | 3 | enum TestEnum : byte { A, B, C } 4 | 5 | struct NestedStruct{ 6 | a:[int:2]; 7 | b:TestEnum; 8 | c:[TestEnum:2]; 9 | d:[int64:2]; 10 | } 11 | 12 | struct ArrayStruct{ 13 | a:float; 14 | b:[int:0xF]; 15 | c:byte; 16 | d:[NestedStruct:2]; 17 | e:int32; 18 | f:[int64:2]; 19 | } 20 | 21 | table ArrayTable{ 22 | a:ArrayStruct; 23 | } 24 | 25 | root_type ArrayTable; 26 | file_identifier "ARRT"; 27 | file_extension "mon"; 28 | -------------------------------------------------------------------------------- /lua/flatbuffers/compat.lua: -------------------------------------------------------------------------------- 1 | local m = {} 2 | 3 | local getAlignSize 4 | if _VERSION == "Lua 5.3" then 5 | getAlignSize = function(k, size) 6 | return ((~k) + 1) & (size - 1) 7 | end 8 | else 9 | getAlignSize = function(self, size, additionalBytes) 10 | local alignsize = bit32.bnot(#self.bytes-self:Head() + additionalBytes) + 1 11 | return bit32.band(alignsize,(size - 1)) 12 | end 13 | end 14 | 15 | m.GetAlignSize = getAlignSize 16 | 17 | return m -------------------------------------------------------------------------------- /tests/monsterdata_extra.json: -------------------------------------------------------------------------------- 1 | { 2 | // Initialize with non-default values. 3 | d0 : -nan, // match with default 4 | d1 : +inf, 5 | d2 : -inf, 6 | d3: nan, 7 | f0 : +nan, // match with default 8 | f1 : -nan, // match with default 9 | f2 : +inf, // match with default 10 | f3 : -inf, // match with default 11 | // Values should have exact binary representation 12 | // to avoid rounding effects in tests. 13 | dvec : [2.0, +inf, -inf, nan,], 14 | fvec : [1.0, -inf, +inf, nan], 15 | } 16 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA.NamespaceB; 4 | 5 | public final class EnumInNestedNS { 6 | private EnumInNestedNS() { } 7 | public static final byte A = 0; 8 | public static final byte B = 1; 9 | public static final byte C = 2; 10 | 11 | public static final String[] names = { "A", "B", "C", }; 12 | 13 | public static String name(int e) { return names[e]; } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /swift/Sources/FlatBuffers/Struct.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public struct Struct { 4 | public private(set) var bb: ByteBuffer 5 | public private(set) var postion: Int32 6 | 7 | public init(bb: ByteBuffer, position: Int32 = 0) { 8 | self.bb = bb 9 | self.postion = position 10 | } 11 | 12 | public func readBuffer(of type: T.Type, at o: Int32) -> T { 13 | let r = bb.read(def: T.self, position: Int(o + postion)) 14 | return r 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | public final class Race { 6 | private Race() { } 7 | public static final byte None = -1; 8 | public static final byte Human = 0; 9 | public static final byte Dwarf = 1; 10 | public static final byte Elf = 2; 11 | 12 | public static final String[] names = { "None", "Human", "Dwarf", "Elf", }; 13 | 14 | public static String name(int e) { return names[e - None]; } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/arrays_test.golden: -------------------------------------------------------------------------------- 1 | { 2 | a : { 3 | a: 12.34, 4 | b: [1,2,3,4,5,6,7,8,9,0xA,0xB,0xC,0xD,0xE,0xF], 5 | c: -127, 6 | d: [ 7 | { 8 | a : [-1,2], 9 | b : A, 10 | c : [C, B], 11 | d : [0x1122334455667788, -0x1122334455667788] 12 | }, 13 | { 14 | a : [3,-4], 15 | b : B, 16 | c : [B, A], 17 | d : [-0x1122334455667788, 0x1122334455667788] 18 | } 19 | ], 20 | e: 1, 21 | f: [-0x8000000000000000, 0x7FFFFFFFFFFFFFFF] 22 | } 23 | } -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA.NamespaceB 4 | 5 | @Suppress("unused") 6 | @ExperimentalUnsignedTypes 7 | class EnumInNestedNS private constructor() { 8 | companion object { 9 | const val A: Byte = 0 10 | const val B: Byte = 1 11 | const val C: Byte = 2 12 | val names : Array = arrayOf("A", "B", "C") 13 | fun name(e: Int) : String = names[e] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /rust/flatbuffers/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flatbuffers" 3 | version = "0.6.2" 4 | authors = ["Robert Winslow ", "FlatBuffers Maintainers"] 5 | license = "Apache-2.0" 6 | description = "Official FlatBuffers Rust runtime library." 7 | homepage = "https://google.github.io/flatbuffers/" 8 | repository = "https://github.com/google/flatbuffers" 9 | keywords = ["flatbuffers", "serialization", "zero-copy"] 10 | categories = ["encoding", "data-structures", "memory-management"] 11 | 12 | [dependencies] 13 | smallvec = "1.0" 14 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyUniqueAliases.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | public final class AnyUniqueAliases { 6 | private AnyUniqueAliases() { } 7 | public static final byte NONE = 0; 8 | public static final byte M = 1; 9 | public static final byte TS = 2; 10 | public static final byte M2 = 3; 11 | 12 | public static final String[] names = { "NONE", "M", "TS", "M2", }; 13 | 14 | public static String name(int e) { return names[e]; } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/fuzzer/flatbuffers_verifier_fuzzer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | #include 5 | #include 6 | #include 7 | 8 | #include "monster_test_generated.h" 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 11 | flatbuffers::Verifier verifier(data, size); 12 | MyGame::Example::VerifyMonsterBuffer(verifier); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /conan/travis/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [[ "$(uname -s)" == 'Darwin' ]]; then 7 | brew update || brew update 8 | brew outdated pyenv || brew upgrade pyenv 9 | brew install pyenv-virtualenv 10 | brew install cmake || true 11 | 12 | if which pyenv > /dev/null; then 13 | eval "$(pyenv init -)" 14 | fi 15 | 16 | pyenv install 2.7.10 17 | pyenv virtualenv 2.7.10 conan 18 | pyenv rehash 19 | pyenv activate conan 20 | fi 21 | 22 | pip install -U conan_package_tools conan 23 | -------------------------------------------------------------------------------- /tests/unicode_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unicode_test", 3 | "testarrayofstring": [ 4 | "Цлїςσδε", 5 | "フムアムカモケモ", 6 | "フムヤムカモケモ", 7 | "㊀㊁㊂㊃㊄", 8 | "☳☶☲", 9 | "𡇙𝌆" 10 | ], 11 | "testarrayoftables": [ 12 | { 13 | "name": "Цлїςσδε" 14 | }, 15 | { 16 | "name": "☳☶☲" 17 | }, 18 | { 19 | "name": "フムヤムカモケモ" 20 | }, 21 | { 22 | "name": "㊀㊁㊂㊃㊄" 23 | }, 24 | { 25 | "name": "フムアムカモケモ" 26 | }, 27 | { 28 | "name": "𡇙𝌆" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyAmbiguousAliases.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | public final class AnyAmbiguousAliases { 6 | private AnyAmbiguousAliases() { } 7 | public static final byte NONE = 0; 8 | public static final byte M1 = 1; 9 | public static final byte M2 = 2; 10 | public static final byte M3 = 3; 11 | 12 | public static final String[] names = { "NONE", "M1", "M2", "M3", }; 13 | 14 | public static String name(int e) { return names[e]; } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /grpc/samples/greeter/Makefile: -------------------------------------------------------------------------------- 1 | CXXFLAGS ?= -I../../../include 2 | LDFLAGS ?= 3 | 4 | .PHONY: all 5 | all: server client 6 | 7 | greeter_generated.h: greeter.fbs 8 | flatc --grpc --cpp $< 9 | 10 | server: server.cpp greeter.grpc.fb.cc greeter_generated.h greeter.grpc.fb.h 11 | g++ -std=c++11 -O2 $(CXXFLAGS) $(LDFLAGS) -lgpr -lgrpc -lgrpc++ server.cpp greeter.grpc.fb.cc -o $@ 12 | 13 | client: client.cpp greeter.grpc.fb.cc greeter_generated.h greeter.grpc.fb.h 14 | g++ -std=c++11 -O2 $(CXXFLAGS) $(LDFLAGS) -lgpr -lgrpc -lgrpc++ client.cpp greeter.grpc.fb.cc -o $@ 15 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyUniqueAliases.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | @Suppress("unused") 6 | @ExperimentalUnsignedTypes 7 | class AnyUniqueAliases private constructor() { 8 | companion object { 9 | const val NONE: UByte = 0u 10 | const val M: UByte = 1u 11 | const val TS: UByte = 2u 12 | const val M2: UByte = 3u 13 | val names : Array = arrayOf("NONE", "M", "TS", "M2") 14 | fun name(e: Int) : String = names[e] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | @Suppress("unused") 6 | @ExperimentalUnsignedTypes 7 | class Race private constructor() { 8 | companion object { 9 | const val None: Byte = -1 10 | const val Human: Byte = 0 11 | const val Dwarf: Byte = 1 12 | const val Elf: Byte = 2 13 | val names : Array = arrayOf("None", "Human", "Dwarf", "Elf") 14 | fun name(e: Int) : String = names[e - None.toInt()] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /go/BUILD.bazel: -------------------------------------------------------------------------------- 1 | load("@io_bazel_rules_go//go:def.bzl", "go_library") 2 | 3 | alias( 4 | name = "go_default_library", 5 | actual = ":go", 6 | visibility = ["//visibility:public"], 7 | ) 8 | 9 | go_library( 10 | name = "go", 11 | srcs = [ 12 | "builder.go", 13 | "doc.go", 14 | "encode.go", 15 | "grpc.go", 16 | "lib.go", 17 | "sizes.go", 18 | "struct.go", 19 | "table.go", 20 | ], 21 | importpath = "github.com/google/flatbuffers/go", 22 | visibility = ["//visibility:public"], 23 | ) 24 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyAmbiguousAliases.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | @Suppress("unused") 6 | @ExperimentalUnsignedTypes 7 | class AnyAmbiguousAliases private constructor() { 8 | companion object { 9 | const val NONE: UByte = 0u 10 | const val M1: UByte = 1u 11 | const val M2: UByte = 2u 12 | const val M3: UByte = 3u 13 | val names : Array = arrayOf("NONE", "M1", "M2", "M3") 14 | fun name(e: Int) : String = names[e] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for submitting an issue! 2 | 3 | Please make sure you include the names of the affected language(s), compiler version(s), operating system version(s), and FlatBuffers version(s) in your issue title. 4 | 5 | This helps us get the correct maintainers to look at your issue. Here are examples of good titles: 6 | 7 | - Crash when accessing FlatBuffer [C++, gcc 4.8, OS X, master] 8 | - Flatc converts a protobuf 'bytes' field to 'string' in fbs schema file [all languages, FlatBuffers 1.4] 9 | 10 | Include other details as appropriate. 11 | 12 | Thanks! 13 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Benchmarks.swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "FlatBuffers.Benchmarks.swift", 8 | platforms: [ 9 | .macOS(.v10_14) 10 | ], 11 | dependencies: [ 12 | .package(path: "../../swift") 13 | ], 14 | targets: [ 15 | .target( 16 | name: "FlatBuffers.Benchmarks.swift", 17 | dependencies: ["FlatBuffers"]), 18 | ] 19 | ) 20 | -------------------------------------------------------------------------------- /tests/evolution_test/evolution_v1.fbs: -------------------------------------------------------------------------------- 1 | namespace Evolution.V1; 2 | 3 | table TableA { 4 | a:float; 5 | b:int; 6 | } 7 | 8 | table TableB { 9 | a:int; 10 | } 11 | 12 | enum Enum : byte { 13 | King, 14 | Queen 15 | } 16 | 17 | union Union { 18 | TableA, 19 | TableB 20 | } 21 | 22 | struct Struct { 23 | a:int; 24 | b:double; 25 | } 26 | 27 | table Root { 28 | a:int; 29 | b:bool; 30 | c:Union; 31 | d:Enum; 32 | e:TableA; 33 | f:Struct; 34 | g:[int]; 35 | h:[TableB]; 36 | i:int = 1234; 37 | } 38 | 39 | root_type Root; -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | /// Composite components of Monster color. 9 | [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 10 | [System.FlagsAttribute] 11 | public enum Color : byte 12 | { 13 | Red = 1, 14 | /// \brief color Green 15 | /// Green is bit_flag with value (1u << 1) 16 | Green = 2, 17 | /// \brief color Blue (1u << 3) 18 | Blue = 8, 19 | }; 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /tests/evolution_test/evolution_v2.json: -------------------------------------------------------------------------------- 1 | { 2 | "b": false, 3 | "c_type": "TableC", 4 | "c": { 5 | "a": 984.2494 6 | }, 7 | "d": "Bishop", 8 | "e": { 9 | "a": 3.1452, 10 | "b": 435, 11 | "c": "yummy yummy fig bar bar" 12 | }, 13 | "ff":{ 14 | "a": 35, 15 | "b": 243.980943 16 | }, 17 | "g": [ 7, 8, 10], 18 | "h": [ 19 | { 20 | "a": 212 21 | }, 22 | { 23 | "a": 459 24 | }, 25 | { 26 | "a": 333 27 | } 28 | ], 29 | "i": 4321, 30 | "j": { 31 | "a": 9874.342, 32 | "b": "more please" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "FlatBuffers", 8 | platforms: [ 9 | .iOS(.v11), 10 | .macOS(.v10_14), 11 | ], 12 | products: [ 13 | .library( 14 | name: "FlatBuffers", 15 | targets: ["FlatBuffers"]), 16 | ], 17 | targets: [ 18 | .target( 19 | name: "FlatBuffers", 20 | dependencies: []), 21 | ] 22 | ) 23 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | public final class Any { 6 | private Any() { } 7 | public static final byte NONE = 0; 8 | public static final byte Monster = 1; 9 | public static final byte TestSimpleTableWithEnum = 2; 10 | public static final byte MyGame_Example2_Monster = 3; 11 | 12 | public static final String[] names = { "NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster", }; 13 | 14 | public static String name(int e) { return names[e]; } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/docker/cpp_test.run.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | JOBS=${JOBS:-1} 4 | export UBSAN_OPTIONS=halt_on_error=1 5 | export ASAN_OPTIONS=halt_on_error=1 6 | export MAKEFLAGS="-j$JOBS" 7 | 8 | config=$1 9 | echo "" 10 | echo "Build Flatbuffers project for '$config' with jobs=$JOBS" 11 | 12 | cmake . -DCMAKE_BUILD_TYPE=$config \ 13 | -DFLATBUFFERS_BUILD_TESTS=ON -DFLATBUFFERS_CODE_SANITIZE=ON 14 | cmake --build . --target all --clean-first -- -j$JOBS 15 | ctest --extra-verbose --output-on-failure -j$JOBS 16 | 17 | echo "Check generated code" 18 | .travis/check-generate-code.sh 19 | 20 | echo "C++ tests done" 21 | -------------------------------------------------------------------------------- /tests/namespace_test/namespace_test2.fbs: -------------------------------------------------------------------------------- 1 | include "namespace_test1.fbs"; 2 | 3 | namespace NamespaceA; 4 | 5 | table TableInFirstNS 6 | { 7 | foo_table:NamespaceB.TableInNestedNS; 8 | foo_enum:NamespaceB.EnumInNestedNS; 9 | foo_struct:NamespaceB.StructInNestedNS; 10 | } 11 | 12 | // Test switching namespaces inside a file. 13 | namespace NamespaceC; 14 | 15 | table TableInC { 16 | refer_to_a1:NamespaceA.TableInFirstNS; 17 | refer_to_a2:NamespaceA.SecondTableInA; 18 | } 19 | 20 | namespace NamespaceA; 21 | 22 | table SecondTableInA { 23 | refer_to_c:NamespaceC.TableInC; 24 | } 25 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test.Swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "FlatBuffers.Test.Swift", 8 | platforms: [ 9 | .iOS(.v11), 10 | .macOS(.v10_14), 11 | ], 12 | dependencies: [ 13 | .package(path: "../../swift/") 14 | ], 15 | targets: [ 16 | .testTarget( 17 | name: "FlatBuffers.Test.SwiftTests", 18 | dependencies: ["FlatBuffers"]), 19 | ] 20 | ) 21 | -------------------------------------------------------------------------------- /swift/Sources/FlatBuffers/FlatBuffersUtils.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | public final class FlatBuffersUtils { 4 | 5 | /// Gets the size of the prefix 6 | /// - Parameter bb: Flatbuffer object 7 | public static func getSizePrefix(bb: ByteBuffer) -> Int32 { 8 | return bb.read(def: Int32.self, position: bb.reader) 9 | } 10 | 11 | /// Removes the prefix by duplicating the Flatbuffer 12 | /// - Parameter bb: Flatbuffer object 13 | public static func removeSizePrefix(bb: ByteBuffer) -> ByteBuffer { 14 | return bb.duplicate(removing: MemoryLayout.size) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/monster_extra.fbs: -------------------------------------------------------------------------------- 1 | namespace MyGame; 2 | 3 | // Not all programming languages support this extra table. 4 | table MonsterExtra { 5 | // Float-point values with NaN and Inf defaults. 6 | d0:double = nan; 7 | d1:double = -nan; // parser must ignore sign of NaN 8 | d2:double = +inf; 9 | d3:double = -inf; 10 | f0:float = -nan; // parser must ignore sign of NaN 11 | f1:float = +nan; 12 | f2:float = +inf; 13 | f3:float = -inf; 14 | dvec : [double]; 15 | fvec : [float]; 16 | deprec:int (deprecated); 17 | } 18 | 19 | root_type MonsterExtra; 20 | 21 | file_identifier "MONE"; 22 | file_extension "mon"; 23 | -------------------------------------------------------------------------------- /CMake/Version.cmake: -------------------------------------------------------------------------------- 1 | find_program(GIT git) 2 | execute_process( 3 | COMMAND ${GIT} describe 4 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 5 | OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY 6 | OUTPUT_STRIP_TRAILING_WHITESPACE 7 | ) 8 | string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}") 9 | string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}") 10 | string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}") 11 | string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}") 12 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | @Suppress("unused") 6 | @ExperimentalUnsignedTypes 7 | class Any_ private constructor() { 8 | companion object { 9 | const val NONE: UByte = 0u 10 | const val Monster: UByte = 1u 11 | const val TestSimpleTableWithEnum: UByte = 2u 12 | const val MyGameExample2Monster: UByte = 3u 13 | val names : Array = arrayOf("NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster") 14 | fun name(e: Int) : String = names[e] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php: -------------------------------------------------------------------------------- 1 | "A", 14 | EnumInNestedNS::B=>"B", 15 | EnumInNestedNS::C=>"C", 16 | ); 17 | 18 | public static function Name($e) 19 | { 20 | if (!isset(self::$names[$e])) { 21 | throw new \Exception(); 22 | } 23 | return self::$names[$e]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /conan/test_package/conanfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from conans import ConanFile, CMake 5 | import os 6 | 7 | 8 | class TestPackageConan(ConanFile): 9 | settings = "os", "compiler", "build_type", "arch" 10 | generators = "cmake" 11 | 12 | def build(self): 13 | cmake = CMake(self) 14 | cmake.configure() 15 | cmake.build() 16 | 17 | def test(self): 18 | bin_path = os.path.join("bin", "test_package") 19 | self.run(bin_path, run_environment=True) 20 | self.run("flatc --version", run_environment=True) 21 | self.run("flathash fnv1_16 conan", run_environment=True) 22 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.php: -------------------------------------------------------------------------------- 1 | "None", 15 | Race::Human=>"Human", 16 | Race::Dwarf=>"Dwarf", 17 | Race::Elf=>"Elf", 18 | ); 19 | 20 | public static function Name($e) 21 | { 22 | if (!isset(self::$names[$e])) { 23 | throw new \Exception(); 24 | } 25 | return self::$names[$e]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/union_vector/Character.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | public final class Character { 4 | private Character() { } 5 | public static final byte NONE = 0; 6 | public static final byte MuLan = 1; 7 | public static final byte Rapunzel = 2; 8 | public static final byte Belle = 3; 9 | public static final byte BookFan = 4; 10 | public static final byte Other = 5; 11 | public static final byte Unused = 6; 12 | 13 | public static final String[] names = { "NONE", "MuLan", "Rapunzel", "Belle", "BookFan", "Other", "Unused", }; 14 | 15 | public static String name(int e) { return names[e]; } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/rust_usage_test/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_usage_test" 3 | version = "0.1.0" 4 | authors = ["Robert Winslow ", "FlatBuffers Maintainers"] 5 | 6 | [dependencies] 7 | flatbuffers = { path = "../../rust/flatbuffers" } 8 | 9 | [[bin]] 10 | name = "monster_example" 11 | path = "bin/monster_example.rs" 12 | 13 | [[bin]] 14 | name = "alloc_check" 15 | path = "bin/alloc_check.rs" 16 | 17 | 18 | [dev-dependencies] 19 | quickcheck = "0.6" 20 | # TODO(rw): look into moving to criterion.rs 21 | bencher = "0.1.5" 22 | static_assertions = "1.0.0" 23 | 24 | [[bench]] 25 | # setup for bencher 26 | name = "flatbuffers_benchmarks" 27 | harness = false 28 | -------------------------------------------------------------------------------- /samples/monster.fbs: -------------------------------------------------------------------------------- 1 | // Example IDL file for our monster's schema. 2 | 3 | namespace MyGame.Sample; 4 | 5 | enum Color:byte { Red = 0, Green, Blue = 2 } 6 | 7 | union Equipment { Weapon } // Optionally add more tables. 8 | 9 | struct Vec3 { 10 | x:float; 11 | y:float; 12 | z:float; 13 | } 14 | 15 | table Monster { 16 | pos:Vec3; 17 | mana:short = 150; 18 | hp:short = 100; 19 | name:string; 20 | friendly:bool = false (deprecated); 21 | inventory:[ubyte]; 22 | color:Color = Blue; 23 | weapons:[Weapon]; 24 | equipped:Equipment; 25 | path:[Vec3]; 26 | } 27 | 28 | table Weapon { 29 | name:string; 30 | damage:short; 31 | } 32 | 33 | root_type Monster; 34 | -------------------------------------------------------------------------------- /grpc/build_grpc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | grpc_1_15_1_githash=1a60e6971f428323245a930031ad267bb3142ba4 4 | 5 | function build_grpc () { 6 | git clone https://github.com/grpc/grpc.git google/grpc 7 | cd google/grpc 8 | git checkout ${grpc_1_15_1_githash} 9 | git submodule update --init 10 | make 11 | make install prefix=`pwd`/install 12 | if [ ! -f ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1 ]; then 13 | ln -s ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.6 ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1 14 | fi 15 | cd ../.. 16 | } 17 | 18 | GRPC_INSTALL_PATH=`pwd`/google/grpc/install 19 | PROTOBUF_DOWNLOAD_PATH=`pwd`/google/grpc/third_party/protobuf 20 | 21 | build_grpc 22 | -------------------------------------------------------------------------------- /tests/union_vector/Character.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | @Suppress("unused") 4 | @ExperimentalUnsignedTypes 5 | class Character_ private constructor() { 6 | companion object { 7 | const val NONE: UByte = 0u 8 | const val MuLan: UByte = 1u 9 | const val Rapunzel: UByte = 2u 10 | const val Belle: UByte = 3u 11 | const val BookFan: UByte = 4u 12 | const val Other: UByte = 5u 13 | const val Unused: UByte = 6u 14 | val names : Array = arrayOf("NONE", "MuLan", "Rapunzel", "Belle", "BookFan", "Other", "Unused") 15 | fun name(e: Int) : String = names[e] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyUniqueAliases.php: -------------------------------------------------------------------------------- 1 | "NONE", 15 | AnyUniqueAliases::M=>"M", 16 | AnyUniqueAliases::TS=>"TS", 17 | AnyUniqueAliases::M2=>"M2", 18 | ); 19 | 20 | public static function Name($e) 21 | { 22 | if (!isset(self::$names[$e])) { 23 | throw new \Exception(); 24 | } 25 | return self::$names[$e]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | /** 6 | * Composite components of Monster color. 7 | */ 8 | public final class Color { 9 | private Color() { } 10 | public static final byte Red = 1; 11 | /** 12 | * \brief color Green 13 | * Green is bit_flag with value (1u << 1) 14 | */ 15 | public static final byte Green = 2; 16 | /** 17 | * \brief color Blue (1u << 3) 18 | */ 19 | public static final byte Blue = 8; 20 | 21 | public static final String[] names = { "Red", "Green", "", "", "", "", "", "Blue", }; 22 | 23 | public static String name(int e) { return names[e - Red]; } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tests/native_type_test_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef NATIVE_TYPE_TEST_IMPL_H 2 | #define NATIVE_TYPE_TEST_IMPL_H 3 | 4 | namespace Native { 5 | struct Vector3D { 6 | float x; 7 | float y; 8 | float z; 9 | 10 | Vector3D() { 11 | x = 0; 12 | y = 0; 13 | z = 0; 14 | }; 15 | Vector3D(float _x, float _y, float _z) { 16 | this->x = _x; 17 | this->y = _y; 18 | this->z = _z; 19 | } 20 | }; 21 | } // namespace Native 22 | 23 | namespace Geometry { 24 | struct Vector3D; 25 | } 26 | 27 | namespace flatbuffers { 28 | Geometry::Vector3D Pack(const Native::Vector3D &obj); 29 | const Native::Vector3D UnPack(const Geometry::Vector3D &obj); 30 | } // namespace flatbuffers 31 | 32 | #endif // VECTOR3D_PACK_H 33 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "com_github_google_flatbuffers") 2 | 3 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 4 | 5 | http_archive( 6 | name = "io_bazel_rules_go", 7 | urls = [ 8 | "https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz", 9 | "https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz", 10 | ], 11 | sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b", 12 | ) 13 | 14 | load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains") 15 | 16 | go_rules_dependencies() 17 | 18 | go_register_toolchains() 19 | -------------------------------------------------------------------------------- /dart/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flat_buffers 2 | version: 1.12.0 3 | description: > 4 | FlatBuffers reading and writing library for Dart. Use the flatc compiler to 5 | generate Dart classes for a FlatBuffers schema, and this library to assist with 6 | reading and writing the binary format. 7 | 8 | Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team. 9 | authors: 10 | - Dan Field 11 | - Konstantin Scheglov 12 | - Paul Berry 13 | homepage: https://github.com/google/flatbuffers 14 | documentation: https://google.github.io/flatbuffers/index.html 15 | dev_dependencies: 16 | test: ^1.3.0 17 | test_reflective_loader: ^0.1.4 18 | path: ^1.5.1 19 | environment: 20 | sdk: '>=2.0.0-dev.28.0 <3.0.0' -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyAmbiguousAliases.php: -------------------------------------------------------------------------------- 1 | "NONE", 15 | AnyAmbiguousAliases::M1=>"M1", 16 | AnyAmbiguousAliases::M2=>"M2", 17 | AnyAmbiguousAliases::M3=>"M3", 18 | ); 19 | 20 | public static function Name($e) 21 | { 22 | if (!isset(self::$names[$e])) { 23 | throw new \Exception(); 24 | } 25 | return self::$names[$e]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/union_vector/union_vector.fbs: -------------------------------------------------------------------------------- 1 | // Demonstrates the ability to have vectors of unions, and also to 2 | // store structs and strings in unions. 3 | 4 | table Attacker { 5 | sword_attack_damage: int; 6 | } 7 | 8 | struct Rapunzel { 9 | hair_length: int; 10 | } 11 | 12 | struct BookReader { 13 | books_read: int; 14 | } 15 | 16 | union Character { 17 | MuLan: Attacker, // Can have name be different from type. 18 | Rapunzel, // Or just both the same, as before. 19 | Belle: BookReader, 20 | BookFan: BookReader, 21 | Other: string, 22 | Unused: string 23 | } 24 | 25 | table Movie { 26 | main_character: Character; 27 | characters: [Character]; 28 | } 29 | 30 | root_type Movie; 31 | file_identifier "MOVI"; 32 | -------------------------------------------------------------------------------- /dart/README.md: -------------------------------------------------------------------------------- 1 | # FlatBuffers for Dart 2 | 3 | This package is used to read and write FlatBuffer files in Dart. 4 | 5 | Most consumers will want to use the [`flatc`](https://github.com/google/flatbuffers) 6 | compiler to generate Dart code from a FlatBuffers IDL schema. For example, the 7 | `monster_my_game.sample_generated.dart` was generated with `flatc` from 8 | `monster.fbs` in the example folder. The generated classes can be used to read 9 | or write binary files that are interoperable with other languages and platforms 10 | supported by FlatBuffers, as illustrated in the `example.dart` in the 11 | examples folder. 12 | 13 | Additional documentation and examples are available [at the FlatBuffers site](https://google.github.io/flatbuffers/index.html) -------------------------------------------------------------------------------- /tests/MyGame/Example/Race.go: -------------------------------------------------------------------------------- 1 | // Code generated by the FlatBuffers compiler. DO NOT EDIT. 2 | 3 | package Example 4 | 5 | import "strconv" 6 | 7 | type Race int8 8 | 9 | const ( 10 | RaceNone Race = -1 11 | RaceHuman Race = 0 12 | RaceDwarf Race = 1 13 | RaceElf Race = 2 14 | ) 15 | 16 | var EnumNamesRace = map[Race]string{ 17 | RaceNone: "None", 18 | RaceHuman: "Human", 19 | RaceDwarf: "Dwarf", 20 | RaceElf: "Elf", 21 | } 22 | 23 | var EnumValuesRace = map[string]Race{ 24 | "None": RaceNone, 25 | "Human": RaceHuman, 26 | "Dwarf": RaceDwarf, 27 | "Elf": RaceElf, 28 | } 29 | 30 | func (v Race) String() string { 31 | if s, ok := EnumNamesRace[v]; ok { 32 | return s 33 | } 34 | return "Race(" + strconv.FormatInt(int64(v), 10) + ")" 35 | } 36 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.php: -------------------------------------------------------------------------------- 1 | "NONE", 15 | Any::Monster=>"Monster", 16 | Any::TestSimpleTableWithEnum=>"TestSimpleTableWithEnum", 17 | Any::MyGame_Example2_Monster=>"MyGame_Example2_Monster", 18 | ); 19 | 20 | public static function Name($e) 21 | { 22 | if (!isset(self::$names[$e])) { 23 | throw new \Exception(); 24 | } 25 | return self::$names[$e]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.php: -------------------------------------------------------------------------------- 1 | "Red", 18 | Color::Green=>"Green", 19 | Color::Blue=>"Blue", 20 | ); 21 | 22 | public static function Name($e) 23 | { 24 | if (!isset(self::$names[$e])) { 25 | throw new \Exception(); 26 | } 27 | return self::$names[$e]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/source/groups: -------------------------------------------------------------------------------- 1 | /// @defgroup flatbuffers_cpp_api C++ API 2 | /// @brief FlatBuffers API for C++ 3 | 4 | /// @defgroup flatbuffers_csharp_api C# API 5 | /// @brief FlatBuffers API for C# 6 | 7 | /// @defgroup flatbuffers_go_api Go API 8 | /// @brief FlatBuffers API for Go 9 | 10 | /// @defgroup flatbuffers_java_api Java API 11 | /// @brief FlatBuffers API for Java 12 | 13 | /// @defgroup flatbuffers_javascript_api JavaScript API 14 | /// @brief FlatBuffers API for JavaScript 15 | 16 | /// @defgroup flatbuffers_typescript_api TypeScript API 17 | /// @brief FlatBuffers API for TypeScript 18 | 19 | /// @defgroup flatbuffers_php_api PHP API 20 | /// @brief FlatBuffers API for PHP 21 | 22 | /// @defgroup flatbuffers_python_api Python API 23 | /// @brief FlatBuffers API for Python 24 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | /** 6 | * Composite components of Monster color. 7 | */ 8 | @Suppress("unused") 9 | @ExperimentalUnsignedTypes 10 | class Color private constructor() { 11 | companion object { 12 | const val Red: UByte = 1u 13 | /** 14 | * \brief color Green 15 | * Green is bit_flag with value (1u << 1) 16 | */ 17 | const val Green: UByte = 2u 18 | /** 19 | * \brief color Blue (1u << 3) 20 | */ 21 | const val Blue: UByte = 8u 22 | val names : Array = arrayOf("Red", "Green", "", "", "", "", "", "Blue") 23 | fun name(e: Int) : String = names[e - Red.toInt()] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /python/flatbuffers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014 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 | from .builder import Builder 16 | from .table import Table 17 | from .compat import range_func as compat_range 18 | from . import util 19 | -------------------------------------------------------------------------------- /samples/android/jni/schemas/animal.fbs: -------------------------------------------------------------------------------- 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 | namespace sample; 16 | 17 | table Animal { 18 | name:string; 19 | sound:string; 20 | } 21 | 22 | root_type Animal; 23 | -------------------------------------------------------------------------------- /tests/JavaScriptTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2016 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | pushd "$(dirname $0)" >/dev/null 18 | ../flatc -b -I include_test monster_test.fbs unicode_test.json 19 | node JavaScriptTest ./monster_test_generated 20 | -------------------------------------------------------------------------------- /tests/LuaTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eu 2 | # 3 | # Copyright 2019 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | pushd "$(dirname $0)" >/dev/null 18 | test_dir="$(pwd)" 19 | 20 | ${test_dir}/../flatc --lua -I include_test monster_test.fbs 21 | 22 | lua5.3 luatest.lua 23 | -------------------------------------------------------------------------------- /android/jni/main.cpp: -------------------------------------------------------------------------------- 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 18 | 19 | extern int main(int argc, char **argv); 20 | 21 | void android_main(android_app *) { 22 | main(0, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /php/Constants.php: -------------------------------------------------------------------------------- 1 | 13 | This issue has been automatically marked as stale because it has not had 14 | activity for 1 year. It will be automatically closed if no further activity occurs. 15 | To keep it open, simply post a new comment. Maintainers will re-open on 16 | new activity. Thank you for your contributions. 17 | # Comment to post when closing a stale issue. Set to `false` to disable 18 | closeComment: false 19 | -------------------------------------------------------------------------------- /reflection/generate_code.bat: -------------------------------------------------------------------------------- 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 | set buildtype=Release 16 | if "%1"=="-b" set buildtype=%2 17 | 18 | ..\%buildtype%\flatc.exe --cpp --cpp-std c++0x --no-prefix -o ../include/flatbuffers reflection.fbs || exit /b 1 19 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.go: -------------------------------------------------------------------------------- 1 | // Code generated by the FlatBuffers compiler. DO NOT EDIT. 2 | 3 | package Example 4 | 5 | import "strconv" 6 | 7 | /// Composite components of Monster color. 8 | type Color byte 9 | 10 | const ( 11 | ColorRed Color = 1 12 | /// \brief color Green 13 | /// Green is bit_flag with value (1u << 1) 14 | ColorGreen Color = 2 15 | /// \brief color Blue (1u << 3) 16 | ColorBlue Color = 8 17 | ) 18 | 19 | var EnumNamesColor = map[Color]string{ 20 | ColorRed: "Red", 21 | ColorGreen: "Green", 22 | ColorBlue: "Blue", 23 | } 24 | 25 | var EnumValuesColor = map[string]Color{ 26 | "Red": ColorRed, 27 | "Green": ColorGreen, 28 | "Blue": ColorBlue, 29 | } 30 | 31 | func (v Color) String() string { 32 | if s, ok := EnumNamesColor[v]; ok { 33 | return s 34 | } 35 | return "Color(" + strconv.FormatInt(int64(v), 10) + ")" 36 | } 37 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.go: -------------------------------------------------------------------------------- 1 | // Code generated by the FlatBuffers compiler. DO NOT EDIT. 2 | 3 | package NamespaceB 4 | 5 | import "strconv" 6 | 7 | type EnumInNestedNS int8 8 | 9 | const ( 10 | EnumInNestedNSA EnumInNestedNS = 0 11 | EnumInNestedNSB EnumInNestedNS = 1 12 | EnumInNestedNSC EnumInNestedNS = 2 13 | ) 14 | 15 | var EnumNamesEnumInNestedNS = map[EnumInNestedNS]string{ 16 | EnumInNestedNSA: "A", 17 | EnumInNestedNSB: "B", 18 | EnumInNestedNSC: "C", 19 | } 20 | 21 | var EnumValuesEnumInNestedNS = map[string]EnumInNestedNS{ 22 | "A": EnumInNestedNSA, 23 | "B": EnumInNestedNSB, 24 | "C": EnumInNestedNSC, 25 | } 26 | 27 | func (v EnumInNestedNS) String() string { 28 | if s, ok := EnumNamesEnumInNestedNS[v]; ok { 29 | return s 30 | } 31 | return "EnumInNestedNS(" + strconv.FormatInt(int64(v), 10) + ")" 32 | } 33 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/Monster.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example2 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Monster = {} -- the module 8 | local Monster_mt = {} -- the class metatable 9 | 10 | function Monster.New() 11 | local o = {} 12 | setmetatable(o, {__index = Monster_mt}) 13 | return o 14 | end 15 | function Monster.GetRootAsMonster(buf, offset) 16 | local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) 17 | local o = Monster.New() 18 | o:Init(buf, n + offset) 19 | return o 20 | end 21 | function Monster_mt:Init(buf, pos) 22 | self.view = flatbuffers.view.New(buf, pos) 23 | end 24 | function Monster.Start(builder) builder:StartObject(0) end 25 | function Monster.End(builder) return builder:EndObject() end 26 | 27 | return Monster -- return the module -------------------------------------------------------------------------------- /tests/union_vector/Character.php: -------------------------------------------------------------------------------- 1 | "NONE", 16 | Character::MuLan=>"MuLan", 17 | Character::Rapunzel=>"Rapunzel", 18 | Character::Belle=>"Belle", 19 | Character::BookFan=>"BookFan", 20 | Character::Other=>"Other", 21 | Character::Unused=>"Unused", 22 | ); 23 | 24 | public static function Name($e) 25 | { 26 | if (!isset(self::$names[$e])) { 27 | throw new \Exception(); 28 | } 29 | return self::$names[$e]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /swift/Sources/FlatBuffers/Int+extension.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension Int { 4 | 5 | /// Moves the current int into the nearest power of two 6 | /// 7 | /// This is used since the UnsafeMutableRawPointer will face issues when writing/reading 8 | /// if the buffer alignment exceeds that actual size of the buffer 9 | var convertToPowerofTwo: Int { 10 | guard self > 0 else { return 1 } 11 | var n = UOffset(self) 12 | 13 | #if arch(arm) || arch(i386) 14 | let max = UInt32(Int.max) 15 | #else 16 | let max = UInt32.max 17 | #endif 18 | 19 | n -= 1 20 | n |= n >> 1 21 | n |= n >> 2 22 | n |= n >> 4 23 | n |= n >> 8 24 | n |= n >> 16 25 | if n != max { 26 | n += 1 27 | } 28 | 29 | return Int(n) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Benchmarks/FlatBuffers.Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | latest 7 | true 8 | $(DefineConstants);UNSAFE_BYTEBUFFER;BYTEBUFFER_NO_BOUNDS_CHECK;ENABLE_SPAN_T 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for submitting a PR! 2 | 3 | Please delete this standard text once you've created your own description. 4 | 5 | Make sure you include the names of the affected language(s) in your PR title. 6 | This helps us get the correct maintainers to look at your issue. 7 | 8 | If you make changes to any of the code generators, be sure to run 9 | `cd tests && sh generate_code.sh` (or equivalent .bat) and include the generated 10 | code changes in the PR. This allows us to better see the effect of the PR. 11 | 12 | If your PR includes C++ code, please adhere to the Google C++ Style Guide, 13 | and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3), 14 | so only some C++11 support is available. 15 | 16 | For any C++ changes, please make sure to run `sh src/clang-format-git.sh` 17 | 18 | Include other details as appropriate. 19 | 20 | Thanks! 21 | -------------------------------------------------------------------------------- /tests/docker/TODO.Dockerfile.testing.php.hhvm_2019_01_16: -------------------------------------------------------------------------------- 1 | # This does not pass tests due to the following error: 2 | # 3 | # Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Google\FlatBuffers\ByteBuffer::getX() expects parameter 1 by reference, but the call was not annotated with '&'. in /code/php/FlatbufferBuilder.php:971 4 | # Stack trace: 5 | # #0 /code/tests/phpTest.php(277): Google\FlatBuffers\FlatbufferBuilder->sizedByteArray() 6 | # #1 /code/tests/phpTest.php(79): fuzzTest1() 7 | # #2 /code/tests/phpTest.php(86): main() 8 | # #3 {main} 9 | # thrown in in /code/php/FlatbufferBuilder.php:971 10 | FROM hhvm/hhvm:2019.01.16 as base 11 | WORKDIR /code 12 | ADD . . 13 | RUN cp flatc_debian_stretch flatc 14 | WORKDIR /code/tests 15 | RUN hhvm --version 16 | RUN hhvm phpTest.php 17 | RUN ../flatc --php -o php union_vector/union_vector.fbs 18 | RUN hhvm phpUnionVectorTest.php 19 | -------------------------------------------------------------------------------- /tests/union_vector/Rapunzel.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | import java.nio.* 4 | import kotlin.math.sign 5 | import com.google.flatbuffers.* 6 | 7 | @Suppress("unused") 8 | @ExperimentalUnsignedTypes 9 | class Rapunzel : Struct() { 10 | 11 | fun __init(_i: Int, _bb: ByteBuffer) { 12 | __reset(_i, _bb) 13 | } 14 | fun __assign(_i: Int, _bb: ByteBuffer) : Rapunzel { 15 | __init(_i, _bb) 16 | return this 17 | } 18 | val hairLength : Int get() = bb.getInt(bb_pos + 0) 19 | fun mutateHairLength(hairLength: Int) : ByteBuffer = bb.putInt(bb_pos + 0, hairLength) 20 | companion object { 21 | fun createRapunzel(builder: FlatBufferBuilder, hairLength: Int) : Int { 22 | builder.prep(4, 4) 23 | builder.putInt(hairLength) 24 | return builder.offset() 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/union_vector/BookReader.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | import java.nio.* 4 | import kotlin.math.sign 5 | import com.google.flatbuffers.* 6 | 7 | @Suppress("unused") 8 | @ExperimentalUnsignedTypes 9 | class BookReader : Struct() { 10 | 11 | fun __init(_i: Int, _bb: ByteBuffer) { 12 | __reset(_i, _bb) 13 | } 14 | fun __assign(_i: Int, _bb: ByteBuffer) : BookReader { 15 | __init(_i, _bb) 16 | return this 17 | } 18 | val booksRead : Int get() = bb.getInt(bb_pos + 0) 19 | fun mutateBooksRead(booksRead: Int) : ByteBuffer = bb.putInt(bb_pos + 0, booksRead) 20 | companion object { 21 | fun createBookReader(builder: FlatBufferBuilder, booksRead: Int) : Int { 22 | builder.prep(4, 4) 23 | builder.putInt(booksRead) 24 | return builder.offset() 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/source/gRPC/CppUsage.md: -------------------------------------------------------------------------------- 1 | Use in C++ {#flatbuffers_grpc_guide_use_cpp} 2 | ========== 3 | 4 | ## Before you get started 5 | 6 | Before diving into the FlatBuffers gRPC usage in C++, you should already be 7 | familiar with the following: 8 | 9 | - FlatBuffers as a serialization format 10 | - [gRPC](http://www.grpc.io/docs/) usage 11 | 12 | ## Using the FlatBuffers gRPC C++ library 13 | 14 | NOTE: The examples below are also in the `grpc/samples/greeter` directory. 15 | 16 | We will illustrate usage with the following schema: 17 | 18 | @include grpc/samples/greeter/greeter.fbs 19 | 20 | When we run `flatc`, we pass in the `--grpc` option and generage an additional 21 | `greeter.grpc.fb.h` and `greeter.grpc.fb.cc`. 22 | 23 | Example server code looks like this: 24 | 25 | @include grpc/samples/greeter/server.cpp 26 | 27 | Example client code looks like this: 28 | 29 | @include grpc/samples/greeter/client.cpp 30 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/FlatBuffersTestMethodAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 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 | using System; 18 | 19 | namespace FlatBuffers.Test 20 | { 21 | [AttributeUsage(AttributeTargets.Method)] 22 | public class FlatBuffersTestMethodAttribute : Attribute 23 | { 24 | } 25 | } -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Test = {} -- the module 8 | local Test_mt = {} -- the class metatable 9 | 10 | function Test.New() 11 | local o = {} 12 | setmetatable(o, {__index = Test_mt}) 13 | return o 14 | end 15 | function Test_mt:Init(buf, pos) 16 | self.view = flatbuffers.view.New(buf, pos) 17 | end 18 | function Test_mt:A() 19 | return self.view:Get(flatbuffers.N.Int16, self.view.pos + 0) 20 | end 21 | function Test_mt:B() 22 | return self.view:Get(flatbuffers.N.Int8, self.view.pos + 2) 23 | end 24 | function Test.CreateTest(builder, a, b) 25 | builder:Prep(2, 4) 26 | builder:Pad(1) 27 | builder:PrependInt8(b) 28 | builder:PrependInt16(a) 29 | return builder:Offset() 30 | end 31 | 32 | return Test -- return the module -------------------------------------------------------------------------------- /snap/snapcraft.yaml: -------------------------------------------------------------------------------- 1 | name: flatbuffers 2 | base: core18 3 | version: git 4 | summary: FlatBuffers compiler 5 | description: | 6 | FlatBuffers compiler 7 | 8 | NOTE: This snap also ships the necessary header files required to compile 9 | projects using flatbuffers, however, for the compilation to work, you have 10 | to manually add the following path in your project's configuration: 11 | 12 | /snap/flatbuffers/current/include 13 | 14 | If you need to use flatbuffers headers from a location other than the above 15 | path, it is recommended to not use this snap as that could cause a mismatch. 16 | 17 | grade: stable 18 | confinement: strict 19 | 20 | parts: 21 | flatc: 22 | plugin: cmake 23 | source: . 24 | configflags: 25 | - -GUnix Makefiles 26 | - -DCMAKE_BUILD_TYPE=Release 27 | build-packages: 28 | - g++ 29 | 30 | apps: 31 | flatc: 32 | command: flatc 33 | plugs: 34 | - home 35 | -------------------------------------------------------------------------------- /tests/RustTest.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Copyright 2018 Google Inc. All rights reserved. 3 | rem 4 | rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | rem you may not use this file except in compliance with the License. 6 | rem You may obtain a copy of the License at 7 | rem 8 | rem http://www.apache.org/licenses/LICENSE-2.0 9 | rem 10 | rem Unless required by applicable law or agreed to in writing, software 11 | rem distributed under the License is distributed on an "AS IS" BASIS, 12 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | rem See the License for the specific language governing permissions and 14 | rem limitations under the License. 15 | 16 | rem Compile then run the Rust test. 17 | 18 | rem TODO(rw): how do we make this script abort the calling script in appveyor? 19 | 20 | cd rust_usage_test 21 | cargo test -- --quiet || exit /b 1 22 | cargo run --bin=alloc_check || exit /b 1 23 | cd .. 24 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Ability.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Ability = {} -- the module 8 | local Ability_mt = {} -- the class metatable 9 | 10 | function Ability.New() 11 | local o = {} 12 | setmetatable(o, {__index = Ability_mt}) 13 | return o 14 | end 15 | function Ability_mt:Init(buf, pos) 16 | self.view = flatbuffers.view.New(buf, pos) 17 | end 18 | function Ability_mt:Id() 19 | return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 0) 20 | end 21 | function Ability_mt:Distance() 22 | return self.view:Get(flatbuffers.N.Uint32, self.view.pos + 4) 23 | end 24 | function Ability.CreateAbility(builder, id, distance) 25 | builder:Prep(4, 8) 26 | builder:PrependUint32(distance) 27 | builder:PrependUint32(id) 28 | return builder:Offset() 29 | end 30 | 31 | return Ability -- return the module -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyAmbiguousAliases.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | class AnyAmbiguousAliases(object): 6 | NONE = 0 7 | M1 = 1 8 | M2 = 2 9 | M3 = 3 10 | 11 | 12 | def AnyAmbiguousAliasesCreator(unionType, table): 13 | from flatbuffers.table import Table 14 | if not isinstance(table, Table): 15 | return None 16 | if unionType == AnyAmbiguousAliases().M1: 17 | import MyGame.Example.Monster 18 | return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 19 | if unionType == AnyAmbiguousAliases().M2: 20 | import MyGame.Example.Monster 21 | return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 22 | if unionType == AnyAmbiguousAliases().M3: 23 | import MyGame.Example.Monster 24 | return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 25 | return None 26 | -------------------------------------------------------------------------------- /tests/MyGame/InParentNamespace.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: MyGame 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local InParentNamespace = {} -- the module 8 | local InParentNamespace_mt = {} -- the class metatable 9 | 10 | function InParentNamespace.New() 11 | local o = {} 12 | setmetatable(o, {__index = InParentNamespace_mt}) 13 | return o 14 | end 15 | function InParentNamespace.GetRootAsInParentNamespace(buf, offset) 16 | local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) 17 | local o = InParentNamespace.New() 18 | o:Init(buf, n + offset) 19 | return o 20 | end 21 | function InParentNamespace_mt:Init(buf, pos) 22 | self.view = flatbuffers.view.New(buf, pos) 23 | end 24 | function InParentNamespace.Start(builder) builder:StartObject(0) end 25 | function InParentNamespace.End(builder) return builder:EndObject() end 26 | 27 | return InParentNamespace -- return the module -------------------------------------------------------------------------------- /swift/FlatBuffers.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'FlatBuffers' 3 | s.version = '0.2.0' 4 | s.summary = 'FlatBuffers: Memory Efficient Serialization Library' 5 | 6 | s.description = "FlatBuffers is a cross platform serialization library architected for 7 | maximum memory efficiency. It allows you to directly access serialized 8 | data without parsing/unpacking it first, while still having great 9 | forwards/backwards compatibility." 10 | 11 | s.homepage = 'https://github.com/google/flatbuffers' 12 | s.license = { :type => 'Apache2.0', :file => 'LICENSE' } 13 | s.author = { 'mustii' => 'mustii@mmk.one' } 14 | s.source = { :git => 'https://github.com/mustiikhalil/flatbuffers.git', :tag => s.version.to_s, :submodules => true } 15 | 16 | s.ios.deployment_target = '11.0' 17 | s.osx.deployment_target = '10.14' 18 | 19 | s.swift_version = '5.0' 20 | s.source_files = 'Sources/**/*' 21 | end 22 | -------------------------------------------------------------------------------- /tests/MyGame/Example/AnyUniqueAliases.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | class AnyUniqueAliases(object): 6 | NONE = 0 7 | M = 1 8 | TS = 2 9 | M2 = 3 10 | 11 | 12 | def AnyUniqueAliasesCreator(unionType, table): 13 | from flatbuffers.table import Table 14 | if not isinstance(table, Table): 15 | return None 16 | if unionType == AnyUniqueAliases().M: 17 | import MyGame.Example.Monster 18 | return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 19 | if unionType == AnyUniqueAliases().TS: 20 | import MyGame.Example.TestSimpleTableWithEnum 21 | return MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos) 22 | if unionType == AnyUniqueAliases().M2: 23 | import MyGame.Example2.Monster 24 | return MyGame.Example2.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 25 | return None 26 | -------------------------------------------------------------------------------- /net/FlatBuffers/IFlatbufferObject.cs: -------------------------------------------------------------------------------- 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 | namespace FlatBuffers 18 | { 19 | /// 20 | /// This is the base for both structs and tables. 21 | /// 22 | public interface IFlatbufferObject 23 | { 24 | void __init(int _i, ByteBuffer _bb); 25 | 26 | ByteBuffer ByteBuffer { get; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/FlatBuffersTestClassAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 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 | using System; 18 | using System.Collections.Generic; 19 | using System.Linq; 20 | using System.Text; 21 | 22 | namespace FlatBuffers.Test 23 | { 24 | [AttributeUsage(AttributeTargets.Class)] 25 | public class FlatBuffersTestClassAttribute : Attribute 26 | { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | class Any(object): 6 | NONE = 0 7 | Monster = 1 8 | TestSimpleTableWithEnum = 2 9 | MyGame_Example2_Monster = 3 10 | 11 | 12 | def AnyCreator(unionType, table): 13 | from flatbuffers.table import Table 14 | if not isinstance(table, Table): 15 | return None 16 | if unionType == Any().Monster: 17 | import MyGame.Example.Monster 18 | return MyGame.Example.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 19 | if unionType == Any().TestSimpleTableWithEnum: 20 | import MyGame.Example.TestSimpleTableWithEnum 21 | return MyGame.Example.TestSimpleTableWithEnum.TestSimpleTableWithEnumT.InitFromBuf(table.Bytes, table.Pos) 22 | if unionType == Any().MyGame_Example2_Monster: 23 | import MyGame.Example2.Monster 24 | return MyGame.Example2.Monster.MonsterT.InitFromBuf(table.Bytes, table.Pos) 25 | return None 26 | -------------------------------------------------------------------------------- /tests/rust_usage_test/bin/monster_example.rs: -------------------------------------------------------------------------------- 1 | extern crate flatbuffers; 2 | 3 | #[allow(dead_code, unused_imports)] 4 | #[path = "../../include_test/include_test1_generated.rs"] 5 | pub mod include_test1_generated; 6 | 7 | #[allow(dead_code, unused_imports)] 8 | #[path = "../../include_test/sub/include_test2_generated.rs"] 9 | pub mod include_test2_generated; 10 | 11 | #[allow(dead_code, unused_imports)] 12 | #[path = "../../monster_test_generated.rs"] 13 | mod monster_test_generated; 14 | pub use monster_test_generated::my_game; 15 | 16 | 17 | use std::io::Read; 18 | 19 | fn main() { 20 | let mut f = std::fs::File::open("../monsterdata_test.mon").unwrap(); 21 | let mut buf = Vec::new(); 22 | f.read_to_end(&mut buf).expect("file reading failed"); 23 | 24 | let monster = my_game::example::get_root_as_monster(&buf[..]); 25 | println!("{}", monster.hp()); // `80` 26 | println!("{}", monster.mana()); // default value of `150` 27 | println!("{:?}", monster.name()); // Some("MyMonster") 28 | } 29 | -------------------------------------------------------------------------------- /tests/evolution_test/evolution_v2.fbs: -------------------------------------------------------------------------------- 1 | namespace Evolution.V2; 2 | 3 | table TableA { 4 | b:int (id: 1); // swapped with 'a' 5 | a:float (id: 0); // swapped with 'b' 6 | c:string (id: 2); // new in v2 7 | } 8 | 9 | table TableB { 10 | a:int; 11 | } 12 | 13 | table TableC { // new in v2 14 | a:double; 15 | b:string; 16 | } 17 | 18 | enum Enum : byte { 19 | King, 20 | Queen, 21 | Rook, // new in v2 22 | Bishop // new in v2 23 | } 24 | 25 | union Union { 26 | TableA, 27 | TableB, 28 | TableC 29 | } 30 | 31 | struct Struct { 32 | a:int; 33 | b:double; 34 | } 35 | 36 | table Root { 37 | a:int (deprecated); // deprecated in v2 38 | b:bool; 39 | c:Union; 40 | d:Enum; 41 | e:TableA; 42 | ff:Struct; // renamed from 'f' in v1 43 | g:[int]; 44 | h:[TableB]; 45 | i:uint = 1234; 46 | j:TableC; // new in v2 47 | k:uint8 = 56; // new in v2 48 | } 49 | 50 | root_type Root; -------------------------------------------------------------------------------- /samples/lua/MyGame/Sample/Vec3.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Sample 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Vec3 = {} -- the module 8 | local Vec3_mt = {} -- the class metatable 9 | 10 | function Vec3.New() 11 | local o = {} 12 | setmetatable(o, {__index = Vec3_mt}) 13 | return o 14 | end 15 | function Vec3_mt:Init(buf, pos) 16 | self.view = flatbuffers.view.New(buf, pos) 17 | end 18 | function Vec3_mt:X() 19 | return self.view:Get(flatbuffers.N.Float32, self.view.pos + 0) 20 | end 21 | function Vec3_mt:Y() 22 | return self.view:Get(flatbuffers.N.Float32, self.view.pos + 4) 23 | end 24 | function Vec3_mt:Z() 25 | return self.view:Get(flatbuffers.N.Float32, self.view.pos + 8) 26 | end 27 | function Vec3.CreateVec3(builder, x, y, z) 28 | builder:Prep(4, 12) 29 | builder:PrependFloat32(z) 30 | builder:PrependFloat32(y) 31 | builder:PrependFloat32(x) 32 | return builder:Offset() 33 | end 34 | 35 | return Vec3 -- return the module -------------------------------------------------------------------------------- /tests/JavaTest.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem Copyright 2014 Google Inc. All rights reserved. 3 | rem 4 | rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | rem you may not use this file except in compliance with the License. 6 | rem You may obtain a copy of the License at 7 | rem 8 | rem http://www.apache.org/licenses/LICENSE-2.0 9 | rem 10 | rem Unless required by applicable law or agreed to in writing, software 11 | rem distributed under the License is distributed on an "AS IS" BASIS, 12 | rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | rem See the License for the specific language governing permissions and 14 | rem limitations under the License. 15 | 16 | rem Compile then run the Java test. 17 | 18 | set batch_file_dir=%~d0%~p0 19 | 20 | javac -g -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test;%batch_file_dir%\union_vector JavaTest.java 21 | java -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test;%batch_file_dir%\union_vector JavaTest 22 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: NamespaceB 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local StructInNestedNS = {} -- the module 8 | local StructInNestedNS_mt = {} -- the class metatable 9 | 10 | function StructInNestedNS.New() 11 | local o = {} 12 | setmetatable(o, {__index = StructInNestedNS_mt}) 13 | return o 14 | end 15 | function StructInNestedNS_mt:Init(buf, pos) 16 | self.view = flatbuffers.view.New(buf, pos) 17 | end 18 | function StructInNestedNS_mt:A() 19 | return self.view:Get(flatbuffers.N.Int32, self.view.pos + 0) 20 | end 21 | function StructInNestedNS_mt:B() 22 | return self.view:Get(flatbuffers.N.Int32, self.view.pos + 4) 23 | end 24 | function StructInNestedNS.CreateStructInNestedNS(builder, a, b) 25 | builder:Prep(4, 8) 26 | builder:PrependInt32(b) 27 | builder:PrependInt32(a) 28 | return builder:Offset() 29 | end 30 | 31 | return StructInNestedNS -- return the module -------------------------------------------------------------------------------- /tests/FlatBuffers.Benchmarks/Program.cs: -------------------------------------------------------------------------------- 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 | using BenchmarkDotNet.Running; 18 | 19 | namespace FlatBuffers.Benchmarks 20 | { 21 | public static class Program 22 | { 23 | public static void Main(string[] args) 24 | { 25 | BenchmarkSwitcher 26 | .FromAssembly(typeof(Program).Assembly) 27 | .Run(args); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flatbuffers", 3 | "version": "1.12.0", 4 | "description": "Memory Efficient Serialization Library", 5 | "files": [ 6 | "js/flatbuffers.js", 7 | "js/flatbuffers.mjs" 8 | ], 9 | "main": "js/flatbuffers", 10 | "module": "js/flatbuffers.mjs", 11 | "directories": { 12 | "doc": "docs", 13 | "test": "tests" 14 | }, 15 | "scripts": { 16 | "test": "tests/JavaScriptTest.sh", 17 | "append-esm-export": "sed \"s/this.flatbuffers = flatbuffers;/export { flatbuffers };/\" js/flatbuffers.js > js/flatbuffers.mjs", 18 | "prepublishOnly": "npm run append-esm-export" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/google/flatbuffers.git" 23 | }, 24 | "keywords": [ 25 | "flatbuffers" 26 | ], 27 | "author": "The FlatBuffers project", 28 | "license": "SEE LICENSE IN LICENSE.txt", 29 | "bugs": { 30 | "url": "https://github.com/google/flatbuffers/issues" 31 | }, 32 | "homepage": "https://google.github.io/flatbuffers/", 33 | "dependencies": {} 34 | } 35 | -------------------------------------------------------------------------------- /tests/union_vector/Rapunzel.php: -------------------------------------------------------------------------------- 1 | bb_pos = $_i; 19 | $this->bb = $_bb; 20 | return $this; 21 | } 22 | 23 | /** 24 | * @return int 25 | */ 26 | public function GetHairLength() 27 | { 28 | return $this->bb->getInt($this->bb_pos + 0); 29 | } 30 | 31 | 32 | /** 33 | * @return int offset 34 | */ 35 | public static function createRapunzel(FlatBufferBuilder $builder, $hairLength) 36 | { 37 | $builder->prep(4, 4); 38 | $builder->putInt($hairLength); 39 | return $builder->offset(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | import java.nio.* 6 | import kotlin.math.sign 7 | import com.google.flatbuffers.* 8 | 9 | @Suppress("unused") 10 | @ExperimentalUnsignedTypes 11 | class Test : Struct() { 12 | 13 | fun __init(_i: Int, _bb: ByteBuffer) { 14 | __reset(_i, _bb) 15 | } 16 | fun __assign(_i: Int, _bb: ByteBuffer) : Test { 17 | __init(_i, _bb) 18 | return this 19 | } 20 | val a : Short get() = bb.getShort(bb_pos + 0) 21 | fun mutateA(a: Short) : ByteBuffer = bb.putShort(bb_pos + 0, a) 22 | val b : Byte get() = bb.get(bb_pos + 2) 23 | fun mutateB(b: Byte) : ByteBuffer = bb.put(bb_pos + 2, b) 24 | companion object { 25 | fun createTest(builder: FlatBufferBuilder, a: Short, b: Byte) : Int { 26 | builder.prep(2, 4) 27 | builder.pad(1) 28 | builder.putByte(b) 29 | builder.putShort(a) 30 | return builder.offset() 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/union_vector/BookReader.php: -------------------------------------------------------------------------------- 1 | bb_pos = $_i; 19 | $this->bb = $_bb; 20 | return $this; 21 | } 22 | 23 | /** 24 | * @return int 25 | */ 26 | public function GetBooksRead() 27 | { 28 | return $this->bb->getInt($this->bb_pos + 0); 29 | } 30 | 31 | 32 | /** 33 | * @return int offset 34 | */ 35 | public static function createBookReader(FlatBufferBuilder $builder, $booksRead) 36 | { 37 | $builder->prep(4, 4); 38 | $builder->putInt($booksRead); 39 | return $builder->offset(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Google, Inc. 2 | # 3 | # This software is provided 'as-is', without any express or implied 4 | # warranty. In no event will the authors be held liable for any damages 5 | # arising from the use of this software. 6 | # Permission is granted to anyone to use this software for any purpose, 7 | # including commercial applications, and to alter it and redistribute it 8 | # freely, subject to the following restrictions: 9 | # 1. The origin of this software must not be misrepresented; you must not 10 | # claim that you wrote the original software. If you use this software 11 | # in a product, an acknowledgment in the product documentation would be 12 | # appreciated but is not required. 13 | # 2. Altered source versions must be plainly marked as such, and must not be 14 | # misrepresented as being the original software. 15 | # 3. This notice may not be removed or altered from any source distribution. 16 | APP_PLATFORM := android-9 17 | APP_PROJECT_PATH := $(call my-dir)/.. 18 | APP_STL ?= stlport_static 19 | APP_ABI := armeabi-v7a 20 | APP_CPPFLAGS += -std=c++11 21 | -------------------------------------------------------------------------------- /samples/android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Google, Inc. 2 | # 3 | # This software is provided 'as-is', without any express or implied 4 | # warranty. In no event will the authors be held liable for any damages 5 | # arising from the use of this software. 6 | # Permission is granted to anyone to use this software for any purpose, 7 | # including commercial applications, and to alter it and redistribute it 8 | # freely, subject to the following restrictions: 9 | # 1. The origin of this software must not be misrepresented; you must not 10 | # claim that you wrote the original software. If you use this software 11 | # in a product, an acknowledgment in the product documentation would be 12 | # appreciated but is not required. 13 | # 2. Altered source versions must be plainly marked as such, and must not be 14 | # misrepresented as being the original software. 15 | # 3. This notice may not be removed or altered from any source distribution. 16 | APP_PLATFORM := android-9 17 | APP_PROJECT_PATH := $(call my-dir)/.. 18 | APP_STL ?= stlport_static 19 | APP_ABI := armeabi-v7a 20 | APP_CPPFLAGS += -std=c++11 21 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | FlatBufferTest 20 | 21 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA.NamespaceB 4 | 5 | import java.nio.* 6 | import kotlin.math.sign 7 | import com.google.flatbuffers.* 8 | 9 | @Suppress("unused") 10 | @ExperimentalUnsignedTypes 11 | class StructInNestedNS : Struct() { 12 | 13 | fun __init(_i: Int, _bb: ByteBuffer) { 14 | __reset(_i, _bb) 15 | } 16 | fun __assign(_i: Int, _bb: ByteBuffer) : StructInNestedNS { 17 | __init(_i, _bb) 18 | return this 19 | } 20 | val a : Int get() = bb.getInt(bb_pos + 0) 21 | fun mutateA(a: Int) : ByteBuffer = bb.putInt(bb_pos + 0, a) 22 | val b : Int get() = bb.getInt(bb_pos + 4) 23 | fun mutateB(b: Int) : ByteBuffer = bb.putInt(bb_pos + 4, b) 24 | companion object { 25 | fun createStructInNestedNS(builder: FlatBufferBuilder, a: Int, b: Int) : Int { 26 | builder.prep(4, 8) 27 | builder.putInt(b) 28 | builder.putInt(a) 29 | return builder.offset() 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | FlatBufferTest 20 | 21 | -------------------------------------------------------------------------------- /reflection/generate_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2016 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | tempDir="../include/flatbuffers/.tmp" 19 | originalFile="../include/flatbuffers/reflection_generated.h" 20 | newFile="$tempDir/reflection_generated.h" 21 | 22 | ../flatc -c --cpp-std c++0x --no-prefix -o $tempDir reflection.fbs 23 | 24 | if [ -f "$newFile" ]; then 25 | if ! cmp -s "$originalFile" "$newFile"; then 26 | mv $newFile $originalFile 27 | else 28 | rm $newFile 29 | fi 30 | rmdir $tempDir 31 | fi 32 | -------------------------------------------------------------------------------- /php/Struct.php: -------------------------------------------------------------------------------- 1 | bb_pos = $pos; 35 | } 36 | 37 | public function setByteBuffer($bb) 38 | { 39 | $this->bb = $bb; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | FlatBufferSample 20 | 21 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Ability.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example 4 | 5 | import java.nio.* 6 | import kotlin.math.sign 7 | import com.google.flatbuffers.* 8 | 9 | @Suppress("unused") 10 | @ExperimentalUnsignedTypes 11 | class Ability : Struct() { 12 | 13 | fun __init(_i: Int, _bb: ByteBuffer) { 14 | __reset(_i, _bb) 15 | } 16 | fun __assign(_i: Int, _bb: ByteBuffer) : Ability { 17 | __init(_i, _bb) 18 | return this 19 | } 20 | val id : UInt get() = bb.getInt(bb_pos + 0).toUInt() 21 | fun mutateId(id: UInt) : ByteBuffer = bb.putInt(bb_pos + 0, id.toInt()) 22 | val distance : UInt get() = bb.getInt(bb_pos + 4).toUInt() 23 | fun mutateDistance(distance: UInt) : ByteBuffer = bb.putInt(bb_pos + 4, distance.toInt()) 24 | companion object { 25 | fun createAbility(builder: FlatBufferBuilder, id: UInt, distance: UInt) : Int { 26 | builder.prep(4, 8) 27 | builder.putInt(distance.toInt()) 28 | builder.putInt(id.toInt()) 29 | return builder.offset() 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/Monster.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example2 4 | 5 | import java.nio.* 6 | import kotlin.math.sign 7 | import com.google.flatbuffers.* 8 | 9 | @Suppress("unused") 10 | @ExperimentalUnsignedTypes 11 | class Monster : Table() { 12 | 13 | fun __init(_i: Int, _bb: ByteBuffer) { 14 | __reset(_i, _bb) 15 | } 16 | fun __assign(_i: Int, _bb: ByteBuffer) : Monster { 17 | __init(_i, _bb) 18 | return this 19 | } 20 | companion object { 21 | fun validateVersion() = Constants.FLATBUFFERS_1_12_0() 22 | fun getRootAsMonster(_bb: ByteBuffer): Monster = getRootAsMonster(_bb, Monster()) 23 | fun getRootAsMonster(_bb: ByteBuffer, obj: Monster): Monster { 24 | _bb.order(ByteOrder.LITTLE_ENDIAN) 25 | return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)) 26 | } 27 | fun startMonster(builder: FlatBufferBuilder) = builder.startTable(0) 28 | fun endMonster(builder: FlatBufferBuilder) : Int { 29 | val o = builder.endTable() 30 | return o 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Referrable.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Referrable = {} -- the module 8 | local Referrable_mt = {} -- the class metatable 9 | 10 | function Referrable.New() 11 | local o = {} 12 | setmetatable(o, {__index = Referrable_mt}) 13 | return o 14 | end 15 | function Referrable.GetRootAsReferrable(buf, offset) 16 | local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) 17 | local o = Referrable.New() 18 | o:Init(buf, n + offset) 19 | return o 20 | end 21 | function Referrable_mt:Init(buf, pos) 22 | self.view = flatbuffers.view.New(buf, pos) 23 | end 24 | function Referrable_mt:Id() 25 | local o = self.view:Offset(4) 26 | if o ~= 0 then 27 | return self.view:Get(flatbuffers.N.Uint64, o + self.view.pos) 28 | end 29 | return 0 30 | end 31 | function Referrable.Start(builder) builder:StartObject(1) end 32 | function Referrable.AddId(builder, id) builder:PrependUint64Slot(0, id, 0) end 33 | function Referrable.End(builder) return builder:EndObject() end 34 | 35 | return Referrable -- return the module -------------------------------------------------------------------------------- /dart/publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2018 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Note to pub consumers: this file is used to assist with publishing the 18 | # pub package from the flatbuffers repository and is not meant for general use. 19 | # As pub does not currently provide a way to exclude files, it is included here. 20 | 21 | command -v pub >/dev/null 2>&1 || { echo >&2 "Require `pub` but it's not installed. Aborting."; exit 1; } 22 | 23 | cp ../samples/monster.fbs example/ 24 | cp ../tests/monster_test.fbs test/ 25 | pub publish 26 | 27 | rm example/monster.fbs 28 | rm test/monster_test.fbs -------------------------------------------------------------------------------- /tests/union_vector/Rapunzel.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | import java.nio.*; 4 | import java.lang.*; 5 | import java.util.*; 6 | import com.google.flatbuffers.*; 7 | 8 | @SuppressWarnings("unused") 9 | public final class Rapunzel extends Struct { 10 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 11 | public Rapunzel __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 12 | 13 | public int hairLength() { return bb.getInt(bb_pos + 0); } 14 | public void mutateHairLength(int hair_length) { bb.putInt(bb_pos + 0, hair_length); } 15 | 16 | public static int createRapunzel(FlatBufferBuilder builder, int hairLength) { 17 | builder.prep(4, 4); 18 | builder.putInt(hairLength); 19 | return builder.offset(); 20 | } 21 | 22 | public static final class Vector extends BaseVector { 23 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 24 | 25 | public Rapunzel get(int j) { return get(new Rapunzel(), j); } 26 | public Rapunzel get(Rapunzel obj, int j) { return obj.__assign(__element(j), bb); } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tests/union_vector/BookReader.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | import java.nio.*; 4 | import java.lang.*; 5 | import java.util.*; 6 | import com.google.flatbuffers.*; 7 | 8 | @SuppressWarnings("unused") 9 | public final class BookReader extends Struct { 10 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 11 | public BookReader __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 12 | 13 | public int booksRead() { return bb.getInt(bb_pos + 0); } 14 | public void mutateBooksRead(int books_read) { bb.putInt(bb_pos + 0, books_read); } 15 | 16 | public static int createBookReader(FlatBufferBuilder builder, int booksRead) { 17 | builder.prep(4, 4); 18 | builder.putInt(booksRead); 19 | return builder.offset(); 20 | } 21 | 22 | public static final class Vector extends BaseVector { 23 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 24 | 25 | public BookReader get(int j) { return get(new BookReader(), j); } 26 | public BookReader get(BookReader obj, int j) { return obj.__assign(__element(j), bb); } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /docs/source/README_TO_GENERATE_DOCS.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | 3 | To generate the docs for FlatBuffers from the source files, you 4 | will first need to install two programs. 5 | 6 | 1. You will need to install `doxygen`. See 7 | [Download Doxygen](http://www.stack.nl/~dimitri/doxygen/download.html). 8 | 9 | 2. You will need to install `doxypypy` to format python comments appropriately. 10 | Install it from [here](https://github.com/Feneric/doxypypy). 11 | 12 | *Note: You will need both `doxygen` and `doxypypy` to be in your 13 | [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable.* 14 | 15 | After you have both of those files installed and in your path, you need to 16 | set up the `py_filter` to invoke `doxypypy` from `doxygen`. 17 | 18 | Follow the steps 19 | [here](https://github.com/Feneric/doxypypy#invoking-doxypypy-from-doxygen). 20 | 21 | ## Generating Docs 22 | 23 | Run the following commands to generate the docs: 24 | 25 | `cd flatbuffers/docs/source` 26 | `doxygen` 27 | 28 | The output is placed in `flatbuffers/docs/html`. 29 | 30 | *Note: The Go API Reference code must be generated ahead of time. For 31 | instructions on how to regenerated this file, please read the comments 32 | in `GoApi.md`.* 33 | -------------------------------------------------------------------------------- /conan/test_package/test_package.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 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 18 | #include 19 | #include "flatbuffers/util.h" 20 | 21 | // Test to validate Conan package generated 22 | 23 | int main(int /*argc*/, const char * /*argv*/ []) { 24 | 25 | const std::string filename("conanbuildinfo.cmake"); 26 | 27 | if (flatbuffers::FileExists(filename.c_str())) { 28 | std::cout << "File " << filename << " exists.\n"; 29 | } else { 30 | std::cout << "File " << filename << " does not exist.\n"; 31 | return EXIT_FAILURE; 32 | } 33 | 34 | return EXIT_SUCCESS; 35 | } 36 | -------------------------------------------------------------------------------- /tests/prototest/test_include.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | include "imported.fbs"; 4 | 5 | namespace proto.test; 6 | 7 | /// Enum doc comment. 8 | enum ProtoEnum : int { 9 | NUL = 0, 10 | FOO = 1, 11 | /// Enum 2nd value doc comment misaligned. 12 | BAR = 5, 13 | } 14 | 15 | /// 2nd table doc comment with 16 | /// many lines. 17 | table ProtoMessage { 18 | c:int = 16; 19 | d:long; 20 | p:uint; 21 | e:ulong; 22 | /// doc comment for f. 23 | f:int = -1; 24 | g:long; 25 | h:uint; 26 | q:ulong; 27 | i:int; 28 | j:long; 29 | /// doc comment for k. 30 | k:bool; 31 | /// doc comment for l on 2 32 | /// lines 33 | l:string (required); 34 | m:[ubyte]; 35 | n:proto.test.ProtoMessage_.OtherMessage; 36 | o:[string]; 37 | z:proto.test.ImportedMessage; 38 | /// doc comment for r. 39 | r:proto.test.ProtoMessage_.Anonymous0; 40 | } 41 | 42 | namespace proto.test.ProtoMessage_; 43 | 44 | table OtherMessage { 45 | a:double; 46 | /// doc comment for b. 47 | b:float = 3.14149; 48 | } 49 | 50 | table Anonymous0 { 51 | /// doc comment for s. 52 | s:proto.test.ImportedMessage; 53 | /// doc comment for t on 2 54 | /// lines. 55 | t:proto.test.ProtoMessage_.OtherMessage; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /tests/prototest/test.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | namespace proto.test; 4 | 5 | /// Enum doc comment. 6 | enum ProtoEnum : int { 7 | NUL = 0, 8 | FOO = 1, 9 | /// Enum 2nd value doc comment misaligned. 10 | BAR = 5, 11 | } 12 | 13 | table ImportedMessage { 14 | a:int; 15 | } 16 | 17 | /// 2nd table doc comment with 18 | /// many lines. 19 | table ProtoMessage { 20 | c:int = 16; 21 | d:long; 22 | p:uint; 23 | e:ulong; 24 | /// doc comment for f. 25 | f:int = -1; 26 | g:long; 27 | h:uint; 28 | q:ulong; 29 | i:int; 30 | j:long; 31 | /// doc comment for k. 32 | k:bool; 33 | /// doc comment for l on 2 34 | /// lines 35 | l:string (required); 36 | m:[ubyte]; 37 | n:proto.test.ProtoMessage_.OtherMessage; 38 | o:[string]; 39 | z:proto.test.ImportedMessage; 40 | /// doc comment for r. 41 | r:proto.test.ProtoMessage_.Anonymous0; 42 | } 43 | 44 | namespace proto.test.ProtoMessage_; 45 | 46 | table OtherMessage { 47 | a:double; 48 | /// doc comment for b. 49 | b:float = 3.14149; 50 | } 51 | 52 | table Anonymous0 { 53 | /// doc comment for s. 54 | s:proto.test.ImportedMessage; 55 | /// doc comment for t on 2 56 | /// lines. 57 | t:proto.test.ProtoMessage_.OtherMessage; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /tests/namespace_test/namespace_test1_generated.lobster: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | import flatbuffers 3 | 4 | namespace NamespaceA_NamespaceB 5 | 6 | enum EnumInNestedNS: 7 | EnumInNestedNS_A = 0 8 | EnumInNestedNS_B = 1 9 | EnumInNestedNS_C = 2 10 | 11 | class TableInNestedNS 12 | 13 | class StructInNestedNS 14 | 15 | class TableInNestedNS : flatbuffers_handle 16 | def foo(): 17 | return buf_.flatbuffers_field_int32(pos_, 4, 0) 18 | 19 | def GetRootAsTableInNestedNS(buf:string): return TableInNestedNS { buf, buf.flatbuffers_indirect(0) } 20 | 21 | struct TableInNestedNSBuilder: 22 | b_:flatbuffers_builder 23 | def start(): 24 | b_.StartObject(1) 25 | return this 26 | def add_foo(foo:int): 27 | b_.PrependInt32Slot(0, foo, 0) 28 | return this 29 | def end(): 30 | return b_.EndObject() 31 | 32 | class StructInNestedNS : flatbuffers_handle 33 | def a(): 34 | return buf_.read_int32_le(pos_ + 0) 35 | def b(): 36 | return buf_.read_int32_le(pos_ + 4) 37 | 38 | def CreateStructInNestedNS(b_:flatbuffers_builder, a:int, b:int): 39 | b_.Prep(4, 8) 40 | b_.PrependInt32(b) 41 | b_.PrependInt32(a) 42 | return b_.Offset() 43 | 44 | -------------------------------------------------------------------------------- /.travis/check-sources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2018 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | if [ -n "$1" ]; then 19 | scan_dir="$1" 20 | else 21 | scan_dir="$( pwd )" 22 | fi 23 | 24 | py_checker="$0.py" 25 | 26 | echo "scan root directory = '$scan_dir'" 27 | python3 --version 28 | # Scan recursively and search all *.cpp and *.h files using regex patterns. 29 | # Assume that script running from a root of Flatbuffers working dir. 30 | python3 $py_checker "ascii" "$scan_dir/include" "\.h$" 31 | python3 $py_checker "ascii" "$scan_dir/src" "\.cpp$" 32 | python3 $py_checker "ascii" "$scan_dir/tests" "\.h$" 33 | python3 $py_checker "utf-8" "$scan_dir/tests" "\.cpp$" 34 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/Lcg.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 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 | namespace FlatBuffers.Test 18 | { 19 | /// 20 | /// Lcg Pseudo RNG 21 | /// 22 | internal sealed class Lcg 23 | { 24 | private const uint InitialValue = 10000; 25 | private uint _state; 26 | 27 | public Lcg() 28 | { 29 | _state = InitialValue; 30 | } 31 | 32 | public uint Next() 33 | { 34 | return (_state = 69069 * _state + 362437); 35 | } 36 | 37 | public void Reset() 38 | { 39 | _state = InitialValue; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /tests/MyGame/InParentNamespace.kt: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame 4 | 5 | import java.nio.* 6 | import kotlin.math.sign 7 | import com.google.flatbuffers.* 8 | 9 | @Suppress("unused") 10 | @ExperimentalUnsignedTypes 11 | class InParentNamespace : Table() { 12 | 13 | fun __init(_i: Int, _bb: ByteBuffer) { 14 | __reset(_i, _bb) 15 | } 16 | fun __assign(_i: Int, _bb: ByteBuffer) : InParentNamespace { 17 | __init(_i, _bb) 18 | return this 19 | } 20 | companion object { 21 | fun validateVersion() = Constants.FLATBUFFERS_1_12_0() 22 | fun getRootAsInParentNamespace(_bb: ByteBuffer): InParentNamespace = getRootAsInParentNamespace(_bb, InParentNamespace()) 23 | fun getRootAsInParentNamespace(_bb: ByteBuffer, obj: InParentNamespace): InParentNamespace { 24 | _bb.order(ByteOrder.LITTLE_ENDIAN) 25 | return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)) 26 | } 27 | fun startInParentNamespace(builder: FlatBufferBuilder) = builder.startTable(0) 28 | fun endInParentNamespace(builder: FlatBufferBuilder) : Int { 29 | val o = builder.endTable() 30 | return o 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: NamespaceB 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local TableInNestedNS = {} -- the module 8 | local TableInNestedNS_mt = {} -- the class metatable 9 | 10 | function TableInNestedNS.New() 11 | local o = {} 12 | setmetatable(o, {__index = TableInNestedNS_mt}) 13 | return o 14 | end 15 | function TableInNestedNS.GetRootAsTableInNestedNS(buf, offset) 16 | local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) 17 | local o = TableInNestedNS.New() 18 | o:Init(buf, n + offset) 19 | return o 20 | end 21 | function TableInNestedNS_mt:Init(buf, pos) 22 | self.view = flatbuffers.view.New(buf, pos) 23 | end 24 | function TableInNestedNS_mt:Foo() 25 | local o = self.view:Offset(4) 26 | if o ~= 0 then 27 | return self.view:Get(flatbuffers.N.Int32, o + self.view.pos) 28 | end 29 | return 0 30 | end 31 | function TableInNestedNS.Start(builder) builder:StartObject(1) end 32 | function TableInNestedNS.AddFoo(builder, foo) builder:PrependInt32Slot(0, foo, 0) end 33 | function TableInNestedNS.End(builder) return builder:EndObject() end 34 | 35 | return TableInNestedNS -- return the module -------------------------------------------------------------------------------- /net/FlatBuffers/Struct.cs: -------------------------------------------------------------------------------- 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 | namespace FlatBuffers 18 | { 19 | /// 20 | /// All structs in the generated code derive from this class, and add their own accessors. 21 | /// 22 | public struct Struct 23 | { 24 | public int bb_pos { get; private set; } 25 | public ByteBuffer bb { get; private set; } 26 | 27 | // Re-init the internal state with an external buffer {@code ByteBuffer} and an offset within. 28 | public Struct(int _i, ByteBuffer _bb) : this() 29 | { 30 | bb = _bb; 31 | bb_pos = _i; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/TestAll.sh: -------------------------------------------------------------------------------- 1 | echo "************************ Java:" 2 | 3 | sh JavaTest.sh 4 | 5 | echo "************************ Kotlin:" 6 | 7 | sh KotlinTest.sh 8 | 9 | echo "************************ Go:" 10 | 11 | sh GoTest.sh 12 | 13 | echo "************************ Python:" 14 | 15 | sh PythonTest.sh 16 | 17 | echo "************************ JavaScript:" 18 | 19 | sh JavaScriptTest.sh 20 | # FIXME does not exist: 21 | # sh JavaScriptUnionVectorTest.sh 22 | 23 | echo "************************ TypeScript:" 24 | 25 | sh TypeScriptTest.sh 26 | 27 | echo "************************ C++:" 28 | 29 | cd .. 30 | ./flattests 31 | cd tests 32 | 33 | echo "************************ C#:" 34 | 35 | cd FlatBuffers.Test 36 | sh NetTest.sh 37 | cd .. 38 | 39 | echo "************************ PHP:" 40 | 41 | php phpTest.php 42 | sh phpUnionVectorTest.sh 43 | 44 | echo "************************ Dart:" 45 | 46 | sh DartTest.sh 47 | 48 | echo "************************ Rust:" 49 | 50 | sh RustTest.sh 51 | 52 | echo "************************ Lobster:" 53 | 54 | # TODO: test if available. 55 | # lobster lobstertest.lobster 56 | 57 | echo "************************ C:" 58 | 59 | echo "(in a different repo)" 60 | 61 | echo "************************ Swift:" 62 | 63 | cd FlatBuffers.Test.Swift 64 | sh SwiftTest.sh 65 | cd .. -------------------------------------------------------------------------------- /samples/android_sample.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2015 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Note: This script requires the Android NDK and Android SDK to be installed. 18 | # It also requires an Android device to be connected for installing and 19 | # running the applicaton. 20 | 21 | sampledir=$(readlink -fn `dirname $0`) 22 | currentdir=$(readlink -fn `pwd`) 23 | 24 | if [[ "$sampledir" != "$currentdir" ]]; then 25 | echo Error: This script must be run from inside the $sampledir directory. 26 | echo You executed it from the $currentdir directory. 27 | exit 1 28 | fi 29 | 30 | # Execute `build_apk.sh` to build and run the android app. 31 | cd android 32 | ./gradlew build 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Ability.php: -------------------------------------------------------------------------------- 1 | bb_pos = $_i; 21 | $this->bb = $_bb; 22 | return $this; 23 | } 24 | 25 | /** 26 | * @return uint 27 | */ 28 | public function GetId() 29 | { 30 | return $this->bb->getUint($this->bb_pos + 0); 31 | } 32 | 33 | /** 34 | * @return uint 35 | */ 36 | public function GetDistance() 37 | { 38 | return $this->bb->getUint($this->bb_pos + 4); 39 | } 40 | 41 | 42 | /** 43 | * @return int offset 44 | */ 45 | public static function createAbility(FlatBufferBuilder $builder, $id, $distance) 46 | { 47 | $builder->prep(4, 8); 48 | $builder->putUint($distance); 49 | $builder->putUint($id); 50 | return $builder->offset(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.php: -------------------------------------------------------------------------------- 1 | bb_pos = $_i; 21 | $this->bb = $_bb; 22 | return $this; 23 | } 24 | 25 | /** 26 | * @return short 27 | */ 28 | public function GetA() 29 | { 30 | return $this->bb->getShort($this->bb_pos + 0); 31 | } 32 | 33 | /** 34 | * @return sbyte 35 | */ 36 | public function GetB() 37 | { 38 | return $this->bb->getSbyte($this->bb_pos + 2); 39 | } 40 | 41 | 42 | /** 43 | * @return int offset 44 | */ 45 | public static function createTest(FlatBufferBuilder $builder, $a, $b) 46 | { 47 | $builder->prep(2, 4); 48 | $builder->pad(1); 49 | $builder->putSbyte($b); 50 | $builder->putShort($a); 51 | return $builder->offset(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /docs/source/GoApi.md: -------------------------------------------------------------------------------- 1 | Go API 2 | ====== 3 | 4 | \addtogroup flatbuffers_go_api 5 | 6 | 26 | \snippet GoApi_generated.txt Go API 27 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/Monster.go: -------------------------------------------------------------------------------- 1 | // Code generated by the FlatBuffers compiler. DO NOT EDIT. 2 | 3 | package Example2 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type MonsterT struct { 10 | } 11 | 12 | func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 13 | if t == nil { return 0 } 14 | MonsterStart(builder) 15 | return MonsterEnd(builder) 16 | } 17 | 18 | func (rcv *Monster) UnPackTo(t *MonsterT) { 19 | } 20 | 21 | func (rcv *Monster) UnPack() *MonsterT { 22 | if rcv == nil { return nil } 23 | t := &MonsterT{} 24 | rcv.UnPackTo(t) 25 | return t 26 | } 27 | 28 | type Monster struct { 29 | _tab flatbuffers.Table 30 | } 31 | 32 | func GetRootAsMonster(buf []byte, offset flatbuffers.UOffsetT) *Monster { 33 | n := flatbuffers.GetUOffsetT(buf[offset:]) 34 | x := &Monster{} 35 | x.Init(buf, n+offset) 36 | return x 37 | } 38 | 39 | func (rcv *Monster) Init(buf []byte, i flatbuffers.UOffsetT) { 40 | rcv._tab.Bytes = buf 41 | rcv._tab.Pos = i 42 | } 43 | 44 | func (rcv *Monster) Table() flatbuffers.Table { 45 | return rcv._tab 46 | } 47 | 48 | func MonsterStart(builder *flatbuffers.Builder) { 49 | builder.StartObject(0) 50 | } 51 | func MonsterEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 52 | return builder.EndObject() 53 | } 54 | -------------------------------------------------------------------------------- /tests/prototest/test_union_include.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | include "imported.fbs"; 4 | 5 | namespace proto.test; 6 | 7 | /// Enum doc comment. 8 | enum ProtoEnum : int { 9 | NUL = 0, 10 | FOO = 1, 11 | /// Enum 2nd value doc comment misaligned. 12 | BAR = 5, 13 | } 14 | 15 | namespace proto.test.ProtoMessage_; 16 | 17 | union RUnion { 18 | /// doc comment for s. 19 | proto.test.ImportedMessage, 20 | /// doc comment for t on 2 21 | /// lines. 22 | proto.test.ProtoMessage_.OtherMessage, 23 | } 24 | 25 | namespace proto.test; 26 | 27 | /// 2nd table doc comment with 28 | /// many lines. 29 | table ProtoMessage { 30 | c:int = 16; 31 | d:long; 32 | p:uint; 33 | e:ulong; 34 | /// doc comment for f. 35 | f:int = -1; 36 | g:long; 37 | h:uint; 38 | q:ulong; 39 | i:int; 40 | j:long; 41 | /// doc comment for k. 42 | k:bool; 43 | /// doc comment for l on 2 44 | /// lines 45 | l:string (required); 46 | m:[ubyte]; 47 | n:proto.test.ProtoMessage_.OtherMessage; 48 | o:[string]; 49 | z:proto.test.ImportedMessage; 50 | /// doc comment for r. 51 | r:proto.test.ProtoMessage_.RUnion; 52 | } 53 | 54 | namespace proto.test.ProtoMessage_; 55 | 56 | table OtherMessage { 57 | a:double; 58 | /// doc comment for b. 59 | b:float = 3.14149; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /tests/prototest/test_union.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | namespace proto.test; 4 | 5 | /// Enum doc comment. 6 | enum ProtoEnum : int { 7 | NUL = 0, 8 | FOO = 1, 9 | /// Enum 2nd value doc comment misaligned. 10 | BAR = 5, 11 | } 12 | 13 | namespace proto.test.ProtoMessage_; 14 | 15 | union RUnion { 16 | /// doc comment for s. 17 | proto.test.ImportedMessage, 18 | /// doc comment for t on 2 19 | /// lines. 20 | proto.test.ProtoMessage_.OtherMessage, 21 | } 22 | 23 | namespace proto.test; 24 | 25 | table ImportedMessage { 26 | a:int; 27 | } 28 | 29 | /// 2nd table doc comment with 30 | /// many lines. 31 | table ProtoMessage { 32 | c:int = 16; 33 | d:long; 34 | p:uint; 35 | e:ulong; 36 | /// doc comment for f. 37 | f:int = -1; 38 | g:long; 39 | h:uint; 40 | q:ulong; 41 | i:int; 42 | j:long; 43 | /// doc comment for k. 44 | k:bool; 45 | /// doc comment for l on 2 46 | /// lines 47 | l:string (required); 48 | m:[ubyte]; 49 | n:proto.test.ProtoMessage_.OtherMessage; 50 | o:[string]; 51 | z:proto.test.ImportedMessage; 52 | /// doc comment for r. 53 | r:proto.test.ProtoMessage_.RUnion; 54 | } 55 | 56 | namespace proto.test.ProtoMessage_; 57 | 58 | table OtherMessage { 59 | a:double; 60 | /// doc comment for b. 61 | b:float = 3.14149; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /go/grpc.go: -------------------------------------------------------------------------------- 1 | package flatbuffers 2 | 3 | // Codec implements gRPC-go Codec which is used to encode and decode messages. 4 | var Codec = "flatbuffers" 5 | 6 | // FlatbuffersCodec defines the interface gRPC uses to encode and decode messages. Note 7 | // that implementations of this interface must be thread safe; a Codec's 8 | // methods can be called from concurrent goroutines. 9 | type FlatbuffersCodec struct{} 10 | 11 | // Marshal returns the wire format of v. 12 | func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) { 13 | return v.(*Builder).FinishedBytes(), nil 14 | } 15 | 16 | // Unmarshal parses the wire format into v. 17 | func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error { 18 | v.(flatbuffersInit).Init(data, GetUOffsetT(data)) 19 | return nil 20 | } 21 | 22 | // String old gRPC Codec interface func 23 | func (FlatbuffersCodec) String() string { 24 | return Codec 25 | } 26 | 27 | // Name returns the name of the Codec implementation. The returned string 28 | // will be used as part of content type in transmission. The result must be 29 | // static; the result cannot change between calls. 30 | // 31 | // add Name() for ForceCodec interface 32 | func (FlatbuffersCodec) Name() string { 33 | return Codec 34 | } 35 | 36 | type flatbuffersInit interface { 37 | Init(data []byte, i UOffsetT) 38 | } 39 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Test extends Struct { 12 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 13 | public Test __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 14 | 15 | public short a() { return bb.getShort(bb_pos + 0); } 16 | public void mutateA(short a) { bb.putShort(bb_pos + 0, a); } 17 | public byte b() { return bb.get(bb_pos + 2); } 18 | public void mutateB(byte b) { bb.put(bb_pos + 2, b); } 19 | 20 | public static int createTest(FlatBufferBuilder builder, short a, byte b) { 21 | builder.prep(2, 4); 22 | builder.pad(1); 23 | builder.putByte(b); 24 | builder.putShort(a); 25 | return builder.offset(); 26 | } 27 | 28 | public static final class Vector extends BaseVector { 29 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 30 | 31 | public Test get(int j) { return get(new Test(), j); } 32 | public Test get(Test obj, int j) { return obj.__assign(__element(j), bb); } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.php: -------------------------------------------------------------------------------- 1 | bb_pos = $_i; 21 | $this->bb = $_bb; 22 | return $this; 23 | } 24 | 25 | /** 26 | * @return int 27 | */ 28 | public function GetA() 29 | { 30 | return $this->bb->getInt($this->bb_pos + 0); 31 | } 32 | 33 | /** 34 | * @return int 35 | */ 36 | public function GetB() 37 | { 38 | return $this->bb->getInt($this->bb_pos + 4); 39 | } 40 | 41 | 42 | /** 43 | * @return int offset 44 | */ 45 | public static function createStructInNestedNS(FlatBufferBuilder $builder, $a, $b) 46 | { 47 | $builder->prep(4, 8); 48 | $builder->putInt($b); 49 | $builder->putInt($a); 50 | return $builder->offset(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.travis/check-sources.sh.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import sys 4 | 5 | def check_encoding(encoding, scan_dir, regex_pattern): 6 | fname = None 7 | try: 8 | assert encoding in ['ascii', 'utf-8'], "unexpected encoding" 9 | cmp = re.compile(regex_pattern) 10 | for root, dirs, files in os.walk(scan_dir): 11 | fname = root 12 | cmp_list = [f for f in files if cmp.search(f) is not None] 13 | for f in cmp_list: 14 | fname = os.path.join(root, f) 15 | with open(fname, mode='rb') as test_file: 16 | btext = test_file.read() 17 | # check encoding 18 | btext.decode(encoding=encoding, errors="strict") 19 | if encoding == "utf-8" and btext.startswith(b'\xEF\xBB\xBF'): 20 | raise ValueError("unexpected BOM in file") 21 | # check LF line endings 22 | LF = btext.count(b'\n') 23 | CR = btext.count(b'\r') 24 | if CR!=0: 25 | raise ValueError("invalid line endings: LF({})/CR({})".format(LF, CR)) 26 | except Exception as err: 27 | print("ERROR with [{}]: {}".format(fname, err)) 28 | return -1 29 | else: 30 | return 0 31 | 32 | if __name__ == "__main__": 33 | # python check-sources.sh.py 'ascii' '.' '.*\.(cpp|h)$' 34 | res = check_encoding(sys.argv[1], sys.argv[2], sys.argv[3]) 35 | sys.exit(0 if res == 0 else -1) 36 | -------------------------------------------------------------------------------- /python/flatbuffers/packer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 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 | """ 16 | Provide pre-compiled struct packers for encoding and decoding. 17 | 18 | See: https://docs.python.org/2/library/struct.html#format-characters 19 | """ 20 | 21 | import struct 22 | from . import compat 23 | 24 | 25 | boolean = struct.Struct(compat.struct_bool_decl) 26 | 27 | uint8 = struct.Struct(" 22 | /// Class that collects utility functions around `ByteBuffer`. 23 | /// 24 | public class ByteBufferUtil 25 | { 26 | // Extract the size prefix from a `ByteBuffer`. 27 | public static int GetSizePrefix(ByteBuffer bb) { 28 | return bb.GetInt(bb.Position); 29 | } 30 | 31 | // Create a duplicate of a size-prefixed `ByteBuffer` that has its position 32 | // advanced just past the size prefix. 33 | public static ByteBuffer RemoveSizePrefix(ByteBuffer bb) { 34 | ByteBuffer s = bb.Duplicate(); 35 | s.Position += FlatBufferConstants.SizePrefixLength; 36 | return s; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/prototest/test_suffix.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | namespace proto.test.test_namespace_suffix; 4 | 5 | /// Enum doc comment. 6 | enum ProtoEnum : int { 7 | NUL = 0, 8 | FOO = 1, 9 | /// Enum 2nd value doc comment misaligned. 10 | BAR = 5, 11 | } 12 | 13 | table ImportedMessage { 14 | a:int; 15 | } 16 | 17 | /// 2nd table doc comment with 18 | /// many lines. 19 | table ProtoMessage { 20 | c:int = 16; 21 | d:long; 22 | p:uint; 23 | e:ulong; 24 | /// doc comment for f. 25 | f:int = -1; 26 | g:long; 27 | h:uint; 28 | q:ulong; 29 | i:int; 30 | j:long; 31 | /// doc comment for k. 32 | k:bool; 33 | /// doc comment for l on 2 34 | /// lines 35 | l:string (required); 36 | m:[ubyte]; 37 | n:proto.test.test_namespace_suffix.ProtoMessage_.OtherMessage; 38 | o:[string]; 39 | z:proto.test.test_namespace_suffix.ImportedMessage; 40 | /// doc comment for r. 41 | r:proto.test.test_namespace_suffix.ProtoMessage_.Anonymous0; 42 | } 43 | 44 | namespace proto.test.test_namespace_suffix.ProtoMessage_; 45 | 46 | table OtherMessage { 47 | a:double; 48 | /// doc comment for b. 49 | b:float = 3.14149; 50 | } 51 | 52 | table Anonymous0 { 53 | /// doc comment for s. 54 | s:proto.test.test_namespace_suffix.ImportedMessage; 55 | /// doc comment for t on 2 56 | /// lines. 57 | t:proto.test.test_namespace_suffix.ProtoMessage_.OtherMessage; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /samples/lua/MyGame/Sample/Weapon.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Sample 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Weapon = {} -- the module 8 | local Weapon_mt = {} -- the class metatable 9 | 10 | function Weapon.New() 11 | local o = {} 12 | setmetatable(o, {__index = Weapon_mt}) 13 | return o 14 | end 15 | function Weapon.GetRootAsWeapon(buf, offset) 16 | local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) 17 | local o = Weapon.New() 18 | o:Init(buf, n + offset) 19 | return o 20 | end 21 | function Weapon_mt:Init(buf, pos) 22 | self.view = flatbuffers.view.New(buf, pos) 23 | end 24 | function Weapon_mt:Name() 25 | local o = self.view:Offset(4) 26 | if o ~= 0 then 27 | return self.view:String(o + self.view.pos) 28 | end 29 | end 30 | function Weapon_mt:Damage() 31 | local o = self.view:Offset(6) 32 | if o ~= 0 then 33 | return self.view:Get(flatbuffers.N.Int16, o + self.view.pos) 34 | end 35 | return 0 36 | end 37 | function Weapon.Start(builder) builder:StartObject(2) end 38 | function Weapon.AddName(builder, name) builder:PrependUOffsetTRelativeSlot(0, name, 0) end 39 | function Weapon.AddDamage(builder, damage) builder:PrependInt16Slot(1, damage, 0) end 40 | function Weapon.End(builder) return builder:EndObject() end 41 | 42 | return Weapon -- return the module -------------------------------------------------------------------------------- /tests/JavaTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2014 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -o errexit 18 | 19 | echo Compile then run the Java test. 20 | 21 | java -version 22 | 23 | testdir=$(dirname $0) 24 | 25 | targetdir="${testdir}/target" 26 | 27 | if [[ -e "${targetdir}" ]]; then 28 | echo "cleaning target" 29 | rm -rf "${targetdir}" 30 | fi 31 | 32 | mkdir -v "${targetdir}" 33 | 34 | if ! find "${testdir}/../java" -type f -name "*.class" -delete; then 35 | echo "failed to clean .class files from java directory" >&2 36 | exit 1 37 | fi 38 | 39 | javac -d "${targetdir}" -classpath "${testdir}/../java:${testdir}:${testdir}/namespace_test:${testdir}/union_vector" "${testdir}/JavaTest.java" 40 | 41 | (cd "${testdir}" && java -classpath "${targetdir}" JavaTest ) 42 | 43 | rm -rf "${targetdir}" 44 | -------------------------------------------------------------------------------- /net/FlatBuffers/Offset.cs: -------------------------------------------------------------------------------- 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 | namespace FlatBuffers 18 | { 19 | /// 20 | /// Offset class for typesafe assignments. 21 | /// 22 | public struct Offset where T : struct 23 | { 24 | public int Value; 25 | public Offset(int value) 26 | { 27 | Value = value; 28 | } 29 | } 30 | 31 | public struct StringOffset 32 | { 33 | public int Value; 34 | public StringOffset(int value) 35 | { 36 | Value = value; 37 | } 38 | } 39 | 40 | public struct VectorOffset 41 | { 42 | public int Value; 43 | public VectorOffset(int value) 44 | { 45 | Value = value; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/DartTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2016 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | pushd "$(dirname $0)" >/dev/null 18 | 19 | command -v pub >/dev/null 2>&1 || { echo >&2 "Dart tests require `pub` but it's not installed. Aborting."; exit 1; } 20 | command -v dart >/dev/null 2>&1 || { echo >&2 "Dart tests require dart to be in path but it's not installed. Aborting."; exit 1; } 21 | # output required files to the dart folder so that pub will be able to 22 | # distribute them and more people can more easily run the dart tests 23 | ../flatc --dart -I include_test -o ../dart/test monster_test.fbs 24 | cp monsterdata_test.mon ../dart/test 25 | 26 | cd ../dart 27 | 28 | # update packages 29 | pub get 30 | # Execute the sample. 31 | dart test/flat_buffers_test.dart 32 | 33 | # cleanup 34 | rm ../dart/test/monsterdata_test.mon 35 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA.NamespaceB; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class StructInNestedNS extends Struct { 12 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 13 | public StructInNestedNS __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 14 | 15 | public int a() { return bb.getInt(bb_pos + 0); } 16 | public void mutateA(int a) { bb.putInt(bb_pos + 0, a); } 17 | public int b() { return bb.getInt(bb_pos + 4); } 18 | public void mutateB(int b) { bb.putInt(bb_pos + 4, b); } 19 | 20 | public static int createStructInNestedNS(FlatBufferBuilder builder, int a, int b) { 21 | builder.prep(4, 8); 22 | builder.putInt(b); 23 | builder.putInt(a); 24 | return builder.offset(); 25 | } 26 | 27 | public static final class Vector extends BaseVector { 28 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 29 | 30 | public StructInNestedNS get(int j) { return get(new StructInNestedNS(), j); } 31 | public StructInNestedNS get(StructInNestedNS obj, int j) { return obj.__assign(__element(j), bb); } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Ability.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Ability extends Struct { 12 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 13 | public Ability __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 14 | 15 | public long id() { return (long)bb.getInt(bb_pos + 0) & 0xFFFFFFFFL; } 16 | public void mutateId(long id) { bb.putInt(bb_pos + 0, (int)id); } 17 | public long distance() { return (long)bb.getInt(bb_pos + 4) & 0xFFFFFFFFL; } 18 | public void mutateDistance(long distance) { bb.putInt(bb_pos + 4, (int)distance); } 19 | 20 | public static int createAbility(FlatBufferBuilder builder, long id, long distance) { 21 | builder.prep(4, 8); 22 | builder.putInt((int)distance); 23 | builder.putInt((int)id); 24 | return builder.offset(); 25 | } 26 | 27 | public static final class Vector extends BaseVector { 28 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 29 | 30 | public Ability get(int j) { return get(new Ability(), j); } 31 | public Ability get(Ability obj, int j) { return obj.__assign(__element(j), bb); } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /grpc/src/compiler/python_generator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | #ifndef GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H 20 | #define GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H 21 | 22 | #include 23 | 24 | #include "src/compiler/schema_interface.h" 25 | 26 | namespace grpc_python_generator { 27 | 28 | // Data pertaining to configuration of the generator with respect to anything 29 | // that may be used internally at Google. 30 | struct GeneratorConfiguration { 31 | grpc::string grpc_package_root; 32 | // TODO(https://github.com/grpc/grpc/issues/8622): Drop this. 33 | grpc::string beta_package_root; 34 | // TODO(https://github.com/google/protobuf/issues/888): Drop this. 35 | grpc::string import_prefix; 36 | }; 37 | 38 | } // namespace grpc_python_generator 39 | 40 | #endif // GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H 41 | -------------------------------------------------------------------------------- /tests/MyGame/InParentNamespace.go: -------------------------------------------------------------------------------- 1 | // Code generated by the FlatBuffers compiler. DO NOT EDIT. 2 | 3 | package MyGame 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type InParentNamespaceT struct { 10 | } 11 | 12 | func (t *InParentNamespaceT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 13 | if t == nil { return 0 } 14 | InParentNamespaceStart(builder) 15 | return InParentNamespaceEnd(builder) 16 | } 17 | 18 | func (rcv *InParentNamespace) UnPackTo(t *InParentNamespaceT) { 19 | } 20 | 21 | func (rcv *InParentNamespace) UnPack() *InParentNamespaceT { 22 | if rcv == nil { return nil } 23 | t := &InParentNamespaceT{} 24 | rcv.UnPackTo(t) 25 | return t 26 | } 27 | 28 | type InParentNamespace struct { 29 | _tab flatbuffers.Table 30 | } 31 | 32 | func GetRootAsInParentNamespace(buf []byte, offset flatbuffers.UOffsetT) *InParentNamespace { 33 | n := flatbuffers.GetUOffsetT(buf[offset:]) 34 | x := &InParentNamespace{} 35 | x.Init(buf, n+offset) 36 | return x 37 | } 38 | 39 | func (rcv *InParentNamespace) Init(buf []byte, i flatbuffers.UOffsetT) { 40 | rcv._tab.Bytes = buf 41 | rcv._tab.Pos = i 42 | } 43 | 44 | func (rcv *InParentNamespace) Table() flatbuffers.Table { 45 | return rcv._tab 46 | } 47 | 48 | func InParentNamespaceStart(builder *flatbuffers.Builder) { 49 | builder.StartObject(0) 50 | } 51 | func InParentNamespaceEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 52 | return builder.EndObject() 53 | } 54 | -------------------------------------------------------------------------------- /.travis/check-generate-code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2018 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | cd tests 19 | ./generate_code.sh 20 | cd .. 21 | 22 | # TODO: Linux and macos builds produce differences here for some reason. 23 | git checkout HEAD -- tests/monster_test.bfbs 24 | git checkout HEAD -- tests/arrays_test.bfbs 25 | git checkout HEAD -- samples/monster.bfbs 26 | 27 | if ! git diff --quiet; then 28 | echo >&2 29 | echo "ERROR: ********************************************************" >&2 30 | echo "ERROR: The following differences were found after running the" >&2 31 | echo "ERROR: tests/generate_code.sh script. Maybe you forgot to run" >&2 32 | echo "ERROR: it after making changes in a generator or schema?" >&2 33 | echo "ERROR: ********************************************************" >&2 34 | echo >&2 35 | git diff --binary --exit-code 36 | fi 37 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/Monster.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example2; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class Monster extends Table { 12 | public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); } 13 | public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); } 14 | public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 15 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 16 | public Monster __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 17 | 18 | 19 | public static void startMonster(FlatBufferBuilder builder) { builder.startTable(0); } 20 | public static int endMonster(FlatBufferBuilder builder) { 21 | int o = builder.endTable(); 22 | return o; 23 | } 24 | 25 | public static final class Vector extends BaseVector { 26 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 27 | 28 | public Monster get(int j) { return get(new Monster(), j); } 29 | public Monster get(Monster obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /tests/RustTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | # 4 | # Copyright 2018 Google Inc. All rights reserved. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | if [[ "$1" == "mips-unknown-linux-gnu" ]]; then 19 | TARGET_FLAG="--target mips-unknown-linux-gnu" 20 | export CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc 21 | export CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu" 22 | fi 23 | 24 | cd ./rust_usage_test 25 | cargo test $TARGET_FLAG -- --quiet 26 | TEST_RESULT=$? 27 | if [[ $TEST_RESULT == 0 ]]; then 28 | echo "OK: Rust tests passed." 29 | else 30 | echo "KO: Rust tests failed." 31 | exit 1 32 | fi 33 | 34 | cargo run $TARGET_FLAG --bin=alloc_check 35 | TEST_RESULT=$? 36 | if [[ $TEST_RESULT == 0 ]]; then 37 | echo "OK: Rust heap alloc test passed." 38 | else 39 | echo "KO: Rust heap alloc test failed." 40 | exit 1 41 | fi 42 | 43 | cargo bench $TARGET_FLAG 44 | -------------------------------------------------------------------------------- /tests/monsterdata_test.golden: -------------------------------------------------------------------------------- 1 | { 2 | pos: { 3 | x: 1.0, 4 | y: 2.0, 5 | z: 3.0, 6 | test1: 3.14159265359, 7 | test2: "Green", 8 | test3: { 9 | a: 10, 10 | b: 20 11 | } 12 | }, 13 | hp: 80, 14 | name: "MyMonster", 15 | inventory: [ 16 | 0, 17 | 1, 18 | 2, 19 | 3, 20 | 4, 21 | 5, 22 | 6, 23 | 7, 24 | 8, 25 | 9 26 | ], 27 | test_type: "Monster", 28 | test: { 29 | name: "Fred" 30 | }, 31 | test4: [ 32 | { 33 | a: 10, 34 | b: 20 35 | }, 36 | { 37 | a: 30, 38 | b: 40 39 | } 40 | ], 41 | testarrayofstring: [ 42 | "bob", 43 | "fred", 44 | "bob", 45 | "fred" 46 | ], 47 | testarrayoftables: [ 48 | { 49 | hp: 1000, 50 | name: "Barney" 51 | }, 52 | { 53 | name: "Fred" 54 | }, 55 | { 56 | name: "Wilma" 57 | } 58 | ], 59 | testnestedflatbuffer: { 60 | name: "NestedMonster" 61 | }, 62 | testbool: true, 63 | testhashs32_fnv1: -579221183, 64 | testhashu32_fnv1: 3715746113, 65 | testhashs64_fnv1: 7930699090847568257, 66 | testhashu64_fnv1: 7930699090847568257, 67 | testhashs32_fnv1a: -1904106383, 68 | testhashu32_fnv1a: 2390860913, 69 | testhashs64_fnv1a: 4898026182817603057, 70 | testhashu64_fnv1a: 4898026182817603057, 71 | flex: 1234, 72 | test5: [ 73 | { 74 | a: 10, 75 | b: 20 76 | }, 77 | { 78 | a: 30, 79 | b: 40 80 | } 81 | ] 82 | } 83 | -------------------------------------------------------------------------------- /grpc/README.md: -------------------------------------------------------------------------------- 1 | GRPC implementation and test 2 | ============================ 3 | 4 | NOTE: files in `src/` are shared with the GRPC project, and maintained there 5 | (any changes should be submitted to GRPC instead). These files are copied 6 | from GRPC, and work with both the Protobuf and FlatBuffers code generator. 7 | 8 | `tests/` contains a GRPC specific test, you need to have built and installed 9 | the GRPC libraries for this to compile. This test will build using the 10 | `FLATBUFFERS_BUILD_GRPCTEST` option to the main FlatBuffers CMake project. 11 | 12 | ## Building Flatbuffers with gRPC 13 | 14 | ### Linux 15 | 16 | 1. Download, build and install gRPC. See [instructions](https://github.com/grpc/grpc/tree/master/src/cpp). 17 | * Lets say your gRPC clone is at `/your/path/to/grpc_repo`. 18 | * Install gRPC in a custom directory by running `make install prefix=/your/path/to/grpc_repo/install`. 19 | 2. `export GRPC_INSTALL_PATH=/your/path/to/grpc_repo/install` 20 | 3. `export PROTOBUF_DOWNLOAD_PATH=/your/path/to/grpc_repo/third_party/protobuf` 21 | 4. `mkdir build ; cd build` 22 | 5. `cmake -DFLATBUFFERS_BUILD_GRPCTEST=ON -DGRPC_INSTALL_PATH=${GRPC_INSTALL_PATH} -DPROTOBUF_DOWNLOAD_PATH=${PROTOBUF_DOWNLOAD_PATH} ..` 23 | 6. `make` 24 | 25 | ## Running FlatBuffer gRPC tests 26 | 27 | ### Linux 28 | 29 | 1. `ln -s ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.6 ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1` 30 | 2. `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GRPC_INSTALL_PATH}/lib` 31 | 3. `make test ARGS=-V` 32 | -------------------------------------------------------------------------------- /tests/prototest/test_union_suffix.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | namespace proto.test.test_namespace_suffix; 4 | 5 | /// Enum doc comment. 6 | enum ProtoEnum : int { 7 | NUL = 0, 8 | FOO = 1, 9 | /// Enum 2nd value doc comment misaligned. 10 | BAR = 5, 11 | } 12 | 13 | namespace proto.test.test_namespace_suffix.ProtoMessage_; 14 | 15 | union RUnion { 16 | /// doc comment for s. 17 | proto.test.test_namespace_suffix.ImportedMessage, 18 | /// doc comment for t on 2 19 | /// lines. 20 | proto.test.test_namespace_suffix.ProtoMessage_.OtherMessage, 21 | } 22 | 23 | namespace proto.test.test_namespace_suffix; 24 | 25 | table ImportedMessage { 26 | a:int; 27 | } 28 | 29 | /// 2nd table doc comment with 30 | /// many lines. 31 | table ProtoMessage { 32 | c:int = 16; 33 | d:long; 34 | p:uint; 35 | e:ulong; 36 | /// doc comment for f. 37 | f:int = -1; 38 | g:long; 39 | h:uint; 40 | q:ulong; 41 | i:int; 42 | j:long; 43 | /// doc comment for k. 44 | k:bool; 45 | /// doc comment for l on 2 46 | /// lines 47 | l:string (required); 48 | m:[ubyte]; 49 | n:proto.test.test_namespace_suffix.ProtoMessage_.OtherMessage; 50 | o:[string]; 51 | z:proto.test.test_namespace_suffix.ImportedMessage; 52 | /// doc comment for r. 53 | r:proto.test.test_namespace_suffix.ProtoMessage_.RUnion; 54 | } 55 | 56 | namespace proto.test.test_namespace_suffix.ProtoMessage_; 57 | 58 | table OtherMessage { 59 | a:double; 60 | /// doc comment for b. 61 | b:float = 3.14149; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /tests/TypeScriptTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2016 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | pushd "$(dirname $0)" >/dev/null 18 | 19 | npm install @types/flatbuffers 20 | 21 | ../flatc --ts --no-fb-import --gen-mutable -o ts -I include_test monster_test.fbs 22 | ../flatc -b -I include_test monster_test.fbs unicode_test.json 23 | tsc --strict --noUnusedParameters --noUnusedLocals --noImplicitReturns --strictNullChecks ts/monster_test_generated.ts 24 | node JavaScriptTest ./ts/monster_test_generated 25 | 26 | ../flatc --ts --js --no-fb-import -o ts union_vector/union_vector.fbs 27 | 28 | # test JS version first, then transpile and rerun for TS 29 | node JavaScriptUnionVectorTest ./ts/union_vector_generated 30 | tsc --strict --noUnusedParameters --noUnusedLocals --noImplicitReturns --strictNullChecks ts/union_vector_generated.ts 31 | node JavaScriptUnionVectorTest ./ts/union_vector_generated 32 | 33 | npm uninstall @types/flatbuffers 34 | -------------------------------------------------------------------------------- /net/FlatBuffers/FlatBufferConstants.cs: -------------------------------------------------------------------------------- 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 | using System; 18 | using System.Collections.Generic; 19 | using System.Linq; 20 | using System.Text; 21 | 22 | namespace FlatBuffers 23 | { 24 | public static class FlatBufferConstants 25 | { 26 | public const int FileIdentifierLength = 4; 27 | public const int SizePrefixLength = 4; 28 | /** A version identifier to force a compile error if someone 29 | accidentally tries to build generated code with a runtime of 30 | two mismatched version. Versions need to always match, as 31 | the runtime and generated code are modified in sync. 32 | Changes to the C# implementation need to be sure to change 33 | the version here and in the code generator on every possible 34 | incompatible change */ 35 | public static void FLATBUFFERS_1_12_0() {} 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInC.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: NamespaceA 4 | 5 | import flatbuffers 6 | 7 | class TableInC(object): 8 | __slots__ = ['_tab'] 9 | 10 | # TableInC 11 | def Init(self, buf, pos): 12 | self._tab = flatbuffers.table.Table(buf, pos) 13 | 14 | # TableInC 15 | def ReferToA1(self): 16 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 17 | if o != 0: 18 | x = self._tab.Indirect(o + self._tab.Pos) 19 | from .TableInFirstNS import TableInFirstNS 20 | obj = TableInFirstNS() 21 | obj.Init(self._tab.Bytes, x) 22 | return obj 23 | return None 24 | 25 | # TableInC 26 | def ReferToA2(self): 27 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 28 | if o != 0: 29 | x = self._tab.Indirect(o + self._tab.Pos) 30 | from .SecondTableInA import SecondTableInA 31 | obj = SecondTableInA() 32 | obj.Init(self._tab.Bytes, x) 33 | return obj 34 | return None 35 | 36 | def TableInCStart(builder): builder.StartObject(2) 37 | def TableInCAddReferToA1(builder, referToA1): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(referToA1), 0) 38 | def TableInCAddReferToA2(builder, referToA2): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(referToA2), 0) 39 | def TableInCEnd(builder): return builder.EndObject() 40 | -------------------------------------------------------------------------------- /tests/monsterdata_test.json: -------------------------------------------------------------------------------- 1 | { 2 | pos: { 3 | x: 1, 4 | y: "2", 5 | z: 3, 6 | test1: 3, 7 | test2: "Green", 8 | test3: { 9 | a: 5, 10 | b: 6 11 | } 12 | }, 13 | hp: 80, 14 | name: "MyMonster", 15 | inventory: [ 16 | 0, 17 | 1, 18 | 2, 19 | 3, 20 | 4 21 | ], 22 | vector_of_longs: [ 23 | 1, 24 | 100, 25 | 10000, 26 | 1000000, 27 | 100000000 28 | ], 29 | vector_of_doubles: [ 30 | -1.7976931348623157e+308, 31 | 0, 32 | 1.7976931348623157e+308 33 | ], 34 | test_type: "Monster", 35 | test: { 36 | name: "Fred", 37 | pos: null 38 | }, 39 | test4: [ 40 | { 41 | a: 10, 42 | b: 20 43 | }, 44 | { 45 | b: "40", 46 | a: 30 47 | } 48 | ], 49 | test5: [ 50 | { 51 | a: 10, 52 | b: 20 53 | }, 54 | { 55 | b: "40", 56 | a: 30 57 | } 58 | ], 59 | testarrayofstring: [ 60 | "test1", 61 | "test2" 62 | ], 63 | enemy: { 64 | name: "Fred" 65 | }, 66 | testarrayofbools:[ 67 | true, false, true 68 | ], 69 | testbool: true, 70 | testhashs32_fnv1: "This string is being hashed!", 71 | testhashu32_fnv1: "This string is being hashed!", 72 | testhashs64_fnv1: "This string is being hashed!", 73 | testhashu64_fnv1: "This string is being hashed!", 74 | testhashs32_fnv1a: "This string is being hashed!", 75 | testhashu32_fnv1a: "This string is being hashed!", 76 | testhashs64_fnv1a: "This string is being hashed!", 77 | testhashu64_fnv1a: "This string is being hashed!", 78 | } 79 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInC.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | type TableInC struct { 9 | _tab flatbuffers.Table 10 | } 11 | 12 | func (rcv *TableInC) Init(buf []byte, i flatbuffers.UOffsetT) { 13 | rcv._tab.Bytes = buf 14 | rcv._tab.Pos = i 15 | } 16 | 17 | func (rcv *TableInC) ReferToA1(obj *TableInFirstNS) *TableInFirstNS { 18 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 19 | if o != 0 { 20 | x := rcv._tab.Indirect(o + rcv._tab.Pos) 21 | if obj == nil { 22 | obj = new(TableInFirstNS) 23 | } 24 | obj.Init(rcv._tab.Bytes, x) 25 | return obj 26 | } 27 | return nil 28 | } 29 | 30 | func (rcv *TableInC) ReferToA2(obj *SecondTableInA) *SecondTableInA { 31 | o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) 32 | if o != 0 { 33 | x := rcv._tab.Indirect(o + rcv._tab.Pos) 34 | if obj == nil { 35 | obj = new(SecondTableInA) 36 | } 37 | obj.Init(rcv._tab.Bytes, x) 38 | return obj 39 | } 40 | return nil 41 | } 42 | 43 | func TableInCStart(builder *flatbuffers.Builder) { builder.StartObject(2) } 44 | func TableInCAddReferToA1(builder *flatbuffers.Builder, referToA1 flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(referToA1), 0) } 45 | func TableInCAddReferToA2(builder *flatbuffers.Builder, referToA2 flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(referToA2), 0) } 46 | func TableInCEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } 47 | -------------------------------------------------------------------------------- /tests/KotlinTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2014 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | echo Compile then run the Kotlin test. 18 | 19 | testdir=$(dirname $0) 20 | targetdir="${testdir}/kotlin" 21 | 22 | if [[ -e "${targetdir}" ]]; then 23 | echo "cleaning target" 24 | rm -rf "${targetdir}" 25 | fi 26 | 27 | mkdir -v "${targetdir}" 28 | 29 | if ! find "${testdir}/../java" -type f -name "*.class" -delete; then 30 | echo "failed to clean .class files from java directory" >&2 31 | exit 1 32 | fi 33 | 34 | all_kt_files=`find . -name "*.kt" -print` 35 | 36 | # Compile java FlatBuffer library 37 | javac ${testdir}/../java/com/google/flatbuffers/*.java -d $targetdir 38 | # Compile Kotlin files 39 | kotlinc $all_kt_files -classpath $targetdir -include-runtime -d $targetdir 40 | # Make jar 41 | jar cvf ${testdir}/kotlin_test.jar -C $targetdir . > /dev/null 42 | # Run test 43 | kotlin -cp ${testdir}/kotlin_test.jar KotlinTest 44 | # clean up 45 | rm -rf $targetdir 46 | rm ${testdir}/kotlin_test.jar 47 | -------------------------------------------------------------------------------- /CMake/PackageRedhat.cmake: -------------------------------------------------------------------------------- 1 | if (UNIX) 2 | set(CPACK_GENERATOR "RPM") 3 | set(CPACK_SOURCE_TGZ "ON") 4 | 5 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "FlatBuffers serialization library and schema compiler.") 6 | 7 | set(CPACK_RPM_PACKAGE_HOMEPAGE "https://github.com/google/flatbuffers") 8 | set(CPACK_RPM_PACKAGE_MAINTAINER "Marc Butler ") 9 | 10 | set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) 11 | set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) 12 | set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) 13 | set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_COMMIT}") 14 | set(CPACK_RPM_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}") 15 | 16 | set(CPACK_RPM_PACKAGE_NAME "flatbuffers") 17 | 18 | # Assume this is not a cross complation build. 19 | if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE) 20 | set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}") 21 | endif(NOT CPACK_RPM_PACKAGE_ARCHITECTURE) 22 | 23 | set(CPACK_RPM_PACKAGE_VENDOR "Google, Inc.") 24 | set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0") 25 | set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt) 26 | set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/CMake/DESCRIPTION.txt) 27 | 28 | # This may reduce rpm compatiblity with very old systems. 29 | set(CPACK_RPM_COMPRESSION_TYPE lzma) 30 | 31 | set(CPACK_RPM_PACKAGE_NAME "flatbuffers") 32 | set(CPACK_PACKAGE_FILE_NAME 33 | "${CPACK_RPM_PACKAGE_NAME}_${CPACK_RPM_PACKAGE_VERSION}_${CPACK_RPM_PACKAGE_ARCHITECTURE}") 34 | endif(UNIX) 35 | -------------------------------------------------------------------------------- /samples/sample_text.lobster: -------------------------------------------------------------------------------- 1 | // Copyright 2018 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 | import from "../lobster/" 16 | import monster_generated 17 | 18 | // Example how to interop with JSON. 19 | 20 | // Test loading some JSON, converting it to a binary FlatBuffer and back again. 21 | 22 | // First read the schema and JSON data. 23 | let schema = read_file("monster.fbs", true) 24 | let json = read_file("monsterdata.json", true) 25 | assert schema and json 26 | 27 | // Parse JSON to binary: 28 | let fb, err1 = flatbuffers_json_to_binary(schema, json, []) 29 | assert not err1 30 | 31 | // Access one field in it, just to check: 32 | let monster = MyGame_Sample_GetRootAsMonster(fb) 33 | assert monster.name == "Orc" 34 | 35 | // Convert binary back to JSON: 36 | let json2, err2 = flatbuffers_binary_to_json(schema, fb, []) 37 | assert not err2 38 | 39 | // The generated JSON should be exactly equal to the original! 40 | assert json == json2 41 | 42 | // Print what we've been converting for good measure: 43 | print json 44 | -------------------------------------------------------------------------------- /tests/FlatBuffers.GRPC.Swift/Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "FlatBuffers.GRPC.Swift", 8 | platforms: [ 9 | .iOS(.v11), 10 | .macOS(.v10_14), 11 | ], 12 | dependencies: [ 13 | // Main SwiftNIO package 14 | .package(path: "../../swift"), 15 | .package(url: "https://github.com/grpc/grpc-swift.git", .branch("nio")) 16 | ], 17 | targets: [ 18 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 19 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 20 | .target( 21 | name: "Model", 22 | dependencies: [ 23 | "GRPC", 24 | "FlatBuffers" 25 | ], 26 | path: "Sources/Model" 27 | ), 28 | 29 | // Client for the HelloWorld example 30 | .target( 31 | name: "Client", 32 | dependencies: [ 33 | "GRPC", 34 | "Model", 35 | ], 36 | path: "Sources/client" 37 | ), 38 | 39 | // Server for the HelloWorld example 40 | .target( 41 | name: "Server", 42 | dependencies: [ 43 | "GRPC", 44 | "Model", 45 | ], 46 | path: "Sources/server" 47 | ), 48 | ] 49 | ) 50 | -------------------------------------------------------------------------------- /tests/MyGame/InParentNamespace.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame; 4 | 5 | import java.nio.*; 6 | import java.lang.*; 7 | import java.util.*; 8 | import com.google.flatbuffers.*; 9 | 10 | @SuppressWarnings("unused") 11 | public final class InParentNamespace extends Table { 12 | public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); } 13 | public static InParentNamespace getRootAsInParentNamespace(ByteBuffer _bb) { return getRootAsInParentNamespace(_bb, new InParentNamespace()); } 14 | public static InParentNamespace getRootAsInParentNamespace(ByteBuffer _bb, InParentNamespace obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 15 | public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } 16 | public InParentNamespace __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 17 | 18 | 19 | public static void startInParentNamespace(FlatBufferBuilder builder) { builder.startTable(0); } 20 | public static int endInParentNamespace(FlatBufferBuilder builder) { 21 | int o = builder.endTable(); 22 | return o; 23 | } 24 | 25 | public static final class Vector extends BaseVector { 26 | public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } 27 | 28 | public InParentNamespace get(int j) { return get(new InParentNamespace(), j); } 29 | public InParentNamespace get(InParentNamespace obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.go: -------------------------------------------------------------------------------- 1 | // Code generated by the FlatBuffers compiler. DO NOT EDIT. 2 | 3 | package Example 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type TestT struct { 10 | A int16 11 | B int8 12 | } 13 | 14 | func (t *TestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 15 | if t == nil { return 0 } 16 | return CreateTest(builder, t.A, t.B) 17 | } 18 | func (rcv *Test) UnPackTo(t *TestT) { 19 | t.A = rcv.A() 20 | t.B = rcv.B() 21 | } 22 | 23 | func (rcv *Test) UnPack() *TestT { 24 | if rcv == nil { return nil } 25 | t := &TestT{} 26 | rcv.UnPackTo(t) 27 | return t 28 | } 29 | 30 | type Test struct { 31 | _tab flatbuffers.Struct 32 | } 33 | 34 | func (rcv *Test) Init(buf []byte, i flatbuffers.UOffsetT) { 35 | rcv._tab.Bytes = buf 36 | rcv._tab.Pos = i 37 | } 38 | 39 | func (rcv *Test) Table() flatbuffers.Table { 40 | return rcv._tab.Table 41 | } 42 | 43 | func (rcv *Test) A() int16 { 44 | return rcv._tab.GetInt16(rcv._tab.Pos + flatbuffers.UOffsetT(0)) 45 | } 46 | func (rcv *Test) MutateA(n int16) bool { 47 | return rcv._tab.MutateInt16(rcv._tab.Pos+flatbuffers.UOffsetT(0), n) 48 | } 49 | 50 | func (rcv *Test) B() int8 { 51 | return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(2)) 52 | } 53 | func (rcv *Test) MutateB(n int8) bool { 54 | return rcv._tab.MutateInt8(rcv._tab.Pos+flatbuffers.UOffsetT(2), n) 55 | } 56 | 57 | func CreateTest(builder *flatbuffers.Builder, a int16, b int8) flatbuffers.UOffsetT { 58 | builder.Prep(2, 4) 59 | builder.Pad(1) 60 | builder.PrependInt8(b) 61 | builder.PrependInt16(a) 62 | return builder.Offset() 63 | } 64 | -------------------------------------------------------------------------------- /grpc/flatbuffers-java-grpc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.google.flatbuffers 8 | flatbuffers-parent 9 | 1.12.0 10 | 11 | flatbuffers-java-grpc 12 | ${project.artifactId} 13 | bundle 14 | 15 | Utilities supporting generated code for GRPC 16 | 17 | 18 | 19 | Wouter van Oortmerssen 20 | 21 | 22 | Yuri Finkelstein 23 | https://github.com/yfinkelstein 24 | 25 | 26 | 27 | 1.12.0 28 | 29 | 30 | 31 | com.google.flatbuffers 32 | flatbuffers-java 33 | ${project.parent.version} 34 | 35 | 36 | io.grpc 37 | grpc-core 38 | ${gRPC.version} 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /tests/union_vector/Rapunzel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | using global::System; 6 | using global::System.Collections.Generic; 7 | using global::FlatBuffers; 8 | 9 | public struct Rapunzel : IFlatbufferObject 10 | { 11 | private Struct __p; 12 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 13 | public void __init(int _i, ByteBuffer _bb) { __p = new Struct(_i, _bb); } 14 | public Rapunzel __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 15 | 16 | public int HairLength { get { return __p.bb.GetInt(__p.bb_pos + 0); } } 17 | public void MutateHairLength(int hair_length) { __p.bb.PutInt(__p.bb_pos + 0, hair_length); } 18 | 19 | public static Offset CreateRapunzel(FlatBufferBuilder builder, int HairLength) { 20 | builder.Prep(4, 4); 21 | builder.PutInt(HairLength); 22 | return new Offset(builder.Offset); 23 | } 24 | public RapunzelT UnPack() { 25 | var _o = new RapunzelT(); 26 | this.UnPackTo(_o); 27 | return _o; 28 | } 29 | public void UnPackTo(RapunzelT _o) { 30 | _o.HairLength = this.HairLength; 31 | } 32 | public static Offset Pack(FlatBufferBuilder builder, RapunzelT _o) { 33 | if (_o == null) return default(Offset); 34 | return CreateRapunzel( 35 | builder, 36 | _o.HairLength); 37 | } 38 | }; 39 | 40 | public class RapunzelT 41 | { 42 | [Newtonsoft.Json.JsonProperty("hair_length")] 43 | public int HairLength { get; set; } 44 | 45 | public RapunzelT() { 46 | this.HairLength = 0; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Stat.lua: -------------------------------------------------------------------------------- 1 | -- automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | -- namespace: Example 4 | 5 | local flatbuffers = require('flatbuffers') 6 | 7 | local Stat = {} -- the module 8 | local Stat_mt = {} -- the class metatable 9 | 10 | function Stat.New() 11 | local o = {} 12 | setmetatable(o, {__index = Stat_mt}) 13 | return o 14 | end 15 | function Stat.GetRootAsStat(buf, offset) 16 | local n = flatbuffers.N.UOffsetT:Unpack(buf, offset) 17 | local o = Stat.New() 18 | o:Init(buf, n + offset) 19 | return o 20 | end 21 | function Stat_mt:Init(buf, pos) 22 | self.view = flatbuffers.view.New(buf, pos) 23 | end 24 | function Stat_mt:Id() 25 | local o = self.view:Offset(4) 26 | if o ~= 0 then 27 | return self.view:String(o + self.view.pos) 28 | end 29 | end 30 | function Stat_mt:Val() 31 | local o = self.view:Offset(6) 32 | if o ~= 0 then 33 | return self.view:Get(flatbuffers.N.Int64, o + self.view.pos) 34 | end 35 | return 0 36 | end 37 | function Stat_mt:Count() 38 | local o = self.view:Offset(8) 39 | if o ~= 0 then 40 | return self.view:Get(flatbuffers.N.Uint16, o + self.view.pos) 41 | end 42 | return 0 43 | end 44 | function Stat.Start(builder) builder:StartObject(3) end 45 | function Stat.AddId(builder, id) builder:PrependUOffsetTRelativeSlot(0, id, 0) end 46 | function Stat.AddVal(builder, val) builder:PrependInt64Slot(1, val, 0) end 47 | function Stat.AddCount(builder, count) builder:PrependUint16Slot(2, count, 0) end 48 | function Stat.End(builder) return builder:EndObject() end 49 | 50 | return Stat -- return the module --------------------------------------------------------------------------------