diff --git a/docs/html/index.html b/docs/html/index.html index 07d36bbc2..634adef3a 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -97,6 +97,7 @@ $(document).ready(function(){initNavTree('index.html','');});
  • How to use the generated C++ code in your own programs.
  • How to use the generated Java/C# code in your own programs.
  • How to use the generated Go code in your own programs.
  • +
  • Support matrix for platforms/languages/features.
  • Some benchmarks showing the advantage of using FlatBuffers.
  • A white paper explaining the "why" of FlatBuffers.
  • A description of the internals of FlatBuffers.
  • diff --git a/docs/html/md__support.html b/docs/html/md__support.html new file mode 100644 index 000000000..5ac173fda --- /dev/null +++ b/docs/html/md__support.html @@ -0,0 +1,122 @@ + + + + + + + +FlatBuffers: Platform / Language / Feature support + + + + + + + + + + + +
    +
    + + + + + + + +
    +
    FlatBuffers +
    +
    + An open source project by FPL. +
    +
    +
    + + +
    +
    + +
    +
    +
    + +
    +
    +
    +
    Platform / Language / Feature support
    +
    +
    +

    FlatBuffers is actively being worked on, which means that certain platform / language / feature combinations may not be available yet.

    +

    This page tries to track those issues, to make informed decisions easier. In general:

    +
      +
    • Languages: language support beyond the ones created by the original FlatBuffer authors typically depends on community contributions.
    • +
    • Features: C++ was the first language supported, since our original target was high performance game development. It thus has the richest feature set, and is likely most robust. Other languages are catching up however.
    • +
    • Platforms: All language implementations are typically portable to most platforms, unless where noted otherwise.
    • +
    +

    NOTE: this table is a start, it needs to be extended.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Feature C++ Java C# Go Python JS
    Codegen for all basic features Yes Yes Yes Yes Yes WIP
    JSON parsing Yes No No No No No
    Simple mutation Yes WIP WIP No No No
    Reflection Yes No No No No No
    Buffer verifier Yes No No No No No
    Testing: basic Yes Yes Yes Yes Yes WIP
    Testing: fuzz Yes No No Yes Yes No
    Performance: Superb Great Great Great Ok ?
    Platform: Windows VS2010 Yes Yes ? ? ?
    Platform: Linux GCC282 Yes ? Yes Yes ?
    Platform: OS X Xcode4 ? ? ? Yes ?
    Platform: Android NDK10d Yes ? ? ? ?
    Platform: iOS ? ? ? ? ? ?
    Engine: Unity ? ? Yes ? ? ?
    Primary authors (github) wvo wvo (ev/js)rw rw (ev)
    +
      +
    • ev = evolutional
    • +
    • js = jonsimantov
    • +
    +
    +
    + + + + diff --git a/docs/html/navtree.js b/docs/html/navtree.js index 58fba48ab..0bbc4dc2a 100644 --- a/docs/html/navtree.js +++ b/docs/html/navtree.js @@ -8,6 +8,7 @@ var NAVTREE = [ "Use in Go", "md__go_usage.html", null ], [ "Use in Java/C-sharp", "md__java_usage.html", null ], [ "Use in Python", "md__python_usage.html", null ], + [ "Platform / Language / Feature support", "md__support.html", null ], [ "Benchmarks", "md__benchmarks.html", null ], [ "FlatBuffers white paper", "md__white_paper.html", null ], [ "FlatBuffer Internals", "md__internals.html", null ], diff --git a/docs/html/navtreeindex0.js b/docs/html/navtreeindex0.js index 92e8403cd..912552ff2 100644 --- a/docs/html/navtreeindex0.js +++ b/docs/html/navtreeindex0.js @@ -1,16 +1,17 @@ var NAVTREEINDEX0 = { "index.html":[], -"md__benchmarks.html":[7], +"md__benchmarks.html":[8], "md__building.html":[0], "md__compiler.html":[1], "md__cpp_usage.html":[3], "md__go_usage.html":[4], -"md__grammar.html":[10], -"md__internals.html":[9], +"md__grammar.html":[11], +"md__internals.html":[10], "md__java_usage.html":[5], "md__python_usage.html":[6], "md__schemas.html":[2], -"md__white_paper.html":[8], +"md__support.html":[7], +"md__white_paper.html":[9], "pages.html":[] }; diff --git a/docs/html/pages.html b/docs/html/pages.html index 5cefb95b2..fef29f969 100644 --- a/docs/html/pages.html +++ b/docs/html/pages.html @@ -70,10 +70,11 @@ $(document).ready(function(){initNavTree('pages.html','');});  Use in Go  Use in Java/C-sharp  Use in Python - Benchmarks - FlatBuffers white paper - FlatBuffer Internals - Grammar of the schema language + Platform / Language / Feature support + Benchmarks + FlatBuffers white paper + FlatBuffer Internals + Grammar of the schema language diff --git a/docs/source/FlatBuffers.md b/docs/source/FlatBuffers.md index 8e78337f4..b77086951 100644 --- a/docs/source/FlatBuffers.md +++ b/docs/source/FlatBuffers.md @@ -115,6 +115,7 @@ sections provide a more in-depth usage guide. programs. - How to [use the generated Go code](md__go_usage.html) in your own programs. +- [Support matrix](md__support.html) for platforms/languages/features. - Some [benchmarks](md__benchmarks.html) showing the advantage of using FlatBuffers. - A [white paper](md__white_paper.html) explaining the "why" of FlatBuffers. diff --git a/docs/source/Support.md b/docs/source/Support.md new file mode 100755 index 000000000..6271bfefd --- /dev/null +++ b/docs/source/Support.md @@ -0,0 +1,39 @@ +# Platform / Language / Feature support + +FlatBuffers is actively being worked on, which means that certain platform / +language / feature combinations may not be available yet. + +This page tries to track those issues, to make informed decisions easier. +In general: + + * Languages: language support beyond the ones created by the original + FlatBuffer authors typically depends on community contributions. + * Features: C++ was the first language supported, since our original + target was high performance game development. It thus has the richest + feature set, and is likely most robust. Other languages are catching up + however. + * Platforms: All language implementations are typically portable to most + platforms, unless where noted otherwise. + +NOTE: this table is a start, it needs to be extended. + +Feature | C++ | Java | C# | Go | Python | JS +------------------------------ | ------ | ------ | ------ | ------ | ------ | ------ +Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | WIP +JSON parsing | Yes | No | No | No | No | No +Simple mutation | Yes | WIP | WIP | No | No | No +Reflection | Yes | No | No | No | No | No +Buffer verifier | Yes | No | No | No | No | No +Testing: basic | Yes | Yes | Yes | Yes | Yes | WIP +Testing: fuzz | Yes | No | No | Yes | Yes | No +Performance: | Superb | Great | Great | Great | Ok | ? +Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? +Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? +Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? +Platform: Android | NDK10d | Yes | ? | ? | ? | ? +Platform: iOS | ? | ? | ? | ? | ? | ? +Engine: Unity | ? | ? | Yes | ? | ? | ? +Primary authors (github) | wvo | wvo | (ev/js)| rw | rw | (ev) + + * ev = evolutional + * js = jonsimantov diff --git a/docs/source/doxyfile b/docs/source/doxyfile index 808c77c56..2cb373bc6 100755 --- a/docs/source/doxyfile +++ b/docs/source/doxyfile @@ -751,6 +751,7 @@ INPUT = "FlatBuffers.md" \ "GoUsage.md" \ "JavaUsage.md" \ "PythonUsage.md" \ + "Support.md" \ "Benchmarks.md" \ "WhitePaper.md" \ "Internals.md" \ diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index 86440b153..936fc5eef 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -870,7 +870,15 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser, // Java doesn't have defaults, which means this method must always // supply all arguments, and thus won't compile when fields are added. if (lang.language != GeneratorOptions::kJava) { - code += " = " + GenDefaultValue(lang, field.value, false); + code += " = "; + // in C#, enum values have their own type, so we need to cast the + // numeric value to the proper type + if (lang.language == GeneratorOptions::kCSharp && + field.value.type.enum_def != nullptr && + field.value.type.base_type != BASE_TYPE_UNION) { + code += "(" + field.value.type.enum_def->name + ")"; + } + code += GenDefaultValue(lang, field.value, false); } } code += ") {\n builder."; diff --git a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj index fd1c60205..bfc0fe18a 100644 --- a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj +++ b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj @@ -71,6 +71,9 @@ MyGame\Example\Test.cs + + MyGame\Example\TestSimpleTableWithEnum.cs + MyGame\Example\Vec3.cs diff --git a/tests/MyGame/Example/Any.cs b/tests/MyGame/Example/Any.cs index b7a5b3614..a05a91851 100644 --- a/tests/MyGame/Example/Any.cs +++ b/tests/MyGame/Example/Any.cs @@ -7,6 +7,7 @@ public enum Any : byte { NONE = 0, Monster = 1, + TestSimpleTableWithEnum = 2, }; diff --git a/tests/MyGame/Example/Any.go b/tests/MyGame/Example/Any.go index 0039bb8c0..a23de4cbc 100644 --- a/tests/MyGame/Example/Any.go +++ b/tests/MyGame/Example/Any.go @@ -5,4 +5,5 @@ package Example const ( AnyNONE = 0 AnyMonster = 1 + AnyTestSimpleTableWithEnum = 2 ) diff --git a/tests/MyGame/Example/Any.java b/tests/MyGame/Example/Any.java index f811f973f..cdc3ec567 100644 --- a/tests/MyGame/Example/Any.java +++ b/tests/MyGame/Example/Any.java @@ -6,8 +6,9 @@ public final class Any { private Any() { } public static final byte NONE = 0; public static final byte Monster = 1; + public static final byte TestSimpleTableWithEnum = 2; - private static final String[] names = { "NONE", "Monster", }; + private static final String[] names = { "NONE", "Monster", "TestSimpleTableWithEnum", }; public static String name(int e) { return names[e]; } }; diff --git a/tests/MyGame/Example/Any.py b/tests/MyGame/Example/Any.py index c88362ece..a247b528c 100644 --- a/tests/MyGame/Example/Any.py +++ b/tests/MyGame/Example/Any.py @@ -5,4 +5,5 @@ class Any(object): NONE = 0 Monster = 1 + TestSimpleTableWithEnum = 2 diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.cs b/tests/MyGame/Example/TestSimpleTableWithEnum.cs new file mode 100644 index 000000000..d2e75b52f --- /dev/null +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.cs @@ -0,0 +1,31 @@ +// automatically generated, do not modify + +namespace MyGame.Example +{ + +using FlatBuffers; + +public sealed class TestSimpleTableWithEnum : Table { + public static TestSimpleTableWithEnum GetRootAsTestSimpleTableWithEnum(ByteBuffer _bb) { return GetRootAsTestSimpleTableWithEnum(_bb, new TestSimpleTableWithEnum()); } + public static TestSimpleTableWithEnum GetRootAsTestSimpleTableWithEnum(ByteBuffer _bb, TestSimpleTableWithEnum obj) { return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } + public TestSimpleTableWithEnum __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } + + public Color Color { get { int o = __offset(4); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : (Color)2; } } + + public static Offset CreateTestSimpleTableWithEnum(FlatBufferBuilder builder, + Color color = (Color)2) { + builder.StartObject(1); + TestSimpleTableWithEnum.AddColor(builder, color); + return TestSimpleTableWithEnum.EndTestSimpleTableWithEnum(builder); + } + + public static void StartTestSimpleTableWithEnum(FlatBufferBuilder builder) { builder.StartObject(1); } + public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)(color), 2); } + public static Offset EndTestSimpleTableWithEnum(FlatBufferBuilder builder) { + int o = builder.EndObject(); + return new Offset(o); + } +}; + + +} diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.go b/tests/MyGame/Example/TestSimpleTableWithEnum.go new file mode 100644 index 000000000..a26a53e46 --- /dev/null +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.go @@ -0,0 +1,27 @@ +// automatically generated, do not modify + +package Example + +import ( + flatbuffers "github.com/google/flatbuffers/go" +) +type TestSimpleTableWithEnum struct { + _tab flatbuffers.Table +} + +func (rcv *TestSimpleTableWithEnum) Init(buf []byte, i flatbuffers.UOffsetT) { + rcv._tab.Bytes = buf + rcv._tab.Pos = i +} + +func (rcv *TestSimpleTableWithEnum) Color() int8 { + o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) + if o != 0 { + return rcv._tab.GetInt8(o + rcv._tab.Pos) + } + return 2 +} + +func TestSimpleTableWithEnumStart(builder *flatbuffers.Builder) { builder.StartObject(1) } +func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color int8) { builder.PrependInt8Slot(0, color, 2) } +func TestSimpleTableWithEnumEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.java b/tests/MyGame/Example/TestSimpleTableWithEnum.java new file mode 100644 index 000000000..af9d7dbff --- /dev/null +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.java @@ -0,0 +1,31 @@ +// automatically generated, do not modify + +package MyGame.Example; + +import java.nio.*; +import java.lang.*; +import java.util.*; +import com.google.flatbuffers.*; + +public final class TestSimpleTableWithEnum extends Table { + public static TestSimpleTableWithEnum getRootAsTestSimpleTableWithEnum(ByteBuffer _bb) { return getRootAsTestSimpleTableWithEnum(_bb, new TestSimpleTableWithEnum()); } + public static TestSimpleTableWithEnum getRootAsTestSimpleTableWithEnum(ByteBuffer _bb, TestSimpleTableWithEnum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__init(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } + public TestSimpleTableWithEnum __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } + + public byte color() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) : 2; } + + public static int createTestSimpleTableWithEnum(FlatBufferBuilder builder, + byte color) { + builder.startObject(1); + TestSimpleTableWithEnum.addColor(builder, color); + return TestSimpleTableWithEnum.endTestSimpleTableWithEnum(builder); + } + + public static void startTestSimpleTableWithEnum(FlatBufferBuilder builder) { builder.startObject(1); } + public static void addColor(FlatBufferBuilder builder, byte color) { builder.addByte(0, color, 2); } + public static int endTestSimpleTableWithEnum(FlatBufferBuilder builder) { + int o = builder.endObject(); + return o; + } +}; + diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.py b/tests/MyGame/Example/TestSimpleTableWithEnum.py new file mode 100644 index 000000000..7085995be --- /dev/null +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.py @@ -0,0 +1,23 @@ +# automatically generated, do not modify + +# namespace: Example + +import flatbuffers + +class TestSimpleTableWithEnum(object): + __slots__ = ['_tab'] + + # TestSimpleTableWithEnum + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # TestSimpleTableWithEnum + def Color(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 2 + +def TestSimpleTableWithEnumStart(builder): builder.StartObject(1) +def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependInt8Slot(0, color, 2) +def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() diff --git a/tests/monster_test.fbs b/tests/monster_test.fbs index 53fa87b81..6a205b057 100755 --- a/tests/monster_test.fbs +++ b/tests/monster_test.fbs @@ -8,10 +8,14 @@ attribute "priority"; enum Color:byte (bit_flags) { Red = 0, Green, Blue = 3, } -union Any { Monster } // TODO: add more elements +union Any { Monster, TestSimpleTableWithEnum } // TODO: add more elements struct Test { a:short; b:byte; } +table TestSimpleTableWithEnum { + color: Color = Green; +} + struct Vec3 (force_align: 16) { x:float; y:float; diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index 7fb698b06..93262ddde 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -15,6 +15,7 @@ namespace MyGame { namespace Example { struct Test; +struct TestSimpleTableWithEnum; struct Vec3; struct Stat; struct Monster; @@ -34,11 +35,12 @@ inline const char *EnumNameColor(Color e) { return EnumNamesColor()[e - Color_Re enum Any { Any_NONE = 0, - Any_Monster = 1 + Any_Monster = 1, + Any_TestSimpleTableWithEnum = 2 }; inline const char **EnumNamesAny() { - static const char *names[] = { "NONE", "Monster", nullptr }; + static const char *names[] = { "NONE", "Monster", "TestSimpleTableWithEnum", nullptr }; return names; } @@ -94,6 +96,35 @@ MANUALLY_ALIGNED_STRUCT(16) Vec3 FLATBUFFERS_FINAL_CLASS { }; STRUCT_END(Vec3, 32); +struct TestSimpleTableWithEnum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + Color color() const { return static_cast(GetField(4, 2)); } + bool mutate_color(Color color) { return SetField(4, static_cast(color)); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* color */) && + verifier.EndTable(); + } +}; + +struct TestSimpleTableWithEnumBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_color(Color color) { fbb_.AddElement(4, static_cast(color), 2); } + TestSimpleTableWithEnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + TestSimpleTableWithEnumBuilder &operator=(const TestSimpleTableWithEnumBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 1)); + return o; + } +}; + +inline flatbuffers::Offset CreateTestSimpleTableWithEnum(flatbuffers::FlatBufferBuilder &_fbb, + Color color = Color_Green) { + TestSimpleTableWithEnumBuilder builder_(_fbb); + builder_.add_color(color); + return builder_.Finish(); +} + struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::String *id() const { return GetPointer(4); } flatbuffers::String *mutable_id() { return GetPointer(4); } @@ -318,6 +349,7 @@ inline bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, An switch (type) { case Any_NONE: return true; case Any_Monster: return verifier.VerifyTable(reinterpret_cast(union_obj)); + case Any_TestSimpleTableWithEnum: return verifier.VerifyTable(reinterpret_cast(union_obj)); default: return false; } }