├── python ├── __init__.py ├── flatbuffers │ ├── __init__.py │ ├── encode.py │ ├── packer.py │ └── compat.py └── setup.py ├── tests ├── MyGame │ ├── __init__.py │ ├── Example │ │ ├── __init__.py │ │ ├── Color.py │ │ ├── Any.py │ │ ├── Color.cs │ │ ├── Color.go │ │ ├── Any.cs │ │ ├── Any.go │ │ ├── Color.java │ │ ├── Color.php │ │ ├── Any.java │ │ ├── Any.php │ │ ├── Test.py │ │ ├── Ability.py │ │ ├── Test.java │ │ ├── Ability.java │ │ ├── Test.cs │ │ ├── TestSimpleTableWithEnum.py │ │ ├── Ability.cs │ │ ├── Test.go │ │ ├── Ability.go │ │ ├── Ability.php │ │ ├── Test.php │ │ ├── TestSimpleTableWithEnum.go │ │ ├── Stat.py │ │ ├── Vec3.py │ │ ├── TestSimpleTableWithEnum.java │ │ ├── Vec3.java │ │ ├── Stat.go │ │ ├── Vec3.cs │ │ ├── TestSimpleTableWithEnum.cs │ │ ├── Stat.java │ │ ├── Vec3.php │ │ ├── Vec3.go │ │ └── Stat.cs │ └── Example2 │ │ ├── Monster.py │ │ ├── Monster.go │ │ ├── Monster.java │ │ ├── Monster.cs │ │ └── Monster.php ├── namespace_test │ ├── NamespaceA │ │ ├── __init__.py │ │ ├── NamespaceB │ │ │ ├── __init__.py │ │ │ ├── EnumInNestedNS.py │ │ │ ├── EnumInNestedNS.cs │ │ │ ├── EnumInNestedNS.go │ │ │ ├── EnumInNestedNS.java │ │ │ ├── EnumInNestedNS.php │ │ │ ├── StructInNestedNS.py │ │ │ ├── StructInNestedNS.java │ │ │ ├── TableInNestedNS.py │ │ │ ├── StructInNestedNS.cs │ │ │ ├── StructInNestedNS.go │ │ │ ├── StructInNestedNS.php │ │ │ ├── TableInNestedNS.go │ │ │ ├── TableInNestedNS.java │ │ │ ├── TableInNestedNS.cs │ │ │ └── TableInNestedNS.php │ │ ├── SecondTableInA.py │ │ ├── SecondTableInA.go │ │ ├── TableInC.py │ │ ├── TableInC.go │ │ ├── SecondTableInA.java │ │ ├── SecondTableInA.cs │ │ ├── TableInC.java │ │ ├── TableInC.cs │ │ ├── TableInFirstNS.py │ │ ├── TableInFirstNS.java │ │ ├── SecondTableInA.php │ │ └── TableInFirstNS.go │ ├── namespace_test1.fbs │ ├── namespace_test2.fbs │ └── NamespaceC │ │ ├── TableInC.py │ │ ├── TableInC.go │ │ ├── TableInC.java │ │ └── TableInC.cs ├── monster_test.bfbs ├── monsterdata_test.mon ├── monsterdata_python_wire.mon ├── prototest │ ├── imported.proto │ ├── test.golden │ └── test.proto ├── FlatBuffers.Test │ ├── Resources │ │ └── monsterdata_test.mon │ ├── NetTest.sh │ ├── FlatBuffersTestMethodAttribute.cs │ ├── FlatBuffersTestClassAttribute.cs │ ├── Lcg.cs │ ├── FuzzTestData.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── include_test │ ├── include_test1.fbs │ └── sub │ │ └── include_test2.fbs ├── unicode_test.json ├── fuzzer │ ├── flatbuffers_verifier_fuzzer.cc │ ├── flatbuffers_parser_fuzzer.cc │ ├── build_fuzzer.sh │ ├── build_run_verifier_test.sh │ └── build_run_parser_test.sh ├── union_vector │ └── union_vector.fbs ├── TestAll.sh ├── JavaScriptTest.sh ├── JavaTest.bat ├── TypeScriptTest.sh ├── monsterdata_test.json ├── generate_code.bat ├── monsterdata_test.golden ├── generate_code.sh └── JavaTest.sh ├── .gitattributes ├── docs ├── source │ ├── CONTRIBUTING.md │ ├── groups │ ├── gRPC │ │ └── CppUsage.md │ ├── README_TO_GENERATE_DOCS.md │ ├── GoApi.md │ └── Grammar.md ├── images │ ├── ftv2mnode.png │ ├── ftv2pnode.png │ └── fpl_logo_small.png └── footer.html ├── biicode.conf ├── go ├── doc.go ├── struct.go ├── lib.go ├── grpc.go └── sizes.go ├── grpc ├── samples │ └── greeter │ │ ├── greeter.fbs │ │ └── Makefile ├── README.md └── src │ └── compiler │ └── config.h ├── samples ├── monsterdata.json ├── monster.fbs ├── android │ ├── jni │ │ ├── schemas │ │ │ └── animal.fbs │ │ ├── Application.mk │ │ ├── main.cpp │ │ └── Android.mk │ ├── res │ │ └── values │ │ │ └── strings.xml │ └── AndroidManifest.xml ├── android_sample.sh ├── php_sample.sh ├── javascript_sample.sh ├── python_sample.sh ├── csharp_sample.sh ├── java_sample.sh ├── sample_text.cpp └── go_sample.sh ├── composer.json ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── biicode ├── README.md ├── cmake │ └── biicode.cmake └── support │ └── bii-travis.sh ├── reflection ├── generate_code.sh └── reflection.fbs ├── package.json ├── php ├── Constants.php └── Struct.php ├── android ├── jni │ ├── main.cpp │ ├── Application.mk │ ├── run_flatc.py │ └── Android.mk ├── .project ├── res │ └── values │ │ └── strings.xml └── AndroidManifest.xml ├── net └── FlatBuffers │ ├── FlatBufferConstants.cs │ ├── Struct.cs │ ├── IFlatbufferObject.cs │ ├── Offset.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── FlatBuffers.csproj ├── java └── com │ └── google │ └── flatbuffers │ ├── Struct.java │ └── Constants.java ├── .travis.yml ├── .gitignore ├── appveyor.yml ├── CONTRIBUTING.md └── CMake └── FindFlatBuffers.cmake /python/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/MyGame/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /tests/MyGame/Example/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/source/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ../../CONTRIBUTING.md -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/monster_test.bfbs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/tests/monster_test.bfbs -------------------------------------------------------------------------------- /docs/images/ftv2mnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/docs/images/ftv2mnode.png -------------------------------------------------------------------------------- /docs/images/ftv2pnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/docs/images/ftv2pnode.png -------------------------------------------------------------------------------- /tests/monsterdata_test.mon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/tests/monsterdata_test.mon -------------------------------------------------------------------------------- /biicode.conf: -------------------------------------------------------------------------------- 1 | # Biicode configuration file 2 | [paths] 3 | include 4 | [mains] 5 | !android/* 6 | [tests] 7 | tests/* 8 | -------------------------------------------------------------------------------- /docs/images/fpl_logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/docs/images/fpl_logo_small.png -------------------------------------------------------------------------------- /go/doc.go: -------------------------------------------------------------------------------- 1 | // Package flatbuffers provides facilities to read and write flatbuffers 2 | // objects. 3 | package flatbuffers 4 | -------------------------------------------------------------------------------- /tests/monsterdata_python_wire.mon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/tests/monsterdata_python_wire.mon -------------------------------------------------------------------------------- /tests/prototest/imported.proto: -------------------------------------------------------------------------------- 1 | package proto.test; 2 | 3 | message ImportedMessage { 4 | optional int32 a = 26; 5 | } 6 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/Resources/monsterdata_test.mon: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/josephDunne/flatbuffers/HEAD/tests/FlatBuffers.Test/Resources/monsterdata_test.mon -------------------------------------------------------------------------------- /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/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 | 6 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | class Color(object): 6 | Red = 1 7 | Green = 2 8 | Blue = 8 9 | 10 | -------------------------------------------------------------------------------- /tests/include_test/sub/include_test2.fbs: -------------------------------------------------------------------------------- 1 | include "sub/include_test2.fbs"; // should be skipped 2 | 3 | namespace MyGame.OtherNameSpace; 4 | 5 | enum FromInclude:long { IncludeVal } 6 | 7 | struct Unused {} 8 | 9 | 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/Color.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | public enum Color : sbyte 9 | { 10 | Red = 1, 11 | Green = 2, 12 | Blue = 8, 13 | }; 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | const ( 6 | ColorRed = 1 7 | ColorGreen = 2 8 | ColorBlue = 8 9 | ) 10 | 11 | var EnumNamesColor = map[int]string{ 12 | ColorRed:"Red", 13 | ColorGreen:"Green", 14 | ColorBlue:"Blue", 15 | } 16 | 17 | -------------------------------------------------------------------------------- /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 | public enum EnumInNestedNS : sbyte 9 | { 10 | A = 0, 11 | B = 1, 12 | C = 2, 13 | }; 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | public enum Any : byte 9 | { 10 | NONE = 0, 11 | Monster = 1, 12 | TestSimpleTableWithEnum = 2, 13 | MyGame_Example2_Monster = 3, 14 | }; 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /samples/monsterdata.json: -------------------------------------------------------------------------------- 1 | { 2 | pos: { 3 | x: 1, 4 | y: 2, 5 | z: 3 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 | { 22 | name: "bow", 23 | damage:90 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceB 4 | 5 | const ( 6 | EnumInNestedNSA = 0 7 | EnumInNestedNSB = 1 8 | EnumInNestedNSC = 2 9 | ) 10 | 11 | var EnumNamesEnumInNestedNS = map[int]string{ 12 | EnumInNestedNSA:"A", 13 | EnumInNestedNSB:"B", 14 | EnumInNestedNSC:"C", 15 | } 16 | 17 | -------------------------------------------------------------------------------- /tests/unicode_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unicode_test", 3 | "testarrayoftables": [ 4 | { "name": "Цлїςσδε" }, 5 | { "name": "フムアムカモケモ" }, 6 | { "name": "フムヤムカモケモ" }, 7 | { "name": "㊀㊁㊂㊃㊄" }, 8 | { "name": "☳☶☲" }, 9 | { "name": "𡇙𝌆" } 10 | ], 11 | "testarrayofstring": [ 12 | "Цлїςσδε", 13 | "フムアムカモケモ", 14 | "フムヤムカモケモ", 15 | "㊀㊁㊂㊃㊄", 16 | "☳☶☲", 17 | "𡇙𝌆" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/FlatBuffers.Test/NetTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Testing C# on Linux using Mono. 4 | 5 | mcs -out:fbnettest.exe ../../net/FlatBuffers/*.cs ../MyGame/Example/*.cs FlatBuffersTestClassAttribute.cs FlatBuffersTestMethodAttribute.cs Assert.cs FlatBuffersExampleTests.cs Program.cs ByteBufferTests.cs FlatBufferBuilderTests.cs FlatBuffersFuzzTests.cs FuzzTestData.cs Lcg.cs TestTable.cs 6 | ./fbnettest.exe 7 | rm fbnettest.exe 8 | rm Resources/monsterdata_cstest.mon 9 | 10 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Any.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | const ( 6 | AnyNONE = 0 7 | AnyMonster = 1 8 | AnyTestSimpleTableWithEnum = 2 9 | AnyMyGame_Example2_Monster = 3 10 | ) 11 | 12 | var EnumNamesAny = map[int]string{ 13 | AnyNONE:"NONE", 14 | AnyMonster:"Monster", 15 | AnyTestSimpleTableWithEnum:"TestSimpleTableWithEnum", 16 | AnyMyGame_Example2_Monster:"MyGame_Example2_Monster", 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Color.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package MyGame.Example; 4 | 5 | public final class Color { 6 | private Color() { } 7 | public static final byte Red = 1; 8 | public static final byte Green = 2; 9 | public static final byte Blue = 8; 10 | 11 | public static final String[] names = { "Red", "Green", "", "", "", "", "", "Blue", }; 12 | 13 | public static String name(int e) { return names[e - Red]; } 14 | } 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 | -------------------------------------------------------------------------------- /docs/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/Color.php: -------------------------------------------------------------------------------- 1 | 5 | #include 6 | #include 7 | 8 | #include "flatbuffers/idl.h" 9 | 10 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 11 | flatbuffers::Parser parser; 12 | // Guarantee 0-termination. 13 | std::string s(reinterpret_cast(data), size); 14 | parser.Parse(s.c_str()); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /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/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/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.php: -------------------------------------------------------------------------------- 1 | /dev/null 18 | ../flatc -b -I include_test monster_test.fbs unicode_test.json 19 | node JavaScriptTest ./monster_test_generated 20 | -------------------------------------------------------------------------------- /php/Constants.php: -------------------------------------------------------------------------------- 1 | 18 | 19 | extern int main(int argc, char **argv); 20 | 21 | void android_main(android_app *app) { 22 | // Make sure glue isn't stripped. 23 | app_dummy(); 24 | 25 | main(0, NULL); 26 | } 27 | -------------------------------------------------------------------------------- /php/Struct.php: -------------------------------------------------------------------------------- 1 | 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; 25 | public ByteBuffer bb; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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 JavaTest.java 21 | java -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test JavaTest 22 | -------------------------------------------------------------------------------- /tests/fuzzer/build_run_parser_test.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 | clang++ -fsanitize-coverage=edge -fsanitize=address -std=c++11 -stdlib=libstdc++ -I.. -I../../include flatbuffers_parser_fuzzer.cc ../../src/idl_parser.cpp ../../src/util.cpp libFuzzer.a -o fuzz_parser 18 | mkdir -p parser_corpus 19 | cp ../*.json ../*.fbs parser_corpus 20 | ./fuzz_parser parser_corpus 21 | -------------------------------------------------------------------------------- /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/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) { bb_pos = _i; bb = _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 | 28 | -------------------------------------------------------------------------------- /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 Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); } 13 | public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; } 15 | public Monster __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 16 | 17 | 18 | public static void startMonster(FlatBufferBuilder builder) { builder.startObject(0); } 19 | public static int endMonster(FlatBufferBuilder builder) { 20 | int o = builder.endObject(); 21 | return o; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tests/prototest/test.golden: -------------------------------------------------------------------------------- 1 | // Generated from test.proto 2 | 3 | namespace _proto._test; 4 | 5 | /// Enum doc comment. 6 | enum ProtoEnum : int { 7 | FOO = 1, 8 | /// Enum 2nd value doc comment misaligned. 9 | BAR = 5, 10 | } 11 | 12 | namespace _proto._test; 13 | 14 | table ImportedMessage { 15 | a:int; 16 | } 17 | 18 | namespace _proto._test; 19 | 20 | /// 2nd table doc comment with 21 | /// many lines. 22 | table ProtoMessage { 23 | c:int = 16; 24 | d:long; 25 | p:uint; 26 | e:ulong; 27 | /// doc comment for f. 28 | f:int = -1; 29 | g:long; 30 | h:uint; 31 | q:ulong; 32 | i:int; 33 | j:long; 34 | /// doc comment for k. 35 | k:bool; 36 | /// doc comment for l on 2 37 | /// lines 38 | l:string (required); 39 | m:string; 40 | n:_proto._test._ProtoMessage.OtherMessage; 41 | o:[string]; 42 | z:_proto._test.ImportedMessage; 43 | } 44 | 45 | namespace _proto._test._ProtoMessage; 46 | 47 | table OtherMessage { 48 | a:double; 49 | /// doc comment for b. 50 | b:float = 3.14149; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /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) { bb_pos = _i; bb = _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 | 28 | -------------------------------------------------------------------------------- /android/.project: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | FlatBufferTest 20 | 21 | -------------------------------------------------------------------------------- /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-10 17 | APP_PROJECT_PATH := $(call my-dir)/.. 18 | APP_STL := gnustl_static 19 | 20 | APP_ABI := armeabi-v7a 21 | 22 | APP_CPPFLAGS += -std=c++11 23 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/Monster.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example2 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct Monster : IFlatbufferObject 12 | { 13 | private Table __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); } 16 | public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 17 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 18 | public Monster __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 19 | 20 | 21 | public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(0); } 22 | public static Offset EndMonster(FlatBufferBuilder builder) { 23 | int o = builder.EndObject(); 24 | return new Offset(o); 25 | } 26 | }; 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /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-10 17 | APP_PROJECT_PATH := $(call my-dir)/.. 18 | APP_STL := gnustl_static 19 | 20 | APP_ABI := armeabi-v7a 21 | 22 | APP_CPPFLAGS += -std=c++11 23 | -------------------------------------------------------------------------------- /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 | ../flatc --ts --no-fb-import --gen-mutable -o ts -I include_test monster_test.fbs 19 | ../flatc -b -I include_test monster_test.fbs unicode_test.json 20 | npm install @types/flatbuffers 21 | tsc --strict --noUnusedParameters --noUnusedLocals --noImplicitReturns --strictNullChecks ts/monster_test_generated.ts 22 | npm uninstall @types/flatbuffers 23 | node JavaScriptTest ./ts/monster_test_generated 24 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: NamespaceB 4 | 5 | import flatbuffers 6 | 7 | class TableInNestedNS(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsTableInNestedNS(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = TableInNestedNS() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # TableInNestedNS 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # TableInNestedNS 22 | def Foo(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) 26 | return 0 27 | 28 | def TableInNestedNSStart(builder): builder.StartObject(1) 29 | def TableInNestedNSAddFoo(builder, foo): builder.PrependInt32Slot(0, foo, 0) 30 | def TableInNestedNSEnd(builder): return builder.EndObject() 31 | -------------------------------------------------------------------------------- /android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | FlatBufferTest 20 | 21 | -------------------------------------------------------------------------------- /python/flatbuffers/encode.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 . import number_types as N 16 | from . import packer 17 | from .compat import memoryview_type 18 | 19 | 20 | def Get(packer_type, buf, head): 21 | """ Get decodes a value at buf[head:] using `packer_type`. """ 22 | return packer_type.unpack_from(memoryview_type(buf), head)[0] 23 | 24 | 25 | def Write(packer_type, buf, head, n): 26 | """ Write encodes `n` at buf[head:] using `packer_type`. """ 27 | packer_type.pack_into(buf, head, n) 28 | -------------------------------------------------------------------------------- /samples/android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | FlatBufferSample 20 | 21 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct Test : IFlatbufferObject 12 | { 13 | private Struct __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 16 | public Test __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 17 | 18 | public short A { get { return __p.bb.GetShort(__p.bb_pos + 0); } } 19 | public void MutateA(short a) { __p.bb.PutShort(__p.bb_pos + 0, a); } 20 | public sbyte B { get { return __p.bb.GetSbyte(__p.bb_pos + 2); } } 21 | public void MutateB(sbyte b) { __p.bb.PutSbyte(__p.bb_pos + 2, b); } 22 | 23 | public static Offset CreateTest(FlatBufferBuilder builder, short A, sbyte B) { 24 | builder.Prep(2, 4); 25 | builder.Pad(1); 26 | builder.PutSbyte(B); 27 | builder.PutShort(A); 28 | return new Offset(builder.Offset); 29 | } 30 | }; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestSimpleTableWithEnum.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | import flatbuffers 6 | 7 | class TestSimpleTableWithEnum(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsTestSimpleTableWithEnum(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = TestSimpleTableWithEnum() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # TestSimpleTableWithEnum 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # TestSimpleTableWithEnum 22 | def Color(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) 26 | return 2 27 | 28 | def TestSimpleTableWithEnumStart(builder): builder.StartObject(1) 29 | def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependInt8Slot(0, color, 2) 30 | def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() 31 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Ability.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct Ability : IFlatbufferObject 12 | { 13 | private Struct __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 16 | public Ability __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 17 | 18 | public uint Id { get { return __p.bb.GetUint(__p.bb_pos + 0); } } 19 | public void MutateId(uint id) { __p.bb.PutUint(__p.bb_pos + 0, id); } 20 | public uint Distance { get { return __p.bb.GetUint(__p.bb_pos + 4); } } 21 | public void MutateDistance(uint distance) { __p.bb.PutUint(__p.bb_pos + 4, distance); } 22 | 23 | public static Offset CreateAbility(FlatBufferBuilder builder, uint Id, uint Distance) { 24 | builder.Prep(4, 8); 25 | builder.PutUint(Distance); 26 | builder.PutUint(Id); 27 | return new Offset(builder.Offset); 28 | } 29 | }; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /java/com/google/flatbuffers/Struct.java: -------------------------------------------------------------------------------- 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 | package com.google.flatbuffers; 18 | 19 | import java.nio.ByteBuffer; 20 | 21 | /// @cond FLATBUFFERS_INTERNAL 22 | 23 | /** 24 | * All structs in the generated code derive from this class, and add their own accessors. 25 | */ 26 | public class Struct { 27 | /** Used to hold the position of the `bb` buffer. */ 28 | protected int bb_pos; 29 | /** The underlying ByteBuffer to hold the data of the Struct. */ 30 | protected ByteBuffer bb; 31 | } 32 | 33 | /// @endcond 34 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Test.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type Test struct { 10 | _tab flatbuffers.Struct 11 | } 12 | 13 | func (rcv *Test) Init(buf []byte, i flatbuffers.UOffsetT) { 14 | rcv._tab.Bytes = buf 15 | rcv._tab.Pos = i 16 | } 17 | 18 | func (rcv *Test) Table() flatbuffers.Table { 19 | return rcv._tab.Table 20 | } 21 | 22 | func (rcv *Test) A() int16 { 23 | return rcv._tab.GetInt16(rcv._tab.Pos + flatbuffers.UOffsetT(0)) 24 | } 25 | func (rcv *Test) MutateA(n int16) bool { 26 | return rcv._tab.MutateInt16(rcv._tab.Pos+flatbuffers.UOffsetT(0), n) 27 | } 28 | 29 | func (rcv *Test) B() int8 { 30 | return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(2)) 31 | } 32 | func (rcv *Test) MutateB(n int8) bool { 33 | return rcv._tab.MutateInt8(rcv._tab.Pos+flatbuffers.UOffsetT(2), n) 34 | } 35 | 36 | func CreateTest(builder *flatbuffers.Builder, a int16, b int8) flatbuffers.UOffsetT { 37 | builder.Prep(2, 4) 38 | builder.Pad(1) 39 | builder.PrependInt8(b) 40 | builder.PrependInt16(a) 41 | return builder.Offset() 42 | } 43 | -------------------------------------------------------------------------------- /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 | test_type: Monster, 23 | test: { 24 | name: "Fred", 25 | pos: null 26 | }, 27 | test4: [ 28 | { 29 | a: 10, 30 | b: 20 31 | }, 32 | { 33 | b: "40", 34 | a: 30 35 | } 36 | ], 37 | testarrayofstring: [ 38 | "test1", 39 | "test2" 40 | ], 41 | enemy: { 42 | name: "Fred" 43 | }, 44 | testarrayofbools:[ 45 | true, false, true 46 | ], 47 | testhashs32_fnv1: "This string is being hashed!", 48 | testhashu32_fnv1: "This string is being hashed!", 49 | testhashs64_fnv1: "This string is being hashed!", 50 | testhashu64_fnv1: "This string is being hashed!", 51 | testhashs32_fnv1a: "This string is being hashed!", 52 | testhashu32_fnv1a: "This string is being hashed!", 53 | testhashs64_fnv1a: "This string is being hashed!", 54 | testhashu64_fnv1a: "This string is being hashed!", 55 | } 56 | -------------------------------------------------------------------------------- /tests/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 --java --csharp --go --binary --python --js --php --grpc --gen-mutable --gen-object-api --no-includes -I include_test monster_test.fbs monsterdata_test.json 19 | ..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --js --php --gen-mutable -o namespace_test namespace_test\namespace_test1.fbs namespace_test\namespace_test2.fbs 20 | ..\%buildtype%\flatc.exe --binary --schema -I include_test monster_test.fbs 21 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace NamespaceA.NamespaceB 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct StructInNestedNS : IFlatbufferObject 12 | { 13 | private Struct __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 16 | public StructInNestedNS __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 17 | 18 | public int A { get { return __p.bb.GetInt(__p.bb_pos + 0); } } 19 | public void MutateA(int a) { __p.bb.PutInt(__p.bb_pos + 0, a); } 20 | public int B { get { return __p.bb.GetInt(__p.bb_pos + 4); } } 21 | public void MutateB(int b) { __p.bb.PutInt(__p.bb_pos + 4, b); } 22 | 23 | public static Offset CreateStructInNestedNS(FlatBufferBuilder builder, int A, int B) { 24 | builder.Prep(4, 8); 25 | builder.PutInt(B); 26 | builder.PutInt(A); 27 | return new Offset(builder.Offset); 28 | } 29 | }; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /python/setup.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 | from setuptools import setup 16 | 17 | setup( 18 | name='flatbuffers', 19 | version='2015.05.14.0', 20 | license='Apache 2.0', 21 | author='FlatBuffers Contributors', 22 | author_email='me@rwinslow.com', 23 | url='https://github.com/google/flatbuffers', 24 | long_description=('Python runtime library for use with the Flatbuffers' 25 | 'serialization format.'), 26 | packages=['flatbuffers'], 27 | include_package_data=True, 28 | requires=[], 29 | description='The FlatBuffers serialization format for Python', 30 | ) 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Ability.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type Ability struct { 10 | _tab flatbuffers.Struct 11 | } 12 | 13 | func (rcv *Ability) Init(buf []byte, i flatbuffers.UOffsetT) { 14 | rcv._tab.Bytes = buf 15 | rcv._tab.Pos = i 16 | } 17 | 18 | func (rcv *Ability) Table() flatbuffers.Table { 19 | return rcv._tab.Table 20 | } 21 | 22 | func (rcv *Ability) Id() uint32 { 23 | return rcv._tab.GetUint32(rcv._tab.Pos + flatbuffers.UOffsetT(0)) 24 | } 25 | func (rcv *Ability) MutateId(n uint32) bool { 26 | return rcv._tab.MutateUint32(rcv._tab.Pos+flatbuffers.UOffsetT(0), n) 27 | } 28 | 29 | func (rcv *Ability) Distance() uint32 { 30 | return rcv._tab.GetUint32(rcv._tab.Pos + flatbuffers.UOffsetT(4)) 31 | } 32 | func (rcv *Ability) MutateDistance(n uint32) bool { 33 | return rcv._tab.MutateUint32(rcv._tab.Pos+flatbuffers.UOffsetT(4), n) 34 | } 35 | 36 | func CreateAbility(builder *flatbuffers.Builder, id uint32, distance uint32) flatbuffers.UOffsetT { 37 | builder.Prep(4, 8) 38 | builder.PrependUint32(distance) 39 | builder.PrependUint32(id) 40 | return builder.Offset() 41 | } 42 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | os: 4 | - linux 5 | - osx 6 | 7 | compiler: 8 | - gcc 9 | #- clang 10 | 11 | env: 12 | matrix: 13 | - BUILD_TYPE=Debug BIICODE=false 14 | - BUILD_TYPE=Release BIICODE=false 15 | # biicode .deb files no longer available. 16 | # - BUILD_TYPE=Release BIICODE=true 17 | # - BUILD_TYPE=Debug BIICODE=true 18 | global: 19 | - GCC_VERSION="4.9" 20 | 21 | before_install: 22 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi 23 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi 24 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq g++-$GCC_VERSION; fi 25 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-$GCC_VERSION; fi 26 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which g++-$GCC_VERSION) /usr/bin/g++; fi 27 | - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi 28 | 29 | script: 30 | - if [ "$BIICODE" == "false" ]; then cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE . && make && make test; fi 31 | - if [ "$BIICODE" == "true" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then ./biicode/support/bii-travis.sh $BUILD_TYPE; fi 32 | -------------------------------------------------------------------------------- /tests/monsterdata_test.golden: -------------------------------------------------------------------------------- 1 | { 2 | pos: { 3 | x: 1.0, 4 | y: 2.0, 5 | z: 3.0, 6 | test1: 3.0, 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 | testhashs32_fnv1: -579221183, 60 | testhashu32_fnv1: 3715746113, 61 | testhashs64_fnv1: 7930699090847568257, 62 | testhashu64_fnv1: 7930699090847568257, 63 | testhashs32_fnv1a: -1904106383, 64 | testhashu32_fnv1a: 2390860913, 65 | testhashs64_fnv1a: 4898026182817603057, 66 | testhashu64_fnv1a: 4898026182817603057, 67 | flex: 1234 68 | } 69 | -------------------------------------------------------------------------------- /biicode/support/bii-travis.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 | 17 | sudo apt-get update -qq 18 | sudo apt-get install libglu1-mesa-dev xorg-dev 19 | wget http://www.biicode.com/downloads/latest/ubuntu64 20 | mv ubuntu64 bii-ubuntu64.deb 21 | (sudo dpkg -i bii-ubuntu64.deb) && sudo apt-get -f install 22 | rm bii-ubuntu64.deb 23 | wget https://s3.amazonaws.com/biibinaries/thirdparty/cmake-3.0.2-Linux-64.tar.gz 24 | tar -xzf cmake-3.0.2-Linux-64.tar.gz 25 | sudo cp -fR cmake-3.0.2-Linux-64/* /usr 26 | rm -rf cmake-3.0.2-Linux-64 27 | rm cmake-3.0.2-Linux-64.tar.gz 28 | 29 | cmake --version 30 | bii init -l && bii configure -DCMAKE_BUILD_TYPE=$1 && bii test -------------------------------------------------------------------------------- /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/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceB 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type StructInNestedNS struct { 10 | _tab flatbuffers.Struct 11 | } 12 | 13 | func (rcv *StructInNestedNS) Init(buf []byte, i flatbuffers.UOffsetT) { 14 | rcv._tab.Bytes = buf 15 | rcv._tab.Pos = i 16 | } 17 | 18 | func (rcv *StructInNestedNS) Table() flatbuffers.Table { 19 | return rcv._tab.Table 20 | } 21 | 22 | func (rcv *StructInNestedNS) A() int32 { 23 | return rcv._tab.GetInt32(rcv._tab.Pos + flatbuffers.UOffsetT(0)) 24 | } 25 | func (rcv *StructInNestedNS) MutateA(n int32) bool { 26 | return rcv._tab.MutateInt32(rcv._tab.Pos+flatbuffers.UOffsetT(0), n) 27 | } 28 | 29 | func (rcv *StructInNestedNS) B() int32 { 30 | return rcv._tab.GetInt32(rcv._tab.Pos + flatbuffers.UOffsetT(4)) 31 | } 32 | func (rcv *StructInNestedNS) MutateB(n int32) bool { 33 | return rcv._tab.MutateInt32(rcv._tab.Pos+flatbuffers.UOffsetT(4), n) 34 | } 35 | 36 | func CreateStructInNestedNS(builder *flatbuffers.Builder, a int32, b int32) flatbuffers.UOffsetT { 37 | builder.Prep(4, 8) 38 | builder.PrependInt32(b) 39 | builder.PrependInt32(a) 40 | return builder.Offset() 41 | } 42 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/SecondTableInA.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: NamespaceA 4 | 5 | import flatbuffers 6 | 7 | class SecondTableInA(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsSecondTableInA(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = SecondTableInA() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # SecondTableInA 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # SecondTableInA 22 | def ReferToC(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | x = self._tab.Indirect(o + self._tab.Pos) 26 | from .TableInC import TableInC 27 | obj = TableInC() 28 | obj.Init(self._tab.Bytes, x) 29 | return obj 30 | return None 31 | 32 | def SecondTableInAStart(builder): builder.StartObject(1) 33 | def SecondTableInAAddReferToC(builder, referToC): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(referToC), 0) 34 | def SecondTableInAEnd(builder): return builder.EndObject() 35 | -------------------------------------------------------------------------------- /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/prototest/test.proto: -------------------------------------------------------------------------------- 1 | // Sample .proto file that we can translate to the corresponding .fbs. 2 | 3 | option some_option = is_ignored; 4 | import "imported.proto"; 5 | 6 | package proto.test; 7 | 8 | /// Enum doc comment. 9 | enum ProtoEnum { 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 | message ProtoMessage { 18 | // Ignored non-doc comment. 19 | // A nested message declaration, will be moved to top level in .fbs 20 | message OtherMessage { 21 | optional double a = 26; 22 | /// doc comment for b. 23 | optional float b = 32 [default = 3.14149]; 24 | } 25 | optional int32 c = 12 [default = 16]; 26 | optional int64 d = 1 [default = 0]; 27 | optional uint32 p = 1; 28 | optional uint64 e = 2; 29 | /// doc comment for f. 30 | optional sint32 f = 3 [default = -1]; 31 | optional sint64 g = 4; 32 | optional fixed32 h = 5; 33 | optional fixed64 q = 6; 34 | optional sfixed32 i = 7; 35 | optional sfixed64 j = 8; 36 | /// doc comment for k. 37 | optional bool k = 9; 38 | /// doc comment for l on 2 39 | /// lines 40 | required string l = 10; 41 | optional bytes m = 11; 42 | optional OtherMessage n = 12; 43 | repeated string o = 14; 44 | optional ImportedMessage z = 16; 45 | } 46 | -------------------------------------------------------------------------------- /tests/generate_code.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 | ../flatc --cpp --java --csharp --go --binary --python --js --ts --php --grpc --gen-mutable --gen-object-api --no-includes --no-fb-import -I include_test monster_test.fbs monsterdata_test.json 18 | ../flatc --cpp --java --csharp --go --binary --python --js --ts --php --gen-mutable --no-fb-import -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs 19 | ../flatc --cpp --gen-mutable --gen-object-api -o union_vector ./union_vector/union_vector.fbs 20 | ../flatc -b --schema --bfbs-comments -I include_test monster_test.fbs 21 | cd ../samples 22 | ../flatc --cpp --gen-mutable --gen-object-api monster.fbs 23 | cd ../reflection 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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("&2 36 | exit 1 37 | fi 38 | 39 | javac -d "${targetdir}" -classpath "${testdir}/../java:${testdir}:${testdir}/namespace_test" "${testdir}/JavaTest.java" 40 | 41 | (cd "${testdir}" && java -classpath "${targetdir}" JavaTest ) 42 | 43 | rm -rf "${targetdir}" 44 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceB 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type TableInNestedNS struct { 10 | _tab flatbuffers.Table 11 | } 12 | 13 | func GetRootAsTableInNestedNS(buf []byte, offset flatbuffers.UOffsetT) *TableInNestedNS { 14 | n := flatbuffers.GetUOffsetT(buf[offset:]) 15 | x := &TableInNestedNS{} 16 | x.Init(buf, n+offset) 17 | return x 18 | } 19 | 20 | func (rcv *TableInNestedNS) Init(buf []byte, i flatbuffers.UOffsetT) { 21 | rcv._tab.Bytes = buf 22 | rcv._tab.Pos = i 23 | } 24 | 25 | func (rcv *TableInNestedNS) Table() flatbuffers.Table { 26 | return rcv._tab 27 | } 28 | 29 | func (rcv *TableInNestedNS) Foo() int32 { 30 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 31 | if o != 0 { 32 | return rcv._tab.GetInt32(o + rcv._tab.Pos) 33 | } 34 | return 0 35 | } 36 | 37 | func (rcv *TableInNestedNS) MutateFoo(n int32) bool { 38 | return rcv._tab.MutateInt32Slot(4, n) 39 | } 40 | 41 | func TableInNestedNSStart(builder *flatbuffers.Builder) { 42 | builder.StartObject(1) 43 | } 44 | func TableInNestedNSAddFoo(builder *flatbuffers.Builder, foo int32) { 45 | builder.PrependInt32Slot(0, foo, 0) 46 | } 47 | func TableInNestedNSEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 48 | return builder.EndObject() 49 | } 50 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | ./build_apk.sh 33 | 34 | # Cleanup the temporary files. 35 | rm build.xml local.properties proguard-project.txt project.properties 36 | rm -rf bin libs obj 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *_wire.txt 2 | *_wire.bin 3 | .DS_Store 4 | *.o 5 | *.o.d 6 | *.class 7 | *.a 8 | *~ 9 | *.vcxproj 10 | *.vcxproj.filters 11 | *.vcxproj.user 12 | *.sln 13 | *.suo 14 | *.keystore 15 | **/bin/** 16 | **/gen/** 17 | **/libs/** 18 | **/obj/** 19 | **/*.dir/** 20 | **/CMakeFiles/** 21 | **/cmake_install.cmake 22 | **/install_manifest.txt 23 | **/CMakeCache.txt 24 | **/CMakeTestfile.cmake 25 | **/Debug/** 26 | **/Release/** 27 | build.xml 28 | local.properties 29 | project.properties 30 | proguard-project.txt 31 | linklint_results 32 | Makefile 33 | flatc 34 | flatc.exe 35 | flathash 36 | flathash.exe 37 | flattests 38 | flattests.exe 39 | flatsamplebinary 40 | flatsamplebinary.exe 41 | flatsampletext 42 | flatsampletext.exe 43 | grpctest 44 | grpctest.exe 45 | snapshot.sh 46 | tests/go_gen 47 | tests/monsterdata_java_wire.mon 48 | tests/monsterdata_go_wire.mon 49 | tests/monsterdata_javascript_wire.mon 50 | tests/unicode_test.mon 51 | tests/ts/ 52 | CMakeLists.txt.user 53 | CMakeScripts/** 54 | CTestTestfile.cmake 55 | FlatBuffers.cbp 56 | build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/** 57 | build/Xcode/FlatBuffers.xcodeproj/xcuserdata/** 58 | FlatBuffers.xcodeproj/ 59 | java/.idea 60 | java/*.iml 61 | .idea 62 | *.iml 63 | target 64 | **/*.pyc 65 | build/VS2010/FlatBuffers.sdf 66 | build/VS2010/FlatBuffers.opensdf 67 | build/VS2010/ipch/**/*.ipch 68 | *.so 69 | Testing/Temporary 70 | .cproject 71 | .settings/ 72 | .project 73 | net/**/obj 74 | node_modules/ 75 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/SecondTableInA.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 | 9 | type SecondTableInA struct { 10 | _tab flatbuffers.Table 11 | } 12 | 13 | func GetRootAsSecondTableInA(buf []byte, offset flatbuffers.UOffsetT) *SecondTableInA { 14 | n := flatbuffers.GetUOffsetT(buf[offset:]) 15 | x := &SecondTableInA{} 16 | x.Init(buf, n+offset) 17 | return x 18 | } 19 | 20 | func (rcv *SecondTableInA) Init(buf []byte, i flatbuffers.UOffsetT) { 21 | rcv._tab.Bytes = buf 22 | rcv._tab.Pos = i 23 | } 24 | 25 | func (rcv *SecondTableInA) Table() flatbuffers.Table { 26 | return rcv._tab 27 | } 28 | 29 | func (rcv *SecondTableInA) ReferToC(obj *TableInC) *TableInC { 30 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 31 | if o != 0 { 32 | x := rcv._tab.Indirect(o + rcv._tab.Pos) 33 | if obj == nil { 34 | obj = new(TableInC) 35 | } 36 | obj.Init(rcv._tab.Bytes, x) 37 | return obj 38 | } 39 | return nil 40 | } 41 | 42 | func SecondTableInAStart(builder *flatbuffers.Builder) { 43 | builder.StartObject(1) 44 | } 45 | func SecondTableInAAddReferToC(builder *flatbuffers.Builder, referToC flatbuffers.UOffsetT) { 46 | builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(referToC), 0) 47 | } 48 | func SecondTableInAEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 49 | return builder.EndObject() 50 | } 51 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestSimpleTableWithEnum.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type TestSimpleTableWithEnum struct { 10 | _tab flatbuffers.Table 11 | } 12 | 13 | func GetRootAsTestSimpleTableWithEnum(buf []byte, offset flatbuffers.UOffsetT) *TestSimpleTableWithEnum { 14 | n := flatbuffers.GetUOffsetT(buf[offset:]) 15 | x := &TestSimpleTableWithEnum{} 16 | x.Init(buf, n+offset) 17 | return x 18 | } 19 | 20 | func (rcv *TestSimpleTableWithEnum) Init(buf []byte, i flatbuffers.UOffsetT) { 21 | rcv._tab.Bytes = buf 22 | rcv._tab.Pos = i 23 | } 24 | 25 | func (rcv *TestSimpleTableWithEnum) Table() flatbuffers.Table { 26 | return rcv._tab 27 | } 28 | 29 | func (rcv *TestSimpleTableWithEnum) Color() int8 { 30 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 31 | if o != 0 { 32 | return rcv._tab.GetInt8(o + rcv._tab.Pos) 33 | } 34 | return 2 35 | } 36 | 37 | func (rcv *TestSimpleTableWithEnum) MutateColor(n int8) bool { 38 | return rcv._tab.MutateInt8Slot(4, n) 39 | } 40 | 41 | func TestSimpleTableWithEnumStart(builder *flatbuffers.Builder) { 42 | builder.StartObject(1) 43 | } 44 | func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color int8) { 45 | builder.PrependInt8Slot(0, color, 2) 46 | } 47 | func TestSimpleTableWithEnumEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 48 | return builder.EndObject() 49 | } 50 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | 5 | os: Visual Studio 2015 6 | 7 | environment: 8 | matrix: 9 | - CMAKE_VS_VERSION: "10 2010" 10 | - CMAKE_VS_VERSION: "14 2015" 11 | 12 | platform: 13 | - x86 14 | - x64 15 | 16 | configuration: 17 | - Debug 18 | - Release 19 | 20 | before_build: 21 | - cmake -G"Visual Studio %CMAKE_VS_VERSION%" 22 | # This cuts down on a lot of noise generated by xamarin warnings. 23 | - del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" 24 | 25 | build: 26 | project: ALL_BUILD.vcxproj 27 | verbosity: minimal 28 | 29 | test_script: 30 | - rem "---------------- C++ -----------------" 31 | - "%CONFIGURATION%\\flattests.exe" 32 | - rem "---------------- Java -----------------" 33 | - "cd tests" 34 | - "java -version" 35 | - "JavaTest.bat" 36 | - rem "---------------- JS -----------------" 37 | - "node --version" 38 | - "..\\%CONFIGURATION%\\flatc -b -I include_test monster_test.fbs unicode_test.json" 39 | - "node JavaScriptTest ./monster_test_generated" 40 | - rem "---------------- C# -----------------" 41 | # Have to compile this here rather than in "build" above because AppVeyor only 42 | # supports building one project?? 43 | - "cd FlatBuffers.Test" 44 | - "msbuild.exe /property:Configuration=Release;OutputPath=tempcs /verbosity:minimal FlatBuffers.Test.csproj" 45 | - "tempcs\\FlatBuffers.Test.exe" 46 | # TODO: add more languages. 47 | - "cd ..\\.." 48 | 49 | artifacts: 50 | - path: $(CONFIGURATION)\\flatc.exe 51 | name: flatc.exe 52 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /docs/source/Grammar.md: -------------------------------------------------------------------------------- 1 | Grammar of the schema language {#flatbuffers_grammar} 2 | ============================== 3 | 4 | schema = include* 5 | ( namespace\_decl | type\_decl | enum\_decl | root\_decl | 6 | file_extension_decl | file_identifier_decl | 7 | attribute\_decl | object )* 8 | 9 | include = `include` string\_constant `;` 10 | 11 | namespace\_decl = `namespace` ident ( `.` ident )* `;` 12 | 13 | attribute\_decl = `attribute` string\_constant `;` 14 | 15 | type\_decl = ( `table` | `struct` ) ident metadata `{` field\_decl+ `}` 16 | 17 | enum\_decl = ( `enum` | `union` ) ident [ `:` type ] metadata `{` commasep( 18 | enumval\_decl ) `}` 19 | 20 | root\_decl = `root_type` ident `;` 21 | 22 | field\_decl = ident `:` type [ `=` scalar ] metadata `;` 23 | 24 | type = `bool` | `byte` | `ubyte` | `short` | `ushort` | `int` | `uint` | 25 | `float` | `long` | `ulong` | `double` 26 | | `string` | `[` type `]` | ident 27 | 28 | enumval\_decl = ident [ `=` integer\_constant ] 29 | 30 | metadata = [ `(` commasep( ident [ `:` single\_value ] ) `)` ] 31 | 32 | scalar = integer\_constant | float\_constant 33 | 34 | object = { commasep( ident `:` value ) } 35 | 36 | single\_value = scalar | string\_constant 37 | 38 | value = single\_value | object | `[` commasep( value ) `]` 39 | 40 | commasep(x) = [ x ( `,` x )\* ] 41 | 42 | file_extension_decl = `file_extension` string\_constant `;` 43 | 44 | file_identifier_decl = `file_identifier` string\_constant `;` 45 | 46 | integer\_constant = -?[0-9]+ | `true` | `false` 47 | 48 | float\_constant = -?[0-9]+.[0-9]+((e|E)(+|-)?[0-9]+)? 49 | -------------------------------------------------------------------------------- /java/com/google/flatbuffers/Constants.java: -------------------------------------------------------------------------------- 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 | package com.google.flatbuffers; 18 | 19 | /// @cond FLATBUFFERS_INTERNAL 20 | 21 | /** 22 | * Class that holds shared constants 23 | */ 24 | public class Constants { 25 | // Java doesn't seem to have these. 26 | /** The number of bytes in an `byte`. */ 27 | static final int SIZEOF_BYTE = 1; 28 | /** The number of bytes in a `short`. */ 29 | static final int SIZEOF_SHORT = 2; 30 | /** The number of bytes in an `int`. */ 31 | static final int SIZEOF_INT = 4; 32 | /** The number of bytes in an `float`. */ 33 | static final int SIZEOF_FLOAT = 4; 34 | /** The number of bytes in an `long`. */ 35 | static final int SIZEOF_LONG = 8; 36 | /** The number of bytes in an `double`. */ 37 | static final int SIZEOF_DOUBLE = 8; 38 | /** The number of bytes in a file identifier. */ 39 | static final int FILE_IDENTIFIER_LENGTH = 4; 40 | } 41 | 42 | /// @endcond 43 | -------------------------------------------------------------------------------- /python/flatbuffers/compat.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 | """ A tiny version of `six` to help with backwards compability. """ 16 | 17 | import sys 18 | 19 | PY2 = sys.version_info[0] == 2 20 | PY26 = sys.version_info[0:2] == (2, 6) 21 | PY27 = sys.version_info[0:2] == (2, 7) 22 | PY275 = sys.version_info[0:3] >= (2, 7, 5) 23 | PY3 = sys.version_info[0] == 3 24 | PY34 = sys.version_info[0:2] >= (3, 4) 25 | 26 | if PY3: 27 | string_types = (str,) 28 | binary_types = (bytes,bytearray) 29 | range_func = range 30 | memoryview_type = memoryview 31 | struct_bool_decl = "?" 32 | else: 33 | string_types = (unicode,) 34 | if PY26 or PY27: 35 | binary_types = (str,bytearray) 36 | else: 37 | binary_types = (str,) 38 | range_func = xrange 39 | if PY26 or (PY27 and not PY275): 40 | memoryview_type = buffer 41 | struct_bool_decl = " 16 | 17 | #include "android_native_app_glue.h" 18 | #include "animal_generated.h" // Includes "flatbuffers/flatbuffers.h". 19 | 20 | void android_main(android_app *app) { 21 | app_dummy(); 22 | 23 | flatbuffers::FlatBufferBuilder builder; 24 | auto name = builder.CreateString("Dog"); 25 | auto sound = builder.CreateString("Bark"); 26 | auto animal_buffer = sample::CreateAnimal(builder, name, sound); 27 | builder.Finish(animal_buffer); 28 | 29 | // We now have a FlatBuffer that can be stored on disk or sent over a network. 30 | 31 | // ...Code to store on disk or send over a network goes here... 32 | 33 | // Instead, we're going to access it immediately, as if we just recieved this. 34 | 35 | auto animal = sample::GetAnimal(builder.GetBufferPointer()); 36 | 37 | assert(animal->name()->str() == "Dog"); 38 | assert(animal->sound()->str() == "Bark"); 39 | (void)animal; // To silence "Unused Variable" warnings. 40 | 41 | __android_log_print(ANDROID_LOG_INFO, "FlatBufferSample", 42 | "FlatBuffer successfully created and verified."); 43 | } 44 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Vec3.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: Example 4 | 5 | import flatbuffers 6 | 7 | class Vec3(object): 8 | __slots__ = ['_tab'] 9 | 10 | # Vec3 11 | def Init(self, buf, pos): 12 | self._tab = flatbuffers.table.Table(buf, pos) 13 | 14 | # Vec3 15 | def X(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0)) 16 | # Vec3 17 | def Y(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4)) 18 | # Vec3 19 | def Z(self): return self._tab.Get(flatbuffers.number_types.Float32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(8)) 20 | # Vec3 21 | def Test1(self): return self._tab.Get(flatbuffers.number_types.Float64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(16)) 22 | # Vec3 23 | def Test2(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(24)) 24 | # Vec3 25 | def Test3(self, obj): 26 | obj.Init(self._tab.Bytes, self._tab.Pos + 26) 27 | return obj 28 | 29 | 30 | def CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b): 31 | builder.Prep(16, 32) 32 | builder.Pad(2) 33 | builder.Prep(2, 4) 34 | builder.Pad(1) 35 | builder.PrependInt8(test3_b) 36 | builder.PrependInt16(test3_a) 37 | builder.Pad(1) 38 | builder.PrependInt8(test2) 39 | builder.PrependFloat64(test1) 40 | builder.Pad(4) 41 | builder.PrependFloat32(z) 42 | builder.PrependFloat32(y) 43 | builder.PrependFloat32(x) 44 | return builder.Offset() 45 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceC/TableInC.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: NamespaceC 4 | 5 | import flatbuffers 6 | 7 | class TableInC(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsTableInC(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = TableInC() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # TableInC 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # TableInC 22 | def ReferToA1(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | x = self._tab.Indirect(o + self._tab.Pos) 26 | from .TableInFirstNS import TableInFirstNS 27 | obj = TableInFirstNS() 28 | obj.Init(self._tab.Bytes, x) 29 | return obj 30 | return None 31 | 32 | # TableInC 33 | def ReferToA2(self): 34 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 35 | if o != 0: 36 | x = self._tab.Indirect(o + self._tab.Pos) 37 | from .SecondTableInA import SecondTableInA 38 | obj = SecondTableInA() 39 | obj.Init(self._tab.Bytes, x) 40 | return obj 41 | return None 42 | 43 | def TableInCStart(builder): builder.StartObject(2) 44 | def TableInCAddReferToA1(builder, referToA1): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(referToA1), 0) 45 | def TableInCAddReferToA2(builder, referToA2): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(referToA2), 0) 46 | def TableInCEnd(builder): return builder.EndObject() 47 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestSimpleTableWithEnum.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 TestSimpleTableWithEnum extends Table { 12 | public static TestSimpleTableWithEnum getRootAsTestSimpleTableWithEnum(ByteBuffer _bb) { return getRootAsTestSimpleTableWithEnum(_bb, new TestSimpleTableWithEnum()); } 13 | public static TestSimpleTableWithEnum getRootAsTestSimpleTableWithEnum(ByteBuffer _bb, TestSimpleTableWithEnum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; } 15 | public TestSimpleTableWithEnum __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 16 | 17 | public byte color() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) : 2; } 18 | public boolean mutateColor(byte color) { int o = __offset(4); if (o != 0) { bb.put(o + bb_pos, color); return true; } else { return false; } } 19 | 20 | public static int createTestSimpleTableWithEnum(FlatBufferBuilder builder, 21 | byte color) { 22 | builder.startObject(1); 23 | TestSimpleTableWithEnum.addColor(builder, color); 24 | return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder); 25 | } 26 | 27 | public static void startTestSimpleTableWithEnum(FlatBufferBuilder builder) { builder.startObject(1); } 28 | public static void addColor(FlatBufferBuilder builder, byte color) { builder.addByte(0, color, 2); } 29 | public static int endTestSimpleTableWithEnum(FlatBufferBuilder builder) { 30 | int o = builder.endObject(); 31 | return o; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Vec3.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 Vec3 extends Struct { 12 | public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; } 13 | public Vec3 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 14 | 15 | public float x() { return bb.getFloat(bb_pos + 0); } 16 | public void mutateX(float x) { bb.putFloat(bb_pos + 0, x); } 17 | public float y() { return bb.getFloat(bb_pos + 4); } 18 | public void mutateY(float y) { bb.putFloat(bb_pos + 4, y); } 19 | public float z() { return bb.getFloat(bb_pos + 8); } 20 | public void mutateZ(float z) { bb.putFloat(bb_pos + 8, z); } 21 | public double test1() { return bb.getDouble(bb_pos + 16); } 22 | public void mutateTest1(double test1) { bb.putDouble(bb_pos + 16, test1); } 23 | public byte test2() { return bb.get(bb_pos + 24); } 24 | public void mutateTest2(byte test2) { bb.put(bb_pos + 24, test2); } 25 | public Test test3() { return test3(new Test()); } 26 | public Test test3(Test obj) { return obj.__assign(bb_pos + 26, bb); } 27 | 28 | public static int createVec3(FlatBufferBuilder builder, float x, float y, float z, double test1, byte test2, short test3_a, byte test3_b) { 29 | builder.prep(16, 32); 30 | builder.pad(2); 31 | builder.prep(2, 4); 32 | builder.pad(1); 33 | builder.putByte(test3_b); 34 | builder.putShort(test3_a); 35 | builder.pad(1); 36 | builder.putByte(test2); 37 | builder.putDouble(test1); 38 | builder.pad(4); 39 | builder.putFloat(z); 40 | builder.putFloat(y); 41 | builder.putFloat(x); 42 | return builder.offset(); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /samples/csharp_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 runs on Mac and Linux. It requires `mono` to be installed 18 | # and `flatc` to be built (using `cmake` in the root directory). 19 | 20 | sampledir=$(cd $(dirname $BASH_SOURCE) && pwd) 21 | rootidr=$(cd $sampledir/.. && pwd) 22 | currentdir=$(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 | # Run `flatc`. Note: This requires you to compile using `cmake` from the 31 | # root `/flatbuffers` directory. 32 | if [ -e ../flatc ]; then 33 | ../flatc --csharp --gen-mutable monster.fbs 34 | elif [ -e ../Debug/flatc ]; then 35 | ../Debug/flatc --csharp --gen-mutable monster.fbs 36 | else 37 | echo 'flatc' could not be found. Make sure to build FlatBuffers from the \ 38 | $rootdir directory. 39 | exit 1 40 | fi 41 | 42 | echo Compiling and running the C# sample. 43 | 44 | # Compile and execute the sample. 45 | mcs SampleBinary.cs MyGame/Sample/*.cs ../net/FlatBuffers/*.cs 46 | mono SampleBinary.exe 47 | 48 | # Cleanup temporary files. 49 | rm SampleBinary.exe 50 | rm -rf MyGame/ 51 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace NamespaceA.NamespaceB 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct TableInNestedNS : IFlatbufferObject 12 | { 13 | private Table __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public static TableInNestedNS GetRootAsTableInNestedNS(ByteBuffer _bb) { return GetRootAsTableInNestedNS(_bb, new TableInNestedNS()); } 16 | public static TableInNestedNS GetRootAsTableInNestedNS(ByteBuffer _bb, TableInNestedNS obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 17 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 18 | public TableInNestedNS __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 19 | 20 | public int Foo { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetInt(o + __p.bb_pos) : (int)0; } } 21 | public bool MutateFoo(int foo) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutInt(o + __p.bb_pos, foo); return true; } else { return false; } } 22 | 23 | public static Offset CreateTableInNestedNS(FlatBufferBuilder builder, 24 | int foo = 0) { 25 | builder.StartObject(1); 26 | TableInNestedNS.AddFoo(builder, foo); 27 | return TableInNestedNS.EndTableInNestedNS(builder); 28 | } 29 | 30 | public static void StartTableInNestedNS(FlatBufferBuilder builder) { builder.StartObject(1); } 31 | public static void AddFoo(FlatBufferBuilder builder, int foo) { builder.AddInt(0, foo, 0); } 32 | public static Offset EndTableInNestedNS(FlatBufferBuilder builder) { 33 | int o = builder.EndObject(); 34 | return new Offset(o); 35 | } 36 | }; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/FuzzTestData.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 | internal static class FuzzTestData 22 | { 23 | private static readonly byte[] _overflowInt32 = new byte[] {0x83, 0x33, 0x33, 0x33}; 24 | private static readonly byte[] _overflowInt64 = new byte[] { 0x84, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; 25 | 26 | public static readonly bool BoolValue = true; 27 | public static readonly sbyte Int8Value = -127; // 0x81 28 | public static readonly byte UInt8Value = 255; // 0xFF 29 | public static readonly short Int16Value = -32222; // 0x8222; 30 | public static readonly ushort UInt16Value = 65262; // 0xFEEE 31 | public static readonly int Int32Value = BitConverter.ToInt32(_overflowInt32, 0); 32 | public static readonly uint UInt32Value = 0xFDDDDDDD; 33 | public static readonly long Int64Value = BitConverter.ToInt64(_overflowInt64, 0); 34 | public static readonly ulong UInt64Value = 0xFCCCCCCCCCCCCCCC; 35 | public static readonly float Float32Value = 3.14159f; 36 | public static readonly double Float64Value = 3.14159265359; 37 | } 38 | } -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/SecondTableInA.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace NamespaceA 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct SecondTableInA : IFlatbufferObject 12 | { 13 | private Table __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public static SecondTableInA GetRootAsSecondTableInA(ByteBuffer _bb) { return GetRootAsSecondTableInA(_bb, new SecondTableInA()); } 16 | public static SecondTableInA GetRootAsSecondTableInA(ByteBuffer _bb, SecondTableInA obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 17 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 18 | public SecondTableInA __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 19 | 20 | public NamespaceC.TableInC? ReferToC { get { int o = __p.__offset(4); return o != 0 ? (NamespaceC.TableInC?)(new NamespaceC.TableInC()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } 21 | 22 | public static Offset CreateSecondTableInA(FlatBufferBuilder builder, 23 | Offset refer_to_cOffset = default(Offset)) { 24 | builder.StartObject(1); 25 | SecondTableInA.AddReferToC(builder, refer_to_cOffset); 26 | return SecondTableInA.EndSecondTableInA(builder); 27 | } 28 | 29 | public static void StartSecondTableInA(FlatBufferBuilder builder) { builder.StartObject(1); } 30 | public static void AddReferToC(FlatBufferBuilder builder, Offset referToCOffset) { builder.AddOffset(0, referToCOffset.Value, 0); } 31 | public static Offset EndSecondTableInA(FlatBufferBuilder builder) { 32 | int o = builder.EndObject(); 33 | return new Offset(o); 34 | } 35 | }; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceC/TableInC.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceC 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type TableInC struct { 10 | _tab flatbuffers.Table 11 | } 12 | 13 | func GetRootAsTableInC(buf []byte, offset flatbuffers.UOffsetT) *TableInC { 14 | n := flatbuffers.GetUOffsetT(buf[offset:]) 15 | x := &TableInC{} 16 | x.Init(buf, n+offset) 17 | return x 18 | } 19 | 20 | func (rcv *TableInC) Init(buf []byte, i flatbuffers.UOffsetT) { 21 | rcv._tab.Bytes = buf 22 | rcv._tab.Pos = i 23 | } 24 | 25 | func (rcv *TableInC) Table() flatbuffers.Table { 26 | return rcv._tab 27 | } 28 | 29 | func (rcv *TableInC) ReferToA1(obj *TableInFirstNS) *TableInFirstNS { 30 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 31 | if o != 0 { 32 | x := rcv._tab.Indirect(o + rcv._tab.Pos) 33 | if obj == nil { 34 | obj = new(TableInFirstNS) 35 | } 36 | obj.Init(rcv._tab.Bytes, x) 37 | return obj 38 | } 39 | return nil 40 | } 41 | 42 | func (rcv *TableInC) ReferToA2(obj *SecondTableInA) *SecondTableInA { 43 | o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) 44 | if o != 0 { 45 | x := rcv._tab.Indirect(o + rcv._tab.Pos) 46 | if obj == nil { 47 | obj = new(SecondTableInA) 48 | } 49 | obj.Init(rcv._tab.Bytes, x) 50 | return obj 51 | } 52 | return nil 53 | } 54 | 55 | func TableInCStart(builder *flatbuffers.Builder) { 56 | builder.StartObject(2) 57 | } 58 | func TableInCAddReferToA1(builder *flatbuffers.Builder, referToA1 flatbuffers.UOffsetT) { 59 | builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(referToA1), 0) 60 | } 61 | func TableInCAddReferToA2(builder *flatbuffers.Builder, referToA2 flatbuffers.UOffsetT) { 62 | builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(referToA2), 0) 63 | } 64 | func TableInCEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 65 | return builder.EndObject() 66 | } 67 | -------------------------------------------------------------------------------- /samples/java_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 runs on Mac and Linux. It requires `java` to be installed 18 | # and `flatc` to be built (using `cmake` in the root directory). 19 | 20 | sampledir=$(cd $(dirname $BASH_SOURCE) && pwd) 21 | rootdir=$(cd $sampledir/.. && pwd) 22 | currentdir=$(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 | # Run `flatc`. Note: This requires you to compile using `cmake` from the 31 | # root `/flatbuffers` directory. 32 | if [ -e ../flatc ]; then 33 | ../flatc --java --gen-mutable monster.fbs 34 | elif [ -e ../Debug/flatc ]; then 35 | ../Debug/flatc --java --gen-mutable monster.fbs 36 | else 37 | echo 'flatc' could not be found. Make sure to build FlatBuffers from the \ 38 | $rootdir directory. 39 | exit 1 40 | fi 41 | 42 | echo Compiling and running the Java sample. 43 | 44 | # Compile and execute the sample. 45 | javac -classpath ${sampledir}/../java:${sampledir} SampleBinary.java 46 | java -classpath ${sampledir}/../java:${sampledir} SampleBinary 47 | 48 | # Cleanup temporary files. 49 | rm -rf MyGame/ 50 | rm ${sampledir}/../java/com/google/flatbuffers/*.class 51 | rm *.class 52 | -------------------------------------------------------------------------------- /grpc/src/compiler/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | #ifndef SRC_COMPILER_CONFIG_H 35 | #define SRC_COMPILER_CONFIG_H 36 | 37 | // This file is here only because schema_interface.h, which is copied from gRPC, 38 | // includes it. There is nothing for Flatbuffers to configure. 39 | 40 | #endif // SRC_COMPILER_CONFIG_H 41 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Stat.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type Stat struct { 10 | _tab flatbuffers.Table 11 | } 12 | 13 | func GetRootAsStat(buf []byte, offset flatbuffers.UOffsetT) *Stat { 14 | n := flatbuffers.GetUOffsetT(buf[offset:]) 15 | x := &Stat{} 16 | x.Init(buf, n+offset) 17 | return x 18 | } 19 | 20 | func (rcv *Stat) Init(buf []byte, i flatbuffers.UOffsetT) { 21 | rcv._tab.Bytes = buf 22 | rcv._tab.Pos = i 23 | } 24 | 25 | func (rcv *Stat) Table() flatbuffers.Table { 26 | return rcv._tab 27 | } 28 | 29 | func (rcv *Stat) Id() []byte { 30 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 31 | if o != 0 { 32 | return rcv._tab.ByteVector(o + rcv._tab.Pos) 33 | } 34 | return nil 35 | } 36 | 37 | func (rcv *Stat) Val() int64 { 38 | o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) 39 | if o != 0 { 40 | return rcv._tab.GetInt64(o + rcv._tab.Pos) 41 | } 42 | return 0 43 | } 44 | 45 | func (rcv *Stat) MutateVal(n int64) bool { 46 | return rcv._tab.MutateInt64Slot(6, n) 47 | } 48 | 49 | func (rcv *Stat) Count() uint16 { 50 | o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) 51 | if o != 0 { 52 | return rcv._tab.GetUint16(o + rcv._tab.Pos) 53 | } 54 | return 0 55 | } 56 | 57 | func (rcv *Stat) MutateCount(n uint16) bool { 58 | return rcv._tab.MutateUint16Slot(8, n) 59 | } 60 | 61 | func StatStart(builder *flatbuffers.Builder) { 62 | builder.StartObject(3) 63 | } 64 | func StatAddId(builder *flatbuffers.Builder, id flatbuffers.UOffsetT) { 65 | builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(id), 0) 66 | } 67 | func StatAddVal(builder *flatbuffers.Builder, val int64) { 68 | builder.PrependInt64Slot(1, val, 0) 69 | } 70 | func StatAddCount(builder *flatbuffers.Builder, count uint16) { 71 | builder.PrependUint16Slot(2, count, 0) 72 | } 73 | func StatEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 74 | return builder.EndObject() 75 | } 76 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Vec3.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct Vec3 : IFlatbufferObject 12 | { 13 | private Struct __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 16 | public Vec3 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 17 | 18 | public float X { get { return __p.bb.GetFloat(__p.bb_pos + 0); } } 19 | public void MutateX(float x) { __p.bb.PutFloat(__p.bb_pos + 0, x); } 20 | public float Y { get { return __p.bb.GetFloat(__p.bb_pos + 4); } } 21 | public void MutateY(float y) { __p.bb.PutFloat(__p.bb_pos + 4, y); } 22 | public float Z { get { return __p.bb.GetFloat(__p.bb_pos + 8); } } 23 | public void MutateZ(float z) { __p.bb.PutFloat(__p.bb_pos + 8, z); } 24 | public double Test1 { get { return __p.bb.GetDouble(__p.bb_pos + 16); } } 25 | public void MutateTest1(double test1) { __p.bb.PutDouble(__p.bb_pos + 16, test1); } 26 | public Color Test2 { get { return (Color)__p.bb.GetSbyte(__p.bb_pos + 24); } } 27 | public void MutateTest2(Color test2) { __p.bb.PutSbyte(__p.bb_pos + 24, (sbyte)test2); } 28 | public Test Test3 { get { return (new Test()).__assign(__p.bb_pos + 26, __p.bb); } } 29 | 30 | public static Offset CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z, double Test1, Color Test2, short test3_A, sbyte test3_B) { 31 | builder.Prep(16, 32); 32 | builder.Pad(2); 33 | builder.Prep(2, 4); 34 | builder.Pad(1); 35 | builder.PutSbyte(test3_B); 36 | builder.PutShort(test3_A); 37 | builder.Pad(1); 38 | builder.PutSbyte((sbyte)Test2); 39 | builder.PutDouble(Test1); 40 | builder.Pad(4); 41 | builder.PutFloat(Z); 42 | builder.PutFloat(Y); 43 | builder.PutFloat(X); 44 | return new Offset(builder.Offset); 45 | } 46 | }; 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/MyGame/Example/TestSimpleTableWithEnum.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public partial struct TestSimpleTableWithEnum : IFlatbufferObject 12 | { 13 | private Table __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public static TestSimpleTableWithEnum GetRootAsTestSimpleTableWithEnum(ByteBuffer _bb) { return GetRootAsTestSimpleTableWithEnum(_bb, new TestSimpleTableWithEnum()); } 16 | public static TestSimpleTableWithEnum GetRootAsTestSimpleTableWithEnum(ByteBuffer _bb, TestSimpleTableWithEnum obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 17 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 18 | public TestSimpleTableWithEnum __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 19 | 20 | public Color Color { get { int o = __p.__offset(4); return o != 0 ? (Color)__p.bb.GetSbyte(o + __p.bb_pos) : Color.Green; } } 21 | public bool MutateColor(Color color) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)color); return true; } else { return false; } } 22 | 23 | public static Offset CreateTestSimpleTableWithEnum(FlatBufferBuilder builder, 24 | Color color = Color.Green) { 25 | builder.StartObject(1); 26 | TestSimpleTableWithEnum.AddColor(builder, color); 27 | return TestSimpleTableWithEnum.EndTestSimpleTableWithEnum(builder); 28 | } 29 | 30 | public static void StartTestSimpleTableWithEnum(FlatBufferBuilder builder) { builder.StartObject(1); } 31 | public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)color, 2); } 32 | public static Offset EndTestSimpleTableWithEnum(FlatBufferBuilder builder) { 33 | int o = builder.EndObject(); 34 | return new Offset(o); 35 | } 36 | }; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInC.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA; 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 TableInC extends Table { 12 | public static TableInC getRootAsTableInC(ByteBuffer _bb) { return getRootAsTableInC(_bb, new TableInC()); } 13 | public static TableInC getRootAsTableInC(ByteBuffer _bb, TableInC obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public TableInC __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 15 | 16 | public NamespaceA.TableInFirstNS referToA1() { return referToA1(new NamespaceA.TableInFirstNS()); } 17 | public NamespaceA.TableInFirstNS referToA1(NamespaceA.TableInFirstNS obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 18 | public SecondTableInA referToA2() { return referToA2(new SecondTableInA()); } 19 | public SecondTableInA referToA2(SecondTableInA obj) { int o = __offset(6); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 20 | 21 | public static int createTableInC(FlatBufferBuilder builder, 22 | int refer_to_a1Offset, 23 | int refer_to_a2Offset) { 24 | builder.startObject(2); 25 | TableInC.addReferToA2(builder, refer_to_a2Offset); 26 | TableInC.addReferToA1(builder, refer_to_a1Offset); 27 | return TableInC.endTableInC(builder); 28 | } 29 | 30 | public static void startTableInC(FlatBufferBuilder builder) { builder.startObject(2); } 31 | public static void addReferToA1(FlatBufferBuilder builder, int referToA1Offset) { builder.addOffset(0, referToA1Offset, 0); } 32 | public static void addReferToA2(FlatBufferBuilder builder, int referToA2Offset) { builder.addOffset(1, referToA2Offset, 0); } 33 | public static int endTableInC(FlatBufferBuilder builder) { 34 | int o = builder.endObject(); 35 | return o; 36 | } 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /tests/MyGame/Example2/Monster.php: -------------------------------------------------------------------------------- 1 | init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb)); 21 | } 22 | 23 | public static function MonsterIdentifier() 24 | { 25 | return "MONS"; 26 | } 27 | 28 | public static function MonsterBufferHasIdentifier(ByteBuffer $buf) 29 | { 30 | return self::__has_identifier($buf, self::MonsterIdentifier()); 31 | } 32 | 33 | public static function MonsterExtension() 34 | { 35 | return "mon"; 36 | } 37 | 38 | /** 39 | * @param int $_i offset 40 | * @param ByteBuffer $_bb 41 | * @return Monster 42 | **/ 43 | public function init($_i, ByteBuffer $_bb) 44 | { 45 | $this->bb_pos = $_i; 46 | $this->bb = $_bb; 47 | return $this; 48 | } 49 | 50 | /** 51 | * @param FlatBufferBuilder $builder 52 | * @return void 53 | */ 54 | public static function startMonster(FlatBufferBuilder $builder) 55 | { 56 | $builder->StartObject(0); 57 | } 58 | 59 | /** 60 | * @param FlatBufferBuilder $builder 61 | * @return Monster 62 | */ 63 | public static function createMonster(FlatBufferBuilder $builder, ) 64 | { 65 | $builder->startObject(0); 66 | $o = $builder->endObject(); 67 | return $o; 68 | } 69 | 70 | /** 71 | * @param FlatBufferBuilder $builder 72 | * @return int table offset 73 | */ 74 | public static function endMonster(FlatBufferBuilder $builder) 75 | { 76 | $o = $builder->endObject(); 77 | return $o; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceC/TableInC.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceC; 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 TableInC extends Table { 12 | public static TableInC getRootAsTableInC(ByteBuffer _bb) { return getRootAsTableInC(_bb, new TableInC()); } 13 | public static TableInC getRootAsTableInC(ByteBuffer _bb, TableInC obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; } 15 | public TableInC __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 16 | 17 | public NamespaceA.TableInFirstNS referToA1() { return referToA1(new NamespaceA.TableInFirstNS()); } 18 | public NamespaceA.TableInFirstNS referToA1(NamespaceA.TableInFirstNS obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } 19 | public NamespaceA.SecondTableInA referToA2() { return referToA2(new NamespaceA.SecondTableInA()); } 20 | public NamespaceA.SecondTableInA referToA2(NamespaceA.SecondTableInA obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } 21 | 22 | public static int createTableInC(FlatBufferBuilder builder, 23 | int refer_to_a1Offset, 24 | int refer_to_a2Offset) { 25 | builder.startObject(2); 26 | TableInC.addReferToA2(builder, refer_to_a2Offset); 27 | TableInC.addReferToA1(builder, refer_to_a1Offset); 28 | return TableInC.endTableInC(builder); 29 | } 30 | 31 | public static void startTableInC(FlatBufferBuilder builder) { builder.startObject(2); } 32 | public static void addReferToA1(FlatBufferBuilder builder, int referToA1Offset) { builder.addOffset(0, referToA1Offset, 0); } 33 | public static void addReferToA2(FlatBufferBuilder builder, int referToA2Offset) { builder.addOffset(1, referToA2Offset, 0); } 34 | public static int endTableInC(FlatBufferBuilder builder) { 35 | int o = builder.endObject(); 36 | return o; 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInC.cs: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | namespace NamespaceA 4 | { 5 | 6 | using System; 7 | using FlatBuffers; 8 | 9 | public sealed class TableInC : Table { 10 | public static TableInC GetRootAsTableInC(ByteBuffer _bb) { return GetRootAsTableInC(_bb, new TableInC()); } 11 | public static TableInC GetRootAsTableInC(ByteBuffer _bb, TableInC obj) { return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 12 | public TableInC __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } 13 | 14 | public NamespaceA.TableInFirstNS ReferToA1 { get { return GetReferToA1(new NamespaceA.TableInFirstNS()); } } 15 | public NamespaceA.TableInFirstNS GetReferToA1(NamespaceA.TableInFirstNS obj) { int o = __offset(4); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 16 | public SecondTableInA ReferToA2 { get { return GetReferToA2(new SecondTableInA()); } } 17 | public SecondTableInA GetReferToA2(SecondTableInA obj) { int o = __offset(6); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } 18 | 19 | public static Offset CreateTableInC(FlatBufferBuilder builder, 20 | Offset refer_to_a1Offset = default(Offset), 21 | Offset refer_to_a2Offset = default(Offset)) { 22 | builder.StartObject(2); 23 | TableInC.AddReferToA2(builder, refer_to_a2Offset); 24 | TableInC.AddReferToA1(builder, refer_to_a1Offset); 25 | return TableInC.EndTableInC(builder); 26 | } 27 | 28 | public static void StartTableInC(FlatBufferBuilder builder) { builder.StartObject(2); } 29 | public static void AddReferToA1(FlatBufferBuilder builder, Offset referToA1Offset) { builder.AddOffset(0, referToA1Offset.Value, 0); } 30 | public static void AddReferToA2(FlatBufferBuilder builder, Offset referToA2Offset) { builder.AddOffset(1, referToA2Offset.Value, 0); } 31 | public static Offset EndTableInC(FlatBufferBuilder builder) { 32 | int o = builder.EndObject(); 33 | return new Offset(o); 34 | } 35 | }; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInFirstNS.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: NamespaceA 4 | 5 | import flatbuffers 6 | 7 | class TableInFirstNS(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsTableInFirstNS(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = TableInFirstNS() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # TableInFirstNS 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # TableInFirstNS 22 | def FooTable(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | x = self._tab.Indirect(o + self._tab.Pos) 26 | from .TableInNestedNS import TableInNestedNS 27 | obj = TableInNestedNS() 28 | obj.Init(self._tab.Bytes, x) 29 | return obj 30 | return None 31 | 32 | # TableInFirstNS 33 | def FooEnum(self): 34 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 35 | if o != 0: 36 | return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) 37 | return 0 38 | 39 | # TableInFirstNS 40 | def FooStruct(self): 41 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) 42 | if o != 0: 43 | x = o + self._tab.Pos 44 | from .StructInNestedNS import StructInNestedNS 45 | obj = StructInNestedNS() 46 | obj.Init(self._tab.Bytes, x) 47 | return obj 48 | return None 49 | 50 | def TableInFirstNSStart(builder): builder.StartObject(3) 51 | def TableInFirstNSAddFooTable(builder, fooTable): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(fooTable), 0) 52 | def TableInFirstNSAddFooEnum(builder, fooEnum): builder.PrependInt8Slot(1, fooEnum, 0) 53 | def TableInFirstNSAddFooStruct(builder, fooStruct): builder.PrependStructSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fooStruct), 0) 54 | def TableInFirstNSEnd(builder): return builder.EndObject() 55 | -------------------------------------------------------------------------------- /net/FlatBuffers/Properties/AssemblyInfo.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.Reflection; 18 | using System.Runtime.CompilerServices; 19 | using System.Runtime.InteropServices; 20 | 21 | // General Information about an assembly is controlled through the following 22 | // set of attributes. Change these attribute values to modify the information 23 | // associated with an assembly. 24 | [assembly: AssemblyTitle("FlatBuffers")] 25 | [assembly: AssemblyDescription("")] 26 | [assembly: AssemblyConfiguration("")] 27 | [assembly: AssemblyCompany("")] 28 | [assembly: AssemblyProduct("FlatBuffers")] 29 | [assembly: AssemblyCopyright("Copyright (c) 2015 Google Inc")] 30 | [assembly: AssemblyTrademark("")] 31 | [assembly: AssemblyCulture("")] 32 | 33 | // Setting ComVisible to false makes the types in this assembly not visible 34 | // to COM components. If you need to access a type in this assembly from 35 | // COM, set the ComVisible attribute to true on that type. 36 | [assembly: ComVisible(false)] 37 | 38 | // The following GUID is for the ID of the typelib if this project is exposed to COM 39 | [assembly: Guid("91c32e64-ef20-47df-9c9f-cec9207bc6df")] 40 | 41 | // Version information for an assembly consists of the following four values: 42 | // 43 | // Major Version 44 | // Minor Version 45 | // Build Number 46 | // Revision 47 | // 48 | // You can specify all the values or you can default the Build and Revision Numbers 49 | // by using the '*' as shown below: 50 | // [assembly: AssemblyVersion("1.0.*")] 51 | [assembly: AssemblyVersion("1.0.0.0")] 52 | [assembly: AssemblyFileVersion("1.0.0.0")] 53 | -------------------------------------------------------------------------------- /tests/FlatBuffers.Test/Properties/AssemblyInfo.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.Reflection; 18 | using System.Runtime.CompilerServices; 19 | using System.Runtime.InteropServices; 20 | 21 | // General Information about an assembly is controlled through the following 22 | // set of attributes. Change these attribute values to modify the information 23 | // associated with an assembly. 24 | [assembly: AssemblyTitle("FlatBuffers.Test")] 25 | [assembly: AssemblyDescription("")] 26 | [assembly: AssemblyConfiguration("")] 27 | [assembly: AssemblyCompany("")] 28 | [assembly: AssemblyProduct("FlatBuffers.Test")] 29 | [assembly: AssemblyCopyright("Copyright (c) 2014 Google Inc")] 30 | [assembly: AssemblyTrademark("")] 31 | [assembly: AssemblyCulture("")] 32 | 33 | // Setting ComVisible to false makes the types in this assembly not visible 34 | // to COM components. If you need to access a type in this assembly from 35 | // COM, set the ComVisible attribute to true on that type. 36 | [assembly: ComVisible(false)] 37 | 38 | // The following GUID is for the ID of the typelib if this project is exposed to COM 39 | [assembly: Guid("a1d58a51-3e74-4ae9-aac7-5a399c9eed1a")] 40 | 41 | // Version information for an assembly consists of the following four values: 42 | // 43 | // Major Version 44 | // Minor Version 45 | // Build Number 46 | // Revision 47 | // 48 | // You can specify all the values or you can default the Build and Revision Numbers 49 | // by using the '*' as shown below: 50 | // [assembly: AssemblyVersion("1.0.*")] 51 | [assembly: AssemblyVersion("1.0.0.0")] 52 | [assembly: AssemblyFileVersion("1.0.0.0")] 53 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Stat.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 Stat extends Table { 12 | public static Stat getRootAsStat(ByteBuffer _bb) { return getRootAsStat(_bb, new Stat()); } 13 | public static Stat getRootAsStat(ByteBuffer _bb, Stat obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; } 15 | public Stat __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 16 | 17 | public String id() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; } 18 | public ByteBuffer idAsByteBuffer() { return __vector_as_bytebuffer(4, 1); } 19 | public long val() { int o = __offset(6); return o != 0 ? bb.getLong(o + bb_pos) : 0L; } 20 | public boolean mutateVal(long val) { int o = __offset(6); if (o != 0) { bb.putLong(o + bb_pos, val); return true; } else { return false; } } 21 | public int count() { int o = __offset(8); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; } 22 | public boolean mutateCount(int count) { int o = __offset(8); if (o != 0) { bb.putShort(o + bb_pos, (short)count); return true; } else { return false; } } 23 | 24 | public static int createStat(FlatBufferBuilder builder, 25 | int idOffset, 26 | long val, 27 | int count) { 28 | builder.startObject(3); 29 | Stat.addVal(builder, val); 30 | Stat.addId(builder, idOffset); 31 | Stat.addCount(builder, count); 32 | return Stat.endStat(builder); 33 | } 34 | 35 | public static void startStat(FlatBufferBuilder builder) { builder.startObject(3); } 36 | public static void addId(FlatBufferBuilder builder, int idOffset) { builder.addOffset(0, idOffset, 0); } 37 | public static void addVal(FlatBufferBuilder builder, long val) { builder.addLong(1, val, 0L); } 38 | public static void addCount(FlatBufferBuilder builder, int count) { builder.addShort(2, (short)count, (short)0); } 39 | public static int endStat(FlatBufferBuilder builder) { 40 | int o = builder.endObject(); 41 | return o; 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInFirstNS.java: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package NamespaceA; 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 TableInFirstNS extends Table { 12 | public static TableInFirstNS getRootAsTableInFirstNS(ByteBuffer _bb) { return getRootAsTableInFirstNS(_bb, new TableInFirstNS()); } 13 | public static TableInFirstNS getRootAsTableInFirstNS(ByteBuffer _bb, TableInFirstNS obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } 14 | public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; } 15 | public TableInFirstNS __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 16 | 17 | public NamespaceA.NamespaceB.TableInNestedNS fooTable() { return fooTable(new NamespaceA.NamespaceB.TableInNestedNS()); } 18 | public NamespaceA.NamespaceB.TableInNestedNS fooTable(NamespaceA.NamespaceB.TableInNestedNS obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; } 19 | public byte fooEnum() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; } 20 | public boolean mutateFooEnum(byte foo_enum) { int o = __offset(6); if (o != 0) { bb.put(o + bb_pos, foo_enum); return true; } else { return false; } } 21 | public NamespaceA.NamespaceB.StructInNestedNS fooStruct() { return fooStruct(new NamespaceA.NamespaceB.StructInNestedNS()); } 22 | public NamespaceA.NamespaceB.StructInNestedNS fooStruct(NamespaceA.NamespaceB.StructInNestedNS obj) { int o = __offset(8); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; } 23 | 24 | public static void startTableInFirstNS(FlatBufferBuilder builder) { builder.startObject(3); } 25 | public static void addFooTable(FlatBufferBuilder builder, int fooTableOffset) { builder.addOffset(0, fooTableOffset, 0); } 26 | public static void addFooEnum(FlatBufferBuilder builder, byte fooEnum) { builder.addByte(1, fooEnum, 0); } 27 | public static void addFooStruct(FlatBufferBuilder builder, int fooStructOffset) { builder.addStruct(2, fooStructOffset, 0); } 28 | public static int endTableInFirstNS(FlatBufferBuilder builder) { 29 | int o = builder.endObject(); 30 | return o; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.php: -------------------------------------------------------------------------------- 1 | init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb)); 21 | } 22 | 23 | /** 24 | * @param int $_i offset 25 | * @param ByteBuffer $_bb 26 | * @return TableInNestedNS 27 | **/ 28 | public function init($_i, ByteBuffer $_bb) 29 | { 30 | $this->bb_pos = $_i; 31 | $this->bb = $_bb; 32 | return $this; 33 | } 34 | 35 | /** 36 | * @return int 37 | */ 38 | public function getFoo() 39 | { 40 | $o = $this->__offset(4); 41 | return $o != 0 ? $this->bb->getInt($o + $this->bb_pos) : 0; 42 | } 43 | 44 | /** 45 | * @param FlatBufferBuilder $builder 46 | * @return void 47 | */ 48 | public static function startTableInNestedNS(FlatBufferBuilder $builder) 49 | { 50 | $builder->StartObject(1); 51 | } 52 | 53 | /** 54 | * @param FlatBufferBuilder $builder 55 | * @return TableInNestedNS 56 | */ 57 | public static function createTableInNestedNS(FlatBufferBuilder $builder, $foo) 58 | { 59 | $builder->startObject(1); 60 | self::addFoo($builder, $foo); 61 | $o = $builder->endObject(); 62 | return $o; 63 | } 64 | 65 | /** 66 | * @param FlatBufferBuilder $builder 67 | * @param int 68 | * @return void 69 | */ 70 | public static function addFoo(FlatBufferBuilder $builder, $foo) 71 | { 72 | $builder->addIntX(0, $foo, 0); 73 | } 74 | 75 | /** 76 | * @param FlatBufferBuilder $builder 77 | * @return int table offset 78 | */ 79 | public static function endTableInNestedNS(FlatBufferBuilder $builder) 80 | { 81 | $o = $builder->endObject(); 82 | return $o; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /samples/sample_text.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 "flatbuffers/idl.h" 18 | #include "flatbuffers/util.h" 19 | 20 | #include "monster_generated.h" // Already includes "flatbuffers/flatbuffers.h". 21 | 22 | using namespace MyGame::Sample; 23 | 24 | // This is an example of parsing text straight into a buffer and then 25 | // generating flatbuffer (JSON) text from the buffer. 26 | int main(int /*argc*/, const char * /*argv*/[]) { 27 | // load FlatBuffer schema (.fbs) and JSON from disk 28 | std::string schemafile; 29 | std::string jsonfile; 30 | bool ok = flatbuffers::LoadFile("samples/monster.fbs", false, &schemafile) && 31 | flatbuffers::LoadFile("samples/monsterdata.json", false, &jsonfile); 32 | if (!ok) { 33 | printf("couldn't load files!\n"); 34 | return 1; 35 | } 36 | 37 | // parse schema first, so we can use it to parse the data after 38 | flatbuffers::Parser parser; 39 | const char *include_directories[] = { "samples", nullptr }; 40 | ok = parser.Parse(schemafile.c_str(), include_directories) && 41 | parser.Parse(jsonfile.c_str(), include_directories); 42 | assert(ok); 43 | 44 | // here, parser.builder_ contains a binary buffer that is the parsed data. 45 | 46 | // to ensure it is correct, we now generate text back from the binary, 47 | // and compare the two: 48 | std::string jsongen; 49 | if (!GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen)) { 50 | printf("Couldn't serialize parsed data to JSON!\n"); 51 | return 1; 52 | } 53 | 54 | if (jsongen != jsonfile) { 55 | printf("%s----------------\n%s", jsongen.c_str(), jsonfile.c_str()); 56 | } 57 | 58 | printf("The FlatBuffer has been parsed from JSON successfully.\n"); 59 | } 60 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/SecondTableInA.php: -------------------------------------------------------------------------------- 1 | init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb)); 21 | } 22 | 23 | /** 24 | * @param int $_i offset 25 | * @param ByteBuffer $_bb 26 | * @return SecondTableInA 27 | **/ 28 | public function init($_i, ByteBuffer $_bb) 29 | { 30 | $this->bb_pos = $_i; 31 | $this->bb = $_bb; 32 | return $this; 33 | } 34 | 35 | public function getReferToC() 36 | { 37 | $obj = new TableInC(); 38 | $o = $this->__offset(4); 39 | return $o != 0 ? $obj->init($this->__indirect($o + $this->bb_pos), $this->bb) : 0; 40 | } 41 | 42 | /** 43 | * @param FlatBufferBuilder $builder 44 | * @return void 45 | */ 46 | public static function startSecondTableInA(FlatBufferBuilder $builder) 47 | { 48 | $builder->StartObject(1); 49 | } 50 | 51 | /** 52 | * @param FlatBufferBuilder $builder 53 | * @return SecondTableInA 54 | */ 55 | public static function createSecondTableInA(FlatBufferBuilder $builder, $refer_to_c) 56 | { 57 | $builder->startObject(1); 58 | self::addReferToC($builder, $refer_to_c); 59 | $o = $builder->endObject(); 60 | return $o; 61 | } 62 | 63 | /** 64 | * @param FlatBufferBuilder $builder 65 | * @param int 66 | * @return void 67 | */ 68 | public static function addReferToC(FlatBufferBuilder $builder, $referToC) 69 | { 70 | $builder->addOffsetX(0, $referToC, 0); 71 | } 72 | 73 | /** 74 | * @param FlatBufferBuilder $builder 75 | * @return int table offset 76 | */ 77 | public static function endSecondTableInA(FlatBufferBuilder $builder) 78 | { 79 | $o = $builder->endObject(); 80 | return $o; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing {#contributing} 2 | ============ 3 | 4 | Want to contribute? Great! First, read this page (including the small print at 5 | the end). 6 | 7 | # Before you contribute 8 | Before we can use your code, you must sign the 9 | [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1) 10 | (CLA), which you can do online. The CLA is necessary mainly because you own the 11 | copyright to your changes, even after your contribution becomes part of our 12 | codebase, so we need your permission to use and distribute your code. We also 13 | need to be sure of various other things—for instance that you'll tell us if you 14 | know that your code infringes on other people's patents. You don't have to sign 15 | the CLA until after you've submitted your code for review and a member has 16 | approved it, but you must do it before we can put your code into our codebase. 17 | Before you start working on a larger contribution, you should get in touch with 18 | us first through the issue tracker with your idea so that we can help out and 19 | possibly guide you. Coordinating up front makes it much easier to avoid 20 | frustration later on. 21 | 22 | # Code reviews 23 | All submissions, including submissions by project members, require review. We 24 | use Github pull requests for this purpose. 25 | 26 | Some tips for good pull requests: 27 | * Use our code 28 | [style guide](https://google.github.io/styleguide/cppguide.html). 29 | When in doubt, try to stay true to the existing code of the project. 30 | * Write a descriptive commit message. What problem are you solving and what 31 | are the consequences? Where and what did you test? Some good tips: 32 | [here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message) 33 | and [here](https://www.kernel.org/doc/Documentation/SubmittingPatches). 34 | * If your PR consists of multiple commits which are successive improvements / 35 | fixes to your first commit, consider squashing them into a single commit 36 | (`git rebase -i`) such that your PR is a single commit on top of the current 37 | HEAD. This make reviewing the code so much easier, and our history more 38 | readable. 39 | 40 | # The small print 41 | Contributions made by corporations are covered by a different agreement than 42 | the one above, the Software Grant and Corporate Contributor License Agreement. 43 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceC/TableInC.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace NamespaceC 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct TableInC : IFlatbufferObject 12 | { 13 | private Table __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public static TableInC GetRootAsTableInC(ByteBuffer _bb) { return GetRootAsTableInC(_bb, new TableInC()); } 16 | public static TableInC GetRootAsTableInC(ByteBuffer _bb, TableInC obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 17 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 18 | public TableInC __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 19 | 20 | public NamespaceA.TableInFirstNS? ReferToA1 { get { int o = __p.__offset(4); return o != 0 ? (NamespaceA.TableInFirstNS?)(new NamespaceA.TableInFirstNS()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } 21 | public NamespaceA.SecondTableInA? ReferToA2 { get { int o = __p.__offset(6); return o != 0 ? (NamespaceA.SecondTableInA?)(new NamespaceA.SecondTableInA()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } } 22 | 23 | public static Offset CreateTableInC(FlatBufferBuilder builder, 24 | Offset refer_to_a1Offset = default(Offset), 25 | Offset refer_to_a2Offset = default(Offset)) { 26 | builder.StartObject(2); 27 | TableInC.AddReferToA2(builder, refer_to_a2Offset); 28 | TableInC.AddReferToA1(builder, refer_to_a1Offset); 29 | return TableInC.EndTableInC(builder); 30 | } 31 | 32 | public static void StartTableInC(FlatBufferBuilder builder) { builder.StartObject(2); } 33 | public static void AddReferToA1(FlatBufferBuilder builder, Offset referToA1Offset) { builder.AddOffset(0, referToA1Offset.Value, 0); } 34 | public static void AddReferToA2(FlatBufferBuilder builder, Offset referToA2Offset) { builder.AddOffset(1, referToA2Offset.Value, 0); } 35 | public static Offset EndTableInC(FlatBufferBuilder builder) { 36 | int o = builder.EndObject(); 37 | return new Offset(o); 38 | } 39 | }; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /samples/go_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 runs on Mac and Linux. It requires `go` to be installed 18 | # and 'flatc' to be built (using `cmake` in the root directory). 19 | 20 | sampledir=$(cd $(dirname $BASH_SOURCE) && pwd) 21 | rootdir=$(cd $sampledir/.. && pwd) 22 | currentdir=$(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 | # Run `flatc`. Note: This requires you to compile using `cmake` from the 31 | # root `/flatbuffers` directory. 32 | if [ -e ../flatc ]; then 33 | ../flatc --go monster.fbs 34 | elif [ -e ../Debug/flatc ]; then 35 | ../Debug/flatc --go monster.fbs 36 | else 37 | echo 'flatc' could not be found. Make sure to build FlatBuffers from the \ 38 | $rootdir directory. 39 | exit 1 40 | fi 41 | 42 | echo Compiling and running the Go sample. 43 | 44 | # Go requires a particular layout of files in order to link the necessary 45 | # packages. Copy these files to the respective directores to compile the 46 | # sample. 47 | mkdir -p ${sampledir}/go_gen/src/MyGame/Sample 48 | mkdir -p ${sampledir}/go_gen/src/github.com/google/flatbuffers/go 49 | cp MyGame/Sample/*.go ${sampledir}/go_gen/src/MyGame/Sample/ 50 | cp ${sampledir}/../go/* ${sampledir}/go_gen/src/github.com/google/flatbuffers/go 51 | 52 | # Export the `GOPATH`, so that `go` will know which directories to search for 53 | # the libraries. 54 | export GOPATH=${sampledir}/go_gen/ 55 | 56 | # Compile and execute the sample. 57 | go build -o go_sample sample_binary.go 58 | ./go_sample 59 | 60 | # Clean up the temporary files. 61 | rm -rf MyGame/ 62 | rm -rf ${sampledir}/go_gen/ 63 | rm go_sample 64 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Vec3.php: -------------------------------------------------------------------------------- 1 | bb_pos = $_i; 21 | $this->bb = $_bb; 22 | return $this; 23 | } 24 | 25 | /** 26 | * @return float 27 | */ 28 | public function GetX() 29 | { 30 | return $this->bb->getFloat($this->bb_pos + 0); 31 | } 32 | 33 | /** 34 | * @return float 35 | */ 36 | public function GetY() 37 | { 38 | return $this->bb->getFloat($this->bb_pos + 4); 39 | } 40 | 41 | /** 42 | * @return float 43 | */ 44 | public function GetZ() 45 | { 46 | return $this->bb->getFloat($this->bb_pos + 8); 47 | } 48 | 49 | /** 50 | * @return double 51 | */ 52 | public function GetTest1() 53 | { 54 | return $this->bb->getDouble($this->bb_pos + 16); 55 | } 56 | 57 | /** 58 | * @return sbyte 59 | */ 60 | public function GetTest2() 61 | { 62 | return $this->bb->getSbyte($this->bb_pos + 24); 63 | } 64 | 65 | /** 66 | * @return Test 67 | */ 68 | public function getTest3() 69 | { 70 | $obj = new Test(); 71 | $obj->init($this->bb_pos + 26, $this->bb); 72 | return $obj; 73 | } 74 | 75 | 76 | /** 77 | * @return int offset 78 | */ 79 | public static function createVec3(FlatBufferBuilder $builder, $x, $y, $z, $test1, $test2, $test3_a, $test3_b) 80 | { 81 | $builder->prep(16, 32); 82 | $builder->pad(2); 83 | $builder->prep(2, 4); 84 | $builder->pad(1); 85 | $builder->putSbyte($test3_b); 86 | $builder->putShort($test3_a); 87 | $builder->pad(1); 88 | $builder->putSbyte($test2); 89 | $builder->putDouble($test1); 90 | $builder->pad(4); 91 | $builder->putFloat($z); 92 | $builder->putFloat($y); 93 | $builder->putFloat($x); 94 | return $builder->offset(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /CMake/FindFlatBuffers.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Stefan.Eilemann@epfl.ch 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 | # Find the flatbuffers schema compiler 17 | # 18 | # Output Variables: 19 | # * FLATBUFFERS_FLATC_EXECUTABLE the flatc compiler executable 20 | # * FLATBUFFERS_FOUND 21 | # 22 | # Provides: 23 | # * FLATBUFFERS_GENERATE_C_HEADERS(Name ) creates the C++ headers 24 | # for the given flatbuffer schema files. 25 | # Returns the header files in ${Name}_OUTPUTS 26 | 27 | set(FLATBUFFERS_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) 28 | 29 | find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc) 30 | find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h) 31 | 32 | include(FindPackageHandleStandardArgs) 33 | find_package_handle_standard_args(flatbuffers 34 | DEFAULT_MSG FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR) 35 | 36 | if(FLATBUFFERS_FOUND) 37 | function(FLATBUFFERS_GENERATE_C_HEADERS Name) 38 | set(FLATC_OUTPUTS) 39 | foreach(FILE ${ARGN}) 40 | get_filename_component(FLATC_OUTPUT ${FILE} NAME_WE) 41 | set(FLATC_OUTPUT 42 | "${CMAKE_CURRENT_BINARY_DIR}/${FLATC_OUTPUT}_generated.h") 43 | list(APPEND FLATC_OUTPUTS ${FLATC_OUTPUT}) 44 | 45 | add_custom_command(OUTPUT ${FLATC_OUTPUT} 46 | COMMAND ${FLATBUFFERS_FLATC_EXECUTABLE} 47 | ARGS -c -o "${CMAKE_CURRENT_BINARY_DIR}/" ${FILE} 48 | COMMENT "Building C++ header for ${FILE}" 49 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 50 | endforeach() 51 | set(${Name}_OUTPUTS ${FLATC_OUTPUTS} PARENT_SCOPE) 52 | endfunction() 53 | 54 | set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR}) 55 | include_directories(${CMAKE_BINARY_DIR}) 56 | else() 57 | set(FLATBUFFERS_INCLUDE_DIR) 58 | endif() 59 | 60 | include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake") -------------------------------------------------------------------------------- /samples/android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 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 | 17 | LOCAL_PATH := $(call my-dir) 18 | FLATBUFFERS_ROOT_DIR := $(LOCAL_PATH)/../../.. 19 | 20 | # FlatBuffers test 21 | include $(CLEAR_VARS) 22 | 23 | # Include the FlatBuffer utility function to generate header files from schemas. 24 | include $(FLATBUFFERS_ROOT_DIR)/android/jni/include.mk 25 | 26 | LOCAL_MODULE := FlatBufferSample 27 | 28 | # Set up some useful variables to identify schema and output directories and 29 | # schema files. 30 | ANDROID_SAMPLE_GENERATED_OUTPUT_DIR := $(LOCAL_PATH)/gen/include 31 | ANDROID_SAMPLE_SCHEMA_DIR := $(LOCAL_PATH)/schemas 32 | ANDROID_SAMPLE_SCHEMA_FILES := $(ANDROID_SAMPLE_SCHEMA_DIR)/animal.fbs 33 | 34 | LOCAL_C_INCLUDES := $(ANDROID_SAMPLE_GENERATED_OUTPUT_DIR) 35 | 36 | $(info $(LOCAL_C_INCLUDES)) 37 | 38 | LOCAL_SRC_FILES := main.cpp 39 | 40 | LOCAL_CPPFLAGS := -std=c++11 -fexceptions -Wall -Wno-literal-suffix 41 | LOCAL_LDLIBS := -llog -landroid 42 | LOCAL_ARM_MODE := arm 43 | LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers 44 | 45 | ifeq (,$(ANDROID_SAMPLE_RUN_ONCE)) 46 | ANDROID_SAMPLE_RUN_ONCE := 1 47 | $(call flatbuffers_header_build_rules,$(ANDROID_SAMPLE_SCHEMA_FILES),$(ANDROID_SAMPLE_SCHEMA_DIR),$(ANDROID_SAMPLE_GENERATED_OUTPUT_DIR),,$(LOCAL_SRC_FILES)) 48 | endif 49 | 50 | include $(BUILD_SHARED_LIBRARY) 51 | 52 | # Path to Flatbuffers root directory. 53 | $(call import-add-path,$(FLATBUFFERS_ROOT_DIR)/..) 54 | 55 | $(call import-module,flatbuffers/android/jni) 56 | $(call import-module,android/native_app_glue) 57 | -------------------------------------------------------------------------------- /tests/namespace_test/NamespaceA/TableInFirstNS.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 | 9 | type TableInFirstNS struct { 10 | _tab flatbuffers.Table 11 | } 12 | 13 | func GetRootAsTableInFirstNS(buf []byte, offset flatbuffers.UOffsetT) *TableInFirstNS { 14 | n := flatbuffers.GetUOffsetT(buf[offset:]) 15 | x := &TableInFirstNS{} 16 | x.Init(buf, n+offset) 17 | return x 18 | } 19 | 20 | func (rcv *TableInFirstNS) Init(buf []byte, i flatbuffers.UOffsetT) { 21 | rcv._tab.Bytes = buf 22 | rcv._tab.Pos = i 23 | } 24 | 25 | func (rcv *TableInFirstNS) Table() flatbuffers.Table { 26 | return rcv._tab 27 | } 28 | 29 | func (rcv *TableInFirstNS) FooTable(obj *TableInNestedNS) *TableInNestedNS { 30 | o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) 31 | if o != 0 { 32 | x := rcv._tab.Indirect(o + rcv._tab.Pos) 33 | if obj == nil { 34 | obj = new(TableInNestedNS) 35 | } 36 | obj.Init(rcv._tab.Bytes, x) 37 | return obj 38 | } 39 | return nil 40 | } 41 | 42 | func (rcv *TableInFirstNS) FooEnum() int8 { 43 | o := flatbuffers.UOffsetT(rcv._tab.Offset(6)) 44 | if o != 0 { 45 | return rcv._tab.GetInt8(o + rcv._tab.Pos) 46 | } 47 | return 0 48 | } 49 | 50 | func (rcv *TableInFirstNS) MutateFooEnum(n int8) bool { 51 | return rcv._tab.MutateInt8Slot(6, n) 52 | } 53 | 54 | func (rcv *TableInFirstNS) FooStruct(obj *StructInNestedNS) *StructInNestedNS { 55 | o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) 56 | if o != 0 { 57 | x := o + rcv._tab.Pos 58 | if obj == nil { 59 | obj = new(StructInNestedNS) 60 | } 61 | obj.Init(rcv._tab.Bytes, x) 62 | return obj 63 | } 64 | return nil 65 | } 66 | 67 | func TableInFirstNSStart(builder *flatbuffers.Builder) { 68 | builder.StartObject(3) 69 | } 70 | func TableInFirstNSAddFooTable(builder *flatbuffers.Builder, fooTable flatbuffers.UOffsetT) { 71 | builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(fooTable), 0) 72 | } 73 | func TableInFirstNSAddFooEnum(builder *flatbuffers.Builder, fooEnum int8) { 74 | builder.PrependInt8Slot(1, fooEnum, 0) 75 | } 76 | func TableInFirstNSAddFooStruct(builder *flatbuffers.Builder, fooStruct flatbuffers.UOffsetT) { 77 | builder.PrependStructSlot(2, flatbuffers.UOffsetT(fooStruct), 0) 78 | } 79 | func TableInFirstNSEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { 80 | return builder.EndObject() 81 | } 82 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Vec3.go: -------------------------------------------------------------------------------- 1 | // automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | package Example 4 | 5 | import ( 6 | flatbuffers "github.com/google/flatbuffers/go" 7 | ) 8 | 9 | type Vec3 struct { 10 | _tab flatbuffers.Struct 11 | } 12 | 13 | func (rcv *Vec3) Init(buf []byte, i flatbuffers.UOffsetT) { 14 | rcv._tab.Bytes = buf 15 | rcv._tab.Pos = i 16 | } 17 | 18 | func (rcv *Vec3) Table() flatbuffers.Table { 19 | return rcv._tab.Table 20 | } 21 | 22 | func (rcv *Vec3) X() float32 { 23 | return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(0)) 24 | } 25 | func (rcv *Vec3) MutateX(n float32) bool { 26 | return rcv._tab.MutateFloat32(rcv._tab.Pos+flatbuffers.UOffsetT(0), n) 27 | } 28 | 29 | func (rcv *Vec3) Y() float32 { 30 | return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(4)) 31 | } 32 | func (rcv *Vec3) MutateY(n float32) bool { 33 | return rcv._tab.MutateFloat32(rcv._tab.Pos+flatbuffers.UOffsetT(4), n) 34 | } 35 | 36 | func (rcv *Vec3) Z() float32 { 37 | return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(8)) 38 | } 39 | func (rcv *Vec3) MutateZ(n float32) bool { 40 | return rcv._tab.MutateFloat32(rcv._tab.Pos+flatbuffers.UOffsetT(8), n) 41 | } 42 | 43 | func (rcv *Vec3) Test1() float64 { 44 | return rcv._tab.GetFloat64(rcv._tab.Pos + flatbuffers.UOffsetT(16)) 45 | } 46 | func (rcv *Vec3) MutateTest1(n float64) bool { 47 | return rcv._tab.MutateFloat64(rcv._tab.Pos+flatbuffers.UOffsetT(16), n) 48 | } 49 | 50 | func (rcv *Vec3) Test2() int8 { 51 | return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(24)) 52 | } 53 | func (rcv *Vec3) MutateTest2(n int8) bool { 54 | return rcv._tab.MutateInt8(rcv._tab.Pos+flatbuffers.UOffsetT(24), n) 55 | } 56 | 57 | func (rcv *Vec3) Test3(obj *Test) *Test { 58 | if obj == nil { 59 | obj = new(Test) 60 | } 61 | obj.Init(rcv._tab.Bytes, rcv._tab.Pos+26) 62 | return obj 63 | } 64 | 65 | func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 int8, test3_a int16, test3_b int8) flatbuffers.UOffsetT { 66 | builder.Prep(16, 32) 67 | builder.Pad(2) 68 | builder.Prep(2, 4) 69 | builder.Pad(1) 70 | builder.PrependInt8(test3_b) 71 | builder.PrependInt16(test3_a) 72 | builder.Pad(1) 73 | builder.PrependInt8(test2) 74 | builder.PrependFloat64(test1) 75 | builder.Pad(4) 76 | builder.PrependFloat32(z) 77 | builder.PrependFloat32(y) 78 | builder.PrependFloat32(x) 79 | return builder.Offset() 80 | } 81 | -------------------------------------------------------------------------------- /android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 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 | 17 | LOCAL_PATH := $(call my-dir)/../.. 18 | 19 | include $(LOCAL_PATH)/android/jni/include.mk 20 | LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH)) 21 | 22 | # Empty static library so that other projects can include just the basic 23 | # FlatBuffers headers as a module. 24 | include $(CLEAR_VARS) 25 | LOCAL_MODULE := flatbuffers 26 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 27 | LOCAL_EXPORT_CPPFLAGS := -std=c++11 -fexceptions -Wall \ 28 | -DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE 29 | 30 | include $(BUILD_STATIC_LIBRARY) 31 | 32 | # static library that additionally includes text parsing/generation/reflection 33 | # for projects that want richer functionality. 34 | include $(CLEAR_VARS) 35 | LOCAL_MODULE := flatbuffers_extra 36 | LOCAL_SRC_FILES := src/idl_parser.cpp \ 37 | src/idl_gen_text.cpp \ 38 | src/reflection.cpp \ 39 | src/util.cpp \ 40 | src/code_generators.cpp 41 | LOCAL_STATIC_LIBRARIES := flatbuffers 42 | include $(BUILD_STATIC_LIBRARY) 43 | 44 | # FlatBuffers test 45 | include $(CLEAR_VARS) 46 | LOCAL_MODULE := FlatBufferTest 47 | LOCAL_SRC_FILES := android/jni/main.cpp \ 48 | tests/test.cpp \ 49 | src/idl_gen_fbs.cpp \ 50 | src/idl_gen_general.cpp 51 | LOCAL_LDLIBS := -llog -landroid 52 | LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers_extra 53 | LOCAL_ARM_MODE := arm 54 | include $(BUILD_SHARED_LIBRARY) 55 | 56 | $(call import-module,android/native_app_glue) 57 | 58 | $(call import-add-path,$(LOCAL_PATH)/../..) 59 | -------------------------------------------------------------------------------- /android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/MyGame/Example/Stat.cs: -------------------------------------------------------------------------------- 1 | // 2 | // automatically generated by the FlatBuffers compiler, do not modify 3 | // 4 | 5 | namespace MyGame.Example 6 | { 7 | 8 | using global::System; 9 | using global::FlatBuffers; 10 | 11 | public struct Stat : IFlatbufferObject 12 | { 13 | private Table __p; 14 | public ByteBuffer ByteBuffer { get { return __p.bb; } } 15 | public static Stat GetRootAsStat(ByteBuffer _bb) { return GetRootAsStat(_bb, new Stat()); } 16 | public static Stat GetRootAsStat(ByteBuffer _bb, Stat obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } 17 | public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } 18 | public Stat __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } 19 | 20 | public string Id { get { int o = __p.__offset(4); return o != 0 ? __p.__string(o + __p.bb_pos) : null; } } 21 | public ArraySegment? GetIdBytes() { return __p.__vector_as_arraysegment(4); } 22 | public long Val { get { int o = __p.__offset(6); return o != 0 ? __p.bb.GetLong(o + __p.bb_pos) : (long)0; } } 23 | public bool MutateVal(long val) { int o = __p.__offset(6); if (o != 0) { __p.bb.PutLong(o + __p.bb_pos, val); return true; } else { return false; } } 24 | public ushort Count { get { int o = __p.__offset(8); return o != 0 ? __p.bb.GetUshort(o + __p.bb_pos) : (ushort)0; } } 25 | public bool MutateCount(ushort count) { int o = __p.__offset(8); if (o != 0) { __p.bb.PutUshort(o + __p.bb_pos, count); return true; } else { return false; } } 26 | 27 | public static Offset CreateStat(FlatBufferBuilder builder, 28 | StringOffset idOffset = default(StringOffset), 29 | long val = 0, 30 | ushort count = 0) { 31 | builder.StartObject(3); 32 | Stat.AddVal(builder, val); 33 | Stat.AddId(builder, idOffset); 34 | Stat.AddCount(builder, count); 35 | return Stat.EndStat(builder); 36 | } 37 | 38 | public static void StartStat(FlatBufferBuilder builder) { builder.StartObject(3); } 39 | public static void AddId(FlatBufferBuilder builder, StringOffset idOffset) { builder.AddOffset(0, idOffset.Value, 0); } 40 | public static void AddVal(FlatBufferBuilder builder, long val) { builder.AddLong(1, val, 0); } 41 | public static void AddCount(FlatBufferBuilder builder, ushort count) { builder.AddUshort(2, count, 0); } 42 | public static Offset EndStat(FlatBufferBuilder builder) { 43 | int o = builder.EndObject(); 44 | return new Offset(o); 45 | } 46 | }; 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /samples/android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /reflection/reflection.fbs: -------------------------------------------------------------------------------- 1 | // This schema defines objects that represent a parsed schema, like 2 | // the binary version of a .fbs file. 3 | // This could be used to operate on unknown FlatBuffers at runtime. 4 | // It can even ... represent itself (!) 5 | 6 | namespace reflection; 7 | 8 | // These must correspond to the enum in idl.h. 9 | enum BaseType : byte { 10 | None, 11 | UType, 12 | Bool, 13 | Byte, 14 | UByte, 15 | Short, 16 | UShort, 17 | Int, 18 | UInt, 19 | Long, 20 | ULong, 21 | Float, 22 | Double, 23 | String, 24 | Vector, 25 | Obj, // Used for tables & structs. 26 | Union 27 | } 28 | 29 | table Type { 30 | base_type:BaseType; 31 | element:BaseType = None; // Only if base_type == Vector. 32 | index:int = -1; // If base_type == Object, index into "objects" below. 33 | // If base_type == Union, UnionType, or integral derived 34 | // from an enum, index into "enums" below. 35 | } 36 | 37 | table KeyValue { 38 | key:string (required, key); 39 | value:string; 40 | } 41 | 42 | table EnumVal { 43 | name:string (required); 44 | value:long (key); 45 | object:Object; // Will be deprecated in favor of union_type in the future. 46 | union_type:Type; 47 | } 48 | 49 | table Enum { 50 | name:string (required, key); 51 | values:[EnumVal] (required); // In order of their values. 52 | is_union:bool = false; 53 | underlying_type:Type (required); 54 | attributes:[KeyValue]; 55 | documentation:[string]; 56 | } 57 | 58 | table Field { 59 | name:string (required, key); 60 | type:Type (required); 61 | id:ushort; 62 | offset:ushort; // Offset into the vtable for tables, or into the struct. 63 | default_integer:long = 0; 64 | default_real:double = 0.0; 65 | deprecated:bool = false; 66 | required:bool = false; 67 | key:bool = false; 68 | attributes:[KeyValue]; 69 | documentation:[string]; 70 | } 71 | 72 | table Object { // Used for both tables and structs. 73 | name:string (required, key); 74 | fields:[Field] (required); // Sorted. 75 | is_struct:bool = false; 76 | minalign:int; 77 | bytesize:int; // For structs. 78 | attributes:[KeyValue]; 79 | documentation:[string]; 80 | } 81 | 82 | table Schema { 83 | objects:[Object] (required); // Sorted. 84 | enums:[Enum] (required); // Sorted. 85 | file_ident:string; 86 | file_ext:string; 87 | root_table:Object; 88 | } 89 | 90 | root_type Schema; 91 | 92 | file_identifier "BFBS"; 93 | file_extension "bfbs"; 94 | -------------------------------------------------------------------------------- /net/FlatBuffers/FlatBuffers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {28C00774-1E73-4A75-AD8F-844CD21A064D} 8 | Library 9 | Properties 10 | FlatBuffers 11 | FlatBuffers 12 | v3.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | --------------------------------------------------------------------------------