Add Get Bytes Method Generator for C#
authorMichael Collins <michael.collins@neudesic.com>
Mon, 5 Oct 2015 02:57:39 +0000 (19:57 -0700)
committerMichael Collins <michael.collins@neudesic.com>
Fri, 4 Dec 2015 18:44:43 +0000 (11:44 -0700)
commite083e466b85c1ae512193cee74e0dbd60be5ab87
treec2c0af7577419dfe1ce526ff309b974cdf4be8a2
parentfe2f8d32aa7ffb23baf5989a208477189cc98f99
Add Get Bytes Method Generator for C#

I updated idl_gen_general.cpp to add support for generating a Get Bytes
method for a vector to the generated C# source code. Given a byte vector
field named Foo, a method named GetFooBytes() will be generated in the
C# source code that will return an ArraySegment<byte> value referencing
the vector data in the underlying ByteBuffer.

I added a method to Table.cs named __vector_as_arraysegment that is used
by the code generated by the change to the C# generator.
__vector_as_arraysegment will take the offset of the vector and will
return the ArraySegment<byte> value corresponding to the bytes that
store the vector data.

I updated FlatBuffersExampleTests.cs to add tests to validate my
implementation of Table.__vector_as_arraysegment. I added tests to
demonstrate that the bytes for the monster's name can be extracted from
the underlying byte array. I also added tests to show that
Table.__vector_as_arraysegment returns a null value if the vector is not
present in the FlatBuffer.

I used the updated flatc.exe program to regenerate the C# source files
for the MyGame example. The new Monster class includes the GetXXXBytes
methods to return the byte arrays containing data for vectors.
net/FlatBuffers/Table.cs
src/idl_gen_general.cpp
tests/FlatBuffers.Test/Assert.cs
tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
tests/MyGame/Example/Monster.cs
tests/MyGame/Example/Stat.cs
tests/MyGame/Example/Test.cs
tests/MyGame/Example/TestSimpleTableWithEnum.cs
tests/MyGame/Example/Vec3.cs