From 02dfa64a89f46588c6de34e59a310fab98e73f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Fern=C3=A1ndez?= Date: Fri, 9 Sep 2016 15:25:09 +0200 Subject: [PATCH] Allow access to underlying ByteBuffer --- .../{IFlatbufferObject .cs => IFlatbufferObject.cs} | 2 ++ src/idl_gen_general.cpp | 5 +++++ tests/FlatBuffers.Test/FlatBuffers.Test.csproj | 6 +++--- tests/MyGame/Example/Monster.cs | 1 + tests/MyGame/Example/Stat.cs | 1 + tests/MyGame/Example/Test.cs | 1 + tests/MyGame/Example/TestSimpleTableWithEnum.cs | 1 + tests/MyGame/Example/Vec3.cs | 1 + tests/MyGame/Example2/Monster.cs | 1 + tests/generate_code.sh | 0 .../NamespaceA/NamespaceB/StructInNestedNS.cs | 1 + .../namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs | 1 + tests/namespace_test/NamespaceA/SecondTableInA.cs | 1 + tests/namespace_test/NamespaceA/TableInFirstNS.cs | 1 + tests/namespace_test/NamespaceC/TableInC.cs | 1 + 15 files changed, 21 insertions(+), 3 deletions(-) rename net/FlatBuffers/{IFlatbufferObject .cs => IFlatbufferObject.cs} (95%) mode change 100644 => 100755 tests/generate_code.sh diff --git a/net/FlatBuffers/IFlatbufferObject .cs b/net/FlatBuffers/IFlatbufferObject.cs similarity index 95% rename from net/FlatBuffers/IFlatbufferObject .cs rename to net/FlatBuffers/IFlatbufferObject.cs index fb6dc5b24..6a15aba6e 100644 --- a/net/FlatBuffers/IFlatbufferObject .cs +++ b/net/FlatBuffers/IFlatbufferObject.cs @@ -22,5 +22,7 @@ namespace FlatBuffers public interface IFlatbufferObject { void __init(int _i, ByteBuffer _bb); + + ByteBuffer ByteBuffer { get; } } } diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index 0cbc9edc3..30899d4d4 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -804,6 +804,11 @@ void GenStruct(StructDef &struct_def, std::string *code_ptr) { code += " private "; code += struct_def.fixed ? "Struct" : "Table"; code += " __p;\n"; + + if (lang_.language == IDLOptions::kCSharp) { + code += " public ByteBuffer ByteBuffer { get { return __p.bb; } }\n"; + } + } else { code += lang_.inheritance_marker; code += struct_def.fixed ? "Struct" : "Table"; diff --git a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj index efdd29a75..6e76b07f1 100644 --- a/tests/FlatBuffers.Test/FlatBuffers.Test.csproj +++ b/tests/FlatBuffers.Test/FlatBuffers.Test.csproj @@ -41,8 +41,8 @@ FlatBuffers\ByteBuffer.cs - - FlatBuffers\IFlatbufferObject .cs + + FlatBuffers\IFlatbufferObject.cs FlatBuffers\Offset.cs @@ -119,4 +119,4 @@ --> - \ No newline at end of file + diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs index 222fc5e79..30f49221e 100644 --- a/tests/MyGame/Example/Monster.cs +++ b/tests/MyGame/Example/Monster.cs @@ -10,6 +10,7 @@ using FlatBuffers; public struct Monster : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); } public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public static bool MonsterBufferHasIdentifier(ByteBuffer _bb) { return Table.__has_identifier(_bb, "MONS"); } diff --git a/tests/MyGame/Example/Stat.cs b/tests/MyGame/Example/Stat.cs index b73dc16a0..0fb5bd0f2 100644 --- a/tests/MyGame/Example/Stat.cs +++ b/tests/MyGame/Example/Stat.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct Stat : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static Stat GetRootAsStat(ByteBuffer _bb) { return GetRootAsStat(_bb, new Stat()); } public static Stat GetRootAsStat(ByteBuffer _bb, Stat obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } diff --git a/tests/MyGame/Example/Test.cs b/tests/MyGame/Example/Test.cs index 08c669bf3..92c3b912c 100644 --- a/tests/MyGame/Example/Test.cs +++ b/tests/MyGame/Example/Test.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct Test : IFlatbufferObject { private Struct __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } public Test __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.cs b/tests/MyGame/Example/TestSimpleTableWithEnum.cs index 0b775ab16..bff386407 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.cs +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.cs @@ -9,6 +9,7 @@ using FlatBuffers; public partial struct TestSimpleTableWithEnum : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static TestSimpleTableWithEnum GetRootAsTestSimpleTableWithEnum(ByteBuffer _bb) { return GetRootAsTestSimpleTableWithEnum(_bb, new TestSimpleTableWithEnum()); } public static TestSimpleTableWithEnum GetRootAsTestSimpleTableWithEnum(ByteBuffer _bb, TestSimpleTableWithEnum obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } diff --git a/tests/MyGame/Example/Vec3.cs b/tests/MyGame/Example/Vec3.cs index 2cafbcc5a..055254343 100644 --- a/tests/MyGame/Example/Vec3.cs +++ b/tests/MyGame/Example/Vec3.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct Vec3 : IFlatbufferObject { private Struct __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } public Vec3 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } diff --git a/tests/MyGame/Example2/Monster.cs b/tests/MyGame/Example2/Monster.cs index 64a5836d2..6b1602edb 100644 --- a/tests/MyGame/Example2/Monster.cs +++ b/tests/MyGame/Example2/Monster.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct Monster : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static Monster GetRootAsMonster(ByteBuffer _bb) { return GetRootAsMonster(_bb, new Monster()); } public static Monster GetRootAsMonster(ByteBuffer _bb, Monster obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } diff --git a/tests/generate_code.sh b/tests/generate_code.sh old mode 100644 new mode 100755 diff --git a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs index 81b57f4b8..508895f58 100644 --- a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs +++ b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct StructInNestedNS : IFlatbufferObject { private Struct __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } public StructInNestedNS __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs index f8a97a403..a2a1c0be7 100644 --- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs +++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct TableInNestedNS : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static TableInNestedNS GetRootAsTableInNestedNS(ByteBuffer _bb) { return GetRootAsTableInNestedNS(_bb, new TableInNestedNS()); } public static TableInNestedNS GetRootAsTableInNestedNS(ByteBuffer _bb, TableInNestedNS obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.cs b/tests/namespace_test/NamespaceA/SecondTableInA.cs index 32ed37b3b..204882884 100644 --- a/tests/namespace_test/NamespaceA/SecondTableInA.cs +++ b/tests/namespace_test/NamespaceA/SecondTableInA.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct SecondTableInA : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static SecondTableInA GetRootAsSecondTableInA(ByteBuffer _bb) { return GetRootAsSecondTableInA(_bb, new SecondTableInA()); } public static SecondTableInA GetRootAsSecondTableInA(ByteBuffer _bb, SecondTableInA obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.cs b/tests/namespace_test/NamespaceA/TableInFirstNS.cs index 4d068a17c..f1c7e96b2 100644 --- a/tests/namespace_test/NamespaceA/TableInFirstNS.cs +++ b/tests/namespace_test/NamespaceA/TableInFirstNS.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct TableInFirstNS : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static TableInFirstNS GetRootAsTableInFirstNS(ByteBuffer _bb) { return GetRootAsTableInFirstNS(_bb, new TableInFirstNS()); } public static TableInFirstNS GetRootAsTableInFirstNS(ByteBuffer _bb, TableInFirstNS obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } diff --git a/tests/namespace_test/NamespaceC/TableInC.cs b/tests/namespace_test/NamespaceC/TableInC.cs index 2fe0fcefa..6dddcd4db 100644 --- a/tests/namespace_test/NamespaceC/TableInC.cs +++ b/tests/namespace_test/NamespaceC/TableInC.cs @@ -9,6 +9,7 @@ using FlatBuffers; public struct TableInC : IFlatbufferObject { private Table __p; + public ByteBuffer ByteBuffer { get { return __p.bb; } } public static TableInC GetRootAsTableInC(ByteBuffer _bb) { return GetRootAsTableInC(_bb, new TableInC()); } public static TableInC GetRootAsTableInC(ByteBuffer _bb, TableInC obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); } public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; }