Refactored the Java and C# code generators into one.

Also made the C# implementation support unsigned types, and
made it more like the Java version.

Bug: 17359988
Change-Id: If5305c08cd5c97f35426639516ce05e53bbec36c
Tested: on Linux and Windows.
parent d01b30cd
...@@ -12,8 +12,7 @@ set(FlatBuffers_Compiler_SRCS ...@@ -12,8 +12,7 @@ set(FlatBuffers_Compiler_SRCS
include/flatbuffers/util.h include/flatbuffers/util.h
src/idl_parser.cpp src/idl_parser.cpp
src/idl_gen_cpp.cpp src/idl_gen_cpp.cpp
src/idl_gen_java.cpp src/idl_gen_general.cpp
src/idl_gen_csharp.cpp
src/idl_gen_go.cpp src/idl_gen_go.cpp
src/idl_gen_text.cpp src/idl_gen_text.cpp
src/flatc.cpp src/flatc.cpp
......
...@@ -266,13 +266,12 @@ ...@@ -266,13 +266,12 @@
<ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" /> <ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" />
<ClInclude Include="..\..\include\flatbuffers\idl.h" /> <ClInclude Include="..\..\include\flatbuffers\idl.h" />
<ClInclude Include="..\..\include\flatbuffers\util.h" /> <ClInclude Include="..\..\include\flatbuffers\util.h" />
<ClCompile Include="..\..\src\idl_gen_csharp.cpp" /> <ClCompile Include="..\..\src\idl_gen_general.cpp" />
<ClCompile Include="..\..\src\idl_gen_go.cpp"> <ClCompile Include="..\..\src\idl_gen_go.cpp">
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Level4</WarningLevel> <WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Level4</WarningLevel>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\idl_parser.cpp" /> <ClCompile Include="..\..\src\idl_parser.cpp" />
<ClCompile Include="..\..\src\idl_gen_cpp.cpp" /> <ClCompile Include="..\..\src\idl_gen_cpp.cpp" />
<ClCompile Include="..\..\src\idl_gen_java.cpp" />
<ClCompile Include="..\..\src\idl_gen_text.cpp" /> <ClCompile Include="..\..\src\idl_gen_text.cpp" />
<ClCompile Include="..\..\src\flatc.cpp" /> <ClCompile Include="..\..\src\flatc.cpp" />
</ItemGroup> </ItemGroup>
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<LocalDebuggerCommandArguments>-j -c -n -g -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>-j -c -n -g -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>-j -c -g -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>-j -c -g -n -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
......
...@@ -32,31 +32,38 @@ namespace flatbuffers { ...@@ -32,31 +32,38 @@ namespace flatbuffers {
// Additionally, Parser::ParseType assumes bool..string is a contiguous range // Additionally, Parser::ParseType assumes bool..string is a contiguous range
// of type tokens. // of type tokens.
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ #define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
TD(NONE, "", uint8_t, byte, byte) \ TD(NONE, "", uint8_t, byte, byte, byte) \
TD(UTYPE, "", uint8_t, byte, byte) /* begin scalars, ints */ \ TD(UTYPE, "", uint8_t, byte, byte, byte) /* begin scalar/int */ \
TD(BOOL, "bool", uint8_t, byte, byte) \ TD(BOOL, "bool", uint8_t, byte, byte, byte) \
TD(CHAR, "byte", int8_t, byte, int8) \ TD(CHAR, "byte", int8_t, byte, int8, sbyte) \
TD(UCHAR, "ubyte", uint8_t, byte, byte) \ TD(UCHAR, "ubyte", uint8_t, byte, byte, byte) \
TD(SHORT, "short", int16_t, short, int16) \ TD(SHORT, "short", int16_t, short, int16, short) \
TD(USHORT, "ushort", uint16_t, short, uint16) \ TD(USHORT, "ushort", uint16_t, short, uint16, ushort) \
TD(INT, "int", int32_t, int, int32) \ TD(INT, "int", int32_t, int, int32, int) \
TD(UINT, "uint", uint32_t, int, uint32) \ TD(UINT, "uint", uint32_t, int, uint32, uint) \
TD(LONG, "long", int64_t, long, int64) \ TD(LONG, "long", int64_t, long, int64, long) \
TD(ULONG, "ulong", uint64_t, long, uint64) /* end ints */ \ TD(ULONG, "ulong", uint64_t, long, uint64, ulong) /* end int */ \
TD(FLOAT, "float", float, float, float32) /* begin floats */ \ TD(FLOAT, "float", float, float, float32, float) /* begin float */ \
TD(DOUBLE, "double", double, double, float64) /* end floats, scalars */ TD(DOUBLE, "double", double, double, float64, double) /* end float/scalar */
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \ #define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
TD(STRING, "string", Offset<void>, int, int) \ TD(STRING, "string", Offset<void>, int, int, int) \
TD(VECTOR, "", Offset<void>, int, int) \ TD(VECTOR, "", Offset<void>, int, int, int) \
TD(STRUCT, "", Offset<void>, int, int) \ TD(STRUCT, "", Offset<void>, int, int, int) \
TD(UNION, "", Offset<void>, int, int) TD(UNION, "", Offset<void>, int, int, int)
// The fields are:
// - enum
// - FlatBuffers schema type.
// - C++ type.
// - Java type.
// - Go type.
// - C# / .Net type.
// using these macros, we can now write code dealing with types just once, e.g. // using these macros, we can now write code dealing with types just once, e.g.
/* /*
switch (type) { switch (type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
// do something specific to CTYPE here // do something specific to CTYPE here
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
...@@ -73,12 +80,13 @@ switch (type) { ...@@ -73,12 +80,13 @@ switch (type) {
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic. __extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
#endif #endif
enum BaseType { enum BaseType {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) BASE_TYPE_ ## ENUM, #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
BASE_TYPE_ ## ENUM,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \
"define largest_scalar_t as " #CTYPE); "define largest_scalar_t as " #CTYPE);
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
...@@ -327,22 +335,11 @@ class Parser { ...@@ -327,22 +335,11 @@ class Parser {
std::map<std::string, bool> included_files_; std::map<std::string, bool> included_files_;
}; };
// Utility functions for generators: // Utility functions for multiple generators:
// Convert an underscore_based_indentifier in to camelCase. extern std::string MakeCamel(const std::string &in, bool first = true);
// Also uppercases the first character if first is true. extern void GenComment(const std::string &dc, std::string *code_ptr,
inline std::string MakeCamel(const std::string &in, bool first = true) { const char *prefix = "");
std::string s;
for (size_t i = 0; i < in.length(); i++) {
if (!i && first)
s += static_cast<char>(toupper(in[0]));
else if (in[i] == '_' && i + 1 < in.length())
s += static_cast<char>(toupper(in[++i]));
else
s += in[i];
}
return s;
}
// Container of options that may apply to any of the source/text generators. // Container of options that may apply to any of the source/text generators.
struct GeneratorOptions { struct GeneratorOptions {
...@@ -351,8 +348,14 @@ struct GeneratorOptions { ...@@ -351,8 +348,14 @@ struct GeneratorOptions {
bool output_enum_identifiers; bool output_enum_identifiers;
bool prefixed_enums; bool prefixed_enums;
// Possible options for the more general generator below.
enum Language { kJava, kCSharp, kMAX };
Language lang;
GeneratorOptions() : strict_json(false), indent_step(2), GeneratorOptions() : strict_json(false), indent_step(2),
output_enum_identifiers(true), prefixed_enums(true) {} output_enum_identifiers(true), prefixed_enums(true),
lang(GeneratorOptions::kJava) {}
}; };
// Generate text (JSON) from a given FlatBuffer, and a given Parser // Generate text (JSON) from a given FlatBuffer, and a given Parser
...@@ -397,6 +400,12 @@ extern bool GenerateCSharp(const Parser &parser, ...@@ -397,6 +400,12 @@ extern bool GenerateCSharp(const Parser &parser,
const std::string &file_name, const std::string &file_name,
const GeneratorOptions &opts); const GeneratorOptions &opts);
// Generate Java/C#/.. files from the definitions in the Parser object.
// See idl_gen_general.cpp.
extern bool GenerateGeneral(const Parser &parser,
const std::string &path,
const std::string &file_name,
const GeneratorOptions &opts);
} // namespace flatbuffers } // namespace flatbuffers
......
...@@ -25,6 +25,7 @@ namespace FlatBuffers ...@@ -25,6 +25,7 @@ namespace FlatBuffers
public class ByteBuffer public class ByteBuffer
{ {
private readonly byte[] _buffer; private readonly byte[] _buffer;
private int _pos; // Must track start of the buffer.
public int Length { get { return _buffer.Length; } } public int Length { get { return _buffer.Length; } }
...@@ -33,8 +34,11 @@ namespace FlatBuffers ...@@ -33,8 +34,11 @@ namespace FlatBuffers
public ByteBuffer(byte[] buffer) public ByteBuffer(byte[] buffer)
{ {
_buffer = buffer; _buffer = buffer;
_pos = 0;
} }
public int position() { return _pos; }
protected void WriteLittleEndian(int offset, byte[] data) protected void WriteLittleEndian(int offset, byte[] data)
{ {
if (!BitConverter.IsLittleEndian) if (!BitConverter.IsLittleEndian)
...@@ -42,6 +46,7 @@ namespace FlatBuffers ...@@ -42,6 +46,7 @@ namespace FlatBuffers
data = data.Reverse().ToArray(); data = data.Reverse().ToArray();
} }
Buffer.BlockCopy(data, 0, _buffer, offset, data.Length); Buffer.BlockCopy(data, 0, _buffer, offset, data.Length);
_pos = offset;
} }
protected byte[] ReadLittleEndian(int offset, int count) protected byte[] ReadLittleEndian(int offset, int count)
...@@ -62,10 +67,18 @@ namespace FlatBuffers ...@@ -62,10 +67,18 @@ namespace FlatBuffers
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
public void PutSbyte(int offset, sbyte value)
{
AssertOffsetAndLength(offset, sizeof(sbyte));
_buffer[offset] = (byte)value;
_pos = offset;
}
public void PutByte(int offset, byte value) public void PutByte(int offset, byte value)
{ {
AssertOffsetAndLength(offset, sizeof(byte)); AssertOffsetAndLength(offset, sizeof(byte));
_buffer[offset] = value; _buffer[offset] = value;
_pos = offset;
} }
public void PutShort(int offset, short value) public void PutShort(int offset, short value)
...@@ -74,18 +87,36 @@ namespace FlatBuffers ...@@ -74,18 +87,36 @@ namespace FlatBuffers
WriteLittleEndian(offset, BitConverter.GetBytes(value)); WriteLittleEndian(offset, BitConverter.GetBytes(value));
} }
public void PutUshort(int offset, ushort value)
{
AssertOffsetAndLength(offset, sizeof(ushort));
WriteLittleEndian(offset, BitConverter.GetBytes(value));
}
public void PutInt(int offset, int value) public void PutInt(int offset, int value)
{ {
AssertOffsetAndLength(offset, sizeof(int)); AssertOffsetAndLength(offset, sizeof(int));
WriteLittleEndian(offset, BitConverter.GetBytes(value)); WriteLittleEndian(offset, BitConverter.GetBytes(value));
} }
public void PutUint(int offset, uint value)
{
AssertOffsetAndLength(offset, sizeof(uint));
WriteLittleEndian(offset, BitConverter.GetBytes(value));
}
public void PutLong(int offset, long value) public void PutLong(int offset, long value)
{ {
AssertOffsetAndLength(offset, sizeof(long)); AssertOffsetAndLength(offset, sizeof(long));
WriteLittleEndian(offset, BitConverter.GetBytes(value)); WriteLittleEndian(offset, BitConverter.GetBytes(value));
} }
public void PutUlong(int offset, ulong value)
{
AssertOffsetAndLength(offset, sizeof(ulong));
WriteLittleEndian(offset, BitConverter.GetBytes(value));
}
public void PutFloat(int offset, float value) public void PutFloat(int offset, float value)
{ {
AssertOffsetAndLength(offset, sizeof(float)); AssertOffsetAndLength(offset, sizeof(float));
...@@ -98,6 +129,12 @@ namespace FlatBuffers ...@@ -98,6 +129,12 @@ namespace FlatBuffers
WriteLittleEndian(offset, BitConverter.GetBytes(value)); WriteLittleEndian(offset, BitConverter.GetBytes(value));
} }
public sbyte GetSbyte(int index)
{
AssertOffsetAndLength(index, sizeof(sbyte));
return (sbyte)_buffer[index];
}
public byte Get(int index) public byte Get(int index)
{ {
AssertOffsetAndLength(index, sizeof(byte)); AssertOffsetAndLength(index, sizeof(byte));
...@@ -111,6 +148,13 @@ namespace FlatBuffers ...@@ -111,6 +148,13 @@ namespace FlatBuffers
return value; return value;
} }
public ushort GetUshort(int index)
{
var tmp = ReadLittleEndian(index, sizeof(ushort));
var value = BitConverter.ToUInt16(tmp, 0);
return value;
}
public int GetInt(int index) public int GetInt(int index)
{ {
var tmp = ReadLittleEndian(index, sizeof(int)); var tmp = ReadLittleEndian(index, sizeof(int));
...@@ -118,6 +162,13 @@ namespace FlatBuffers ...@@ -118,6 +162,13 @@ namespace FlatBuffers
return value; return value;
} }
public uint GetUint(int index)
{
var tmp = ReadLittleEndian(index, sizeof(uint));
var value = BitConverter.ToUInt32(tmp, 0);
return value;
}
public long GetLong(int index) public long GetLong(int index)
{ {
var tmp = ReadLittleEndian(index, sizeof(long)); var tmp = ReadLittleEndian(index, sizeof(long));
...@@ -125,6 +176,13 @@ namespace FlatBuffers ...@@ -125,6 +176,13 @@ namespace FlatBuffers
return value; return value;
} }
public ulong GetUlong(int index)
{
var tmp = ReadLittleEndian(index, sizeof(ulong));
var value = BitConverter.ToUInt64(tmp, 0);
return value;
}
public float GetFloat(int index) public float GetFloat(int index)
{ {
var tmp = ReadLittleEndian(index, sizeof(float)); var tmp = ReadLittleEndian(index, sizeof(float));
......
...@@ -50,7 +50,7 @@ namespace FlatBuffers ...@@ -50,7 +50,7 @@ namespace FlatBuffers
} }
public int Offset { get { return _bb.Length - _space; } } public int Offset() { return _bb.Length - _space; }
public void Pad(int size) public void Pad(int size)
{ {
...@@ -105,6 +105,11 @@ namespace FlatBuffers ...@@ -105,6 +105,11 @@ namespace FlatBuffers
Pad(alignSize); Pad(alignSize);
} }
public void PutSbyte(sbyte x)
{
_bb.PutSbyte(_space -= sizeof(sbyte), x);
}
public void PutByte(byte x) public void PutByte(byte x)
{ {
_bb.PutByte(_space -= sizeof(byte), x); _bb.PutByte(_space -= sizeof(byte), x);
...@@ -115,16 +120,31 @@ namespace FlatBuffers ...@@ -115,16 +120,31 @@ namespace FlatBuffers
_bb.PutShort(_space -= sizeof(short), x); _bb.PutShort(_space -= sizeof(short), x);
} }
public void PutInt32(int x) public void PutUshort(ushort x)
{
_bb.PutUshort(_space -= sizeof(ushort), x);
}
public void PutInt(int x)
{ {
_bb.PutInt(_space -= sizeof(int), x); _bb.PutInt(_space -= sizeof(int), x);
} }
public void PutInt64(long x) public void PutUint(uint x)
{
_bb.PutUint(_space -= sizeof(uint), x);
}
public void PutLong(long x)
{ {
_bb.PutLong(_space -= sizeof(long), x); _bb.PutLong(_space -= sizeof(long), x);
} }
public void PutUlong(ulong x)
{
_bb.PutUlong(_space -= sizeof(ulong), x);
}
public void PutFloat(float x) public void PutFloat(float x)
{ {
_bb.PutFloat(_space -= sizeof(float), x); _bb.PutFloat(_space -= sizeof(float), x);
...@@ -137,10 +157,14 @@ namespace FlatBuffers ...@@ -137,10 +157,14 @@ namespace FlatBuffers
// Adds a scalar to the buffer, properly aligned, and the buffer grown // Adds a scalar to the buffer, properly aligned, and the buffer grown
// if needed. // if needed.
public void AddSbyte(sbyte x) { Prep(sizeof(sbyte), 0); PutSbyte(x); }
public void AddByte(byte x) { Prep(sizeof(byte), 0); PutByte(x); } public void AddByte(byte x) { Prep(sizeof(byte), 0); PutByte(x); }
public void AddShort(short x) { Prep(sizeof(short), 0); PutShort(x); } public void AddShort(short x) { Prep(sizeof(short), 0); PutShort(x); }
public void AddInt(int x) { Prep(sizeof(int), 0); PutInt32(x); } public void AddUshort(ushort x) { Prep(sizeof(ushort), 0); PutUshort(x); }
public void AddLong(long x) { Prep(sizeof(long), 0); PutInt64(x); } public void AddInt(int x) { Prep(sizeof(int), 0); PutInt(x); }
public void AddUint(uint x) { Prep(sizeof(uint), 0); PutUint(x); }
public void AddLong(long x) { Prep(sizeof(long), 0); PutLong(x); }
public void AddULong(ulong x) { Prep(sizeof(ulong), 0); PutUlong(x); }
public void AddFloat(float x) { Prep(sizeof(float), 0); PutFloat(x); } public void AddFloat(float x) { Prep(sizeof(float), 0); PutFloat(x); }
public void AddDouble(double x) { Prep(sizeof(double), 0); public void AddDouble(double x) { Prep(sizeof(double), 0);
PutDouble(x); } PutDouble(x); }
...@@ -151,11 +175,11 @@ namespace FlatBuffers ...@@ -151,11 +175,11 @@ namespace FlatBuffers
public void AddOffset(int off) public void AddOffset(int off)
{ {
Prep(sizeof(int), 0); // Ensure alignment is already done. Prep(sizeof(int), 0); // Ensure alignment is already done.
if (off > Offset) if (off > Offset())
throw new ArgumentException(); throw new ArgumentException();
off = Offset - off + sizeof(int); off = Offset() - off + sizeof(int);
PutInt32(off); PutInt(off);
} }
public void StartVector(int elemSize, int count, int alignment) public void StartVector(int elemSize, int count, int alignment)
...@@ -168,8 +192,8 @@ namespace FlatBuffers ...@@ -168,8 +192,8 @@ namespace FlatBuffers
public int EndVector() public int EndVector()
{ {
PutInt32(_vectorNumElems); PutInt(_vectorNumElems);
return Offset; return Offset();
} }
public void Nested(int obj) public void Nested(int obj)
...@@ -177,7 +201,7 @@ namespace FlatBuffers ...@@ -177,7 +201,7 @@ namespace FlatBuffers
// Structs are always stored inline, so need to be created right // Structs are always stored inline, so need to be created right
// where they are used. You'll get this assert if you created it // where they are used. You'll get this assert if you created it
// elsewhere. // elsewhere.
if (obj != Offset) if (obj != Offset())
throw new Exception( throw new Exception(
"FlatBuffers: struct must be serialized inline."); "FlatBuffers: struct must be serialized inline.");
} }
...@@ -195,7 +219,7 @@ namespace FlatBuffers ...@@ -195,7 +219,7 @@ namespace FlatBuffers
{ {
NotNested(); NotNested();
_vtable = new int[numfields]; _vtable = new int[numfields];
_objectStart = Offset; _objectStart = Offset();
} }
...@@ -203,14 +227,18 @@ namespace FlatBuffers ...@@ -203,14 +227,18 @@ namespace FlatBuffers
// buffer. // buffer.
public void Slot(int voffset) public void Slot(int voffset)
{ {
_vtable[voffset] = Offset; _vtable[voffset] = Offset();
} }
// Add a scalar to a table at `o` into its vtable, with value `x` and default `d` // Add a scalar to a table at `o` into its vtable, with value `x` and default `d`
public void AddByte(int o, byte x, int d) { if (x != d) { AddByte(x); Slot(o); } } public void AddSbyte(int o, sbyte x, sbyte d) { if (x != d) { AddSbyte(x); Slot(o); } }
public void AddByte(int o, byte x, byte d) { if (x != d) { AddByte(x); Slot(o); } }
public void AddShort(int o, short x, int d) { if (x != d) { AddShort(x); Slot(o); } } public void AddShort(int o, short x, int d) { if (x != d) { AddShort(x); Slot(o); } }
public void AddUshort(int o, ushort x, ushort d) { if (x != d) { AddUshort(x); Slot(o); } }
public void AddInt(int o, int x, int d) { if (x != d) { AddInt(x); Slot(o); } } public void AddInt(int o, int x, int d) { if (x != d) { AddInt(x); Slot(o); } }
public void AddUint(int o, uint x, uint d) { if (x != d) { AddUint(x); Slot(o); } }
public void AddLong(int o, long x, long d) { if (x != d) { AddLong(x); Slot(o); } } public void AddLong(int o, long x, long d) { if (x != d) { AddLong(x); Slot(o); } }
public void AddULong(int o, ulong x, ulong d) { if (x != d) { AddULong(x); Slot(o); } }
public void AddFloat(int o, float x, double d) { if (x != d) { AddFloat(x); Slot(o); } } public void AddFloat(int o, float x, double d) { if (x != d) { AddFloat(x); Slot(o); } }
public void AddDouble(int o, double x, double d) { if (x != d) { AddDouble(x); Slot(o); } } public void AddDouble(int o, double x, double d) { if (x != d) { AddDouble(x); Slot(o); } }
public void AddOffset(int o, int x, int d) { if (x != d) { AddOffset(x); Slot(o); } } public void AddOffset(int o, int x, int d) { if (x != d) { AddOffset(x); Slot(o); } }
...@@ -245,7 +273,7 @@ namespace FlatBuffers ...@@ -245,7 +273,7 @@ namespace FlatBuffers
"Flatbuffers: calling endObject without a startObject"); "Flatbuffers: calling endObject without a startObject");
AddInt((int)0); AddInt((int)0);
var vtableloc = Offset; var vtableloc = Offset();
// Write out the current vtable. // Write out the current vtable.
for (int i = _vtable.Length - 1; i >= 0 ; i--) { for (int i = _vtable.Length - 1; i >= 0 ; i--) {
// Offset relative to the start of the table. // Offset relative to the start of the table.
...@@ -298,9 +326,9 @@ namespace FlatBuffers ...@@ -298,9 +326,9 @@ namespace FlatBuffers
_vtables = newvtables; _vtables = newvtables;
}; };
_vtables[_numVtables++] = Offset; _vtables[_numVtables++] = Offset();
// Point table to current vtable. // Point table to current vtable.
_bb.PutInt(_bb.Length - vtableloc, Offset - vtableloc); _bb.PutInt(_bb.Length - vtableloc, Offset() - vtableloc);
} }
_vtable = null; _vtable = null;
...@@ -313,17 +341,13 @@ namespace FlatBuffers ...@@ -313,17 +341,13 @@ namespace FlatBuffers
AddOffset(rootTable); AddOffset(rootTable);
} }
public ByteBuffer Data { get { return _bb; }} public ByteBuffer DataBuffer() { return _bb; }
// The FlatBuffer data doesn't start at offset 0 in the ByteBuffer:
public int DataStart { get { return _space; } }
// Utility function for copying a byte array that starts at 0. // Utility function for copying a byte array that starts at 0.
public byte[] SizedByteArray() public byte[] SizedByteArray()
{ {
var newArray = new byte[_bb.Data.Length]; var newArray = new byte[_bb.Data.Length];
Buffer.BlockCopy(_bb.Data, DataStart, newArray, 0, Buffer.BlockCopy(_bb.Data, _bb.position(), newArray, 0,
_bb.Data.Length); _bb.Data.Length);
return newArray; return newArray;
} }
......
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>FlatBuffers</id>
<version>1.0.0-alpha00003</version>
<authors>Google Inc</authors>
<description>A .NET port of Google Inc's FlatBuffers project.</description>
<language>en-US</language>
<projectUrl>https://github.com/evolutional/flatbuffers</projectUrl>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
</metadata>
</package>
\ No newline at end of file
...@@ -74,14 +74,14 @@ namespace FlatBuffers ...@@ -74,14 +74,14 @@ namespace FlatBuffers
return t; return t;
} }
protected static bool __has_identifier(ByteBuffer bb, int offset, string ident) protected static bool __has_identifier(ByteBuffer bb, string ident)
{ {
if (ident.Length != FlatBufferConstants.FileIdentifierLength) if (ident.Length != FlatBufferConstants.FileIdentifierLength)
throw new ArgumentException("FlatBuffers: file identifier must be length " + FlatBufferConstants.FileIdentifierLength, "ident"); throw new ArgumentException("FlatBuffers: file identifier must be length " + FlatBufferConstants.FileIdentifierLength, "ident");
for (var i = 0; i < FlatBufferConstants.FileIdentifierLength; i++) for (var i = 0; i < FlatBufferConstants.FileIdentifierLength; i++)
{ {
if (ident[i] != (char)bb.Get(offset + sizeof(int) + i)) return false; if (ident[i] != (char)bb.Get(bb.position() + sizeof(int) + i)) return false;
} }
return true; return true;
......
...@@ -62,21 +62,28 @@ struct Generator { ...@@ -62,21 +62,28 @@ struct Generator {
const flatbuffers::GeneratorOptions &opts); const flatbuffers::GeneratorOptions &opts);
const char *extension; const char *extension;
const char *name; const char *name;
flatbuffers::GeneratorOptions::Language lang;
const char *help; const char *help;
}; };
const Generator generators[] = { const Generator generators[] = {
{ flatbuffers::GenerateBinary, "b", "binary", { flatbuffers::GenerateBinary, "b", "binary",
flatbuffers::GeneratorOptions::kMAX,
"Generate wire format binaries for any data definitions" }, "Generate wire format binaries for any data definitions" },
{ flatbuffers::GenerateTextFile, "t", "text", { flatbuffers::GenerateTextFile, "t", "text",
flatbuffers::GeneratorOptions::kMAX,
"Generate text output for any data definitions" }, "Generate text output for any data definitions" },
{ flatbuffers::GenerateCPP, "c", "C++", { flatbuffers::GenerateCPP, "c", "C++",
flatbuffers::GeneratorOptions::kMAX,
"Generate C++ headers for tables/structs" }, "Generate C++ headers for tables/structs" },
{ flatbuffers::GenerateGo, "g", "Go", { flatbuffers::GenerateGo, "g", "Go",
flatbuffers::GeneratorOptions::kMAX,
"Generate Go files for tables/structs" }, "Generate Go files for tables/structs" },
{ flatbuffers::GenerateJava, "j", "Java", { flatbuffers::GenerateGeneral, "j", "Java",
flatbuffers::GeneratorOptions::kJava,
"Generate Java classes for tables/structs" }, "Generate Java classes for tables/structs" },
{ flatbuffers::GenerateCSharp, "n", "C#", { flatbuffers::GenerateGeneral, "n", "C#",
flatbuffers::GeneratorOptions::kCSharp,
"Generate C# classes for tables/structs" } "Generate C# classes for tables/structs" }
}; };
...@@ -194,6 +201,7 @@ int main(int argc, const char *argv[]) { ...@@ -194,6 +201,7 @@ int main(int argc, const char *argv[]) {
for (size_t i = 0; i < num_generators; ++i) { for (size_t i = 0; i < num_generators; ++i) {
if (generator_enabled[i]) { if (generator_enabled[i]) {
flatbuffers::EnsureDirExists(output_path); flatbuffers::EnsureDirExists(output_path);
opts.lang = generators[i].lang;
if (!generators[i].generate(parser, output_path, filebase, opts)) { if (!generators[i].generate(parser, output_path, filebase, opts)) {
Error((std::string("Unable to generate ") + Error((std::string("Unable to generate ") +
generators[i].name + generators[i].name +
......
...@@ -26,7 +26,7 @@ namespace cpp { ...@@ -26,7 +26,7 @@ namespace cpp {
// Return a C++ type from the table in idl.h // Return a C++ type from the table in idl.h
static std::string GenTypeBasic(const Type &type) { static std::string GenTypeBasic(const Type &type) {
static const char *ctypename[] = { static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) #CTYPE, #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) #CTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
...@@ -96,16 +96,6 @@ static std::string GenTypeGet(const Parser &parser, const Type &type, ...@@ -96,16 +96,6 @@ static std::string GenTypeGet(const Parser &parser, const Type &type,
: beforeptr + GenTypePointer(parser, type) + afterptr; : beforeptr + GenTypePointer(parser, type) + afterptr;
} }
// Generate a documentation comment, if available.
static void GenComment(const std::string &dc,
std::string *code_ptr,
const char *prefix = "") {
std::string &code = *code_ptr;
if (dc.length()) {
code += std::string(prefix) + "///" + dc + "\n";
}
}
static std::string GenEnumVal(const EnumDef &enum_def, const EnumVal &enum_val, static std::string GenEnumVal(const EnumDef &enum_def, const EnumVal &enum_val,
const GeneratorOptions &opts) { const GeneratorOptions &opts) {
return opts.prefixed_enums ? enum_def.name + "_" + enum_val.name return opts.prefixed_enums ? enum_def.name + "_" + enum_val.name
......
This diff is collapsed.
This diff is collapsed.
...@@ -612,7 +612,7 @@ static bool SaveType(const Parser &parser, const Definition &def, ...@@ -612,7 +612,7 @@ static bool SaveType(const Parser &parser, const Definition &def,
static std::string GenTypeBasic(const Type &type) { static std::string GenTypeBasic(const Type &type) {
static const char *ctypename[] = { static const char *ctypename[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) #GTYPE, #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) #GTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
......
...@@ -159,7 +159,7 @@ template<> void Print<const void *>(const void *val, ...@@ -159,7 +159,7 @@ template<> void Print<const void *>(const void *val,
type = type.VectorType(); type = type.VectorType();
// Call PrintVector above specifically for each element type: // Call PrintVector above specifically for each element type:
switch (type.base_type) { switch (type.base_type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
PrintVector<CTYPE>( \ PrintVector<CTYPE>( \
*reinterpret_cast<const Vector<CTYPE> *>(val), \ *reinterpret_cast<const Vector<CTYPE> *>(val), \
...@@ -225,7 +225,7 @@ static void GenStruct(const StructDef &struct_def, const Table *table, ...@@ -225,7 +225,7 @@ static void GenStruct(const StructDef &struct_def, const Table *table,
OutputIdentifier(fd.name, opts, _text); OutputIdentifier(fd.name, opts, _text);
text += ": "; text += ": ";
switch (fd.value.type.base_type) { switch (fd.value.type.base_type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
GenField<CTYPE>(fd, table, struct_def.fixed, \ GenField<CTYPE>(fd, table, struct_def.fixed, \
opts, indent + Indent(opts), _text); \ opts, indent + Indent(opts), _text); \
...@@ -233,7 +233,7 @@ static void GenStruct(const StructDef &struct_def, const Table *table, ...@@ -233,7 +233,7 @@ static void GenStruct(const StructDef &struct_def, const Table *table,
FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
// Generate drop-thru case statements for all pointer types: // Generate drop-thru case statements for all pointer types:
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: case BASE_TYPE_ ## ENUM:
FLATBUFFERS_GEN_TYPES_POINTER(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES_POINTER(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
......
...@@ -23,14 +23,15 @@ ...@@ -23,14 +23,15 @@
namespace flatbuffers { namespace flatbuffers {
const char *const kTypeNames[] = { const char *const kTypeNames[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) IDLTYPE, #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) IDLTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
nullptr nullptr
}; };
const char kTypeSizes[] = { const char kTypeSizes[] = {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) sizeof(CTYPE), #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
sizeof(CTYPE),
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
...@@ -92,7 +93,8 @@ enum { ...@@ -92,7 +93,8 @@ enum {
#define FLATBUFFERS_TOKEN(NAME, VALUE, STRING) kToken ## NAME = VALUE, #define FLATBUFFERS_TOKEN(NAME, VALUE, STRING) kToken ## NAME = VALUE,
FLATBUFFERS_GEN_TOKENS(FLATBUFFERS_TOKEN) FLATBUFFERS_GEN_TOKENS(FLATBUFFERS_TOKEN)
#undef FLATBUFFERS_TOKEN #undef FLATBUFFERS_TOKEN
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) kToken ## ENUM, #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
kToken ## ENUM,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
...@@ -102,7 +104,7 @@ static std::string TokenToString(int t) { ...@@ -102,7 +104,7 @@ static std::string TokenToString(int t) {
#define FLATBUFFERS_TOKEN(NAME, VALUE, STRING) STRING, #define FLATBUFFERS_TOKEN(NAME, VALUE, STRING) STRING,
FLATBUFFERS_GEN_TOKENS(FLATBUFFERS_TOKEN) FLATBUFFERS_GEN_TOKENS(FLATBUFFERS_TOKEN)
#undef FLATBUFFERS_TOKEN #undef FLATBUFFERS_TOKEN
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) IDLTYPE, #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) IDLTYPE,
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
}; };
...@@ -200,7 +202,7 @@ void Parser::Next() { ...@@ -200,7 +202,7 @@ void Parser::Next() {
attribute_.clear(); attribute_.clear();
attribute_.append(start, cursor_); attribute_.append(start, cursor_);
// First, see if it is a type keyword from the table of types: // First, see if it is a type keyword from the table of types:
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
if (attribute_ == IDLTYPE) { \ if (attribute_ == IDLTYPE) { \
token_ = kToken ## ENUM; \ token_ = kToken ## ENUM; \
return; \ return; \
...@@ -491,7 +493,7 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) { ...@@ -491,7 +493,7 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) {
auto field = it->second; auto field = it->second;
if (!struct_def.sortbysize || size == SizeOf(value.type.base_type)) { if (!struct_def.sortbysize || size == SizeOf(value.type.base_type)) {
switch (value.type.base_type) { switch (value.type.base_type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
builder_.Pad(field->padding); \ builder_.Pad(field->padding); \
if (struct_def.fixed) { \ if (struct_def.fixed) { \
...@@ -504,7 +506,7 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) { ...@@ -504,7 +506,7 @@ uoffset_t Parser::ParseTable(const StructDef &struct_def) {
break; break;
FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD); FLATBUFFERS_GEN_TYPES_SCALAR(FLATBUFFERS_TD);
#undef FLATBUFFERS_TD #undef FLATBUFFERS_TD
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
builder_.Pad(field->padding); \ builder_.Pad(field->padding); \
if (IsStruct(field->value.type)) { \ if (IsStruct(field->value.type)) { \
...@@ -559,7 +561,7 @@ uoffset_t Parser::ParseVector(const Type &type) { ...@@ -559,7 +561,7 @@ uoffset_t Parser::ParseVector(const Type &type) {
// start at the back, since we're building the data backwards. // start at the back, since we're building the data backwards.
auto &val = field_stack_.back().first; auto &val = field_stack_.back().first;
switch (val.type.base_type) { switch (val.type.base_type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE) \ #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE) \
case BASE_TYPE_ ## ENUM: \ case BASE_TYPE_ ## ENUM: \
if (IsStruct(val.type)) SerializeStruct(*val.type.struct_def, val); \ if (IsStruct(val.type)) SerializeStruct(*val.type.struct_def, val); \
else builder_.PushElement(atot<CTYPE>(val.constant.c_str())); \ else builder_.PushElement(atot<CTYPE>(val.constant.c_str())); \
......
...@@ -63,7 +63,7 @@ namespace FlatBuffers.Test ...@@ -63,7 +63,7 @@ namespace FlatBuffers.Test
{ {
action(); action();
} }
catch (T ex) catch (T)
{ {
caught = true; caught = true;
} }
......
...@@ -39,7 +39,7 @@ namespace FlatBuffers.Test ...@@ -39,7 +39,7 @@ namespace FlatBuffers.Test
var str = fbb.CreateString("MyMonster"); var str = fbb.CreateString("MyMonster");
var test1 = fbb.CreateString("test1"); var test1 = fbb.CreateString("test1");
var test2 = fbb.CreateString("test2"); var test2 = fbb.CreateString("test2");
Monster.StartInventoryVector(fbb, 5); Monster.StartInventoryVector(fbb, 5);
...@@ -54,19 +54,19 @@ namespace FlatBuffers.Test ...@@ -54,19 +54,19 @@ namespace FlatBuffers.Test
var mon2 = Monster.EndMonster(fbb); var mon2 = Monster.EndMonster(fbb);
Monster.StartTest4Vector(fbb, 2); Monster.StartTest4Vector(fbb, 2);
MyGame.Example.Test.CreateTest(fbb, (short)10, (byte)20); MyGame.Example.Test.CreateTest(fbb, (short)10, (sbyte)20);
MyGame.Example.Test.CreateTest(fbb, (short)30, (byte)40); MyGame.Example.Test.CreateTest(fbb, (short)30, (sbyte)40);
var test4 = fbb.EndVector(); var test4 = fbb.EndVector();
Monster.StartTestarrayofstringVector(fbb, 2); Monster.StartTestarrayofstringVector(fbb, 2);
fbb.AddOffset(test2); fbb.AddOffset(test2);
fbb.AddOffset(test1); fbb.AddOffset(test1);
var testArrayOfString = fbb.EndVector(); var testArrayOfString = fbb.EndVector();
Monster.StartMonster(fbb); Monster.StartMonster(fbb);
Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0, Monster.AddPos(fbb, Vec3.CreateVec3(fbb, 1.0f, 2.0f, 3.0f, 3.0,
(byte)4, (short)5, (byte)6)); (sbyte)4, (short)5, (sbyte)6));
Monster.AddHp(fbb, (short)80); Monster.AddHp(fbb, (short)80);
Monster.AddName(fbb, str); Monster.AddName(fbb, str);
Monster.AddInventory(fbb, inv); Monster.AddInventory(fbb, inv);
...@@ -79,19 +79,19 @@ namespace FlatBuffers.Test ...@@ -79,19 +79,19 @@ namespace FlatBuffers.Test
fbb.Finish(mon); fbb.Finish(mon);
// Dump to output directory so we can inspect later, if needed // Dump to output directory so we can inspect later, if needed
using (var ms= new MemoryStream(fbb.Data.Data, fbb.DataStart, fbb.Offset)) using (var ms = new MemoryStream(fbb.DataBuffer().Data, fbb.DataBuffer().position(), fbb.Offset()))
{ {
var data = ms.ToArray(); var data = ms.ToArray();
File.WriteAllBytes(@"Resources/monsterdata_cstest.bin",data); File.WriteAllBytes(@"Resources/monsterdata_cstest.bin",data);
} }
// Now assert the buffer // Now assert the buffer
TestBuffer(fbb.Data, fbb.DataStart); TestBuffer(fbb.DataBuffer());
} }
private void TestBuffer(ByteBuffer bb, int start) private void TestBuffer(ByteBuffer bb)
{ {
var monster = Monster.GetRootAsMonster(bb, start); var monster = Monster.GetRootAsMonster(bb);
Assert.AreEqual(80, monster.Hp()); Assert.AreEqual(80, monster.Hp());
Assert.AreEqual(150, monster.Mana()); Assert.AreEqual(150, monster.Mana());
...@@ -103,10 +103,10 @@ namespace FlatBuffers.Test ...@@ -103,10 +103,10 @@ namespace FlatBuffers.Test
Assert.AreEqual(3.0f, pos.Z()); Assert.AreEqual(3.0f, pos.Z());
Assert.AreEqual(3.0f, pos.Test1()); Assert.AreEqual(3.0f, pos.Test1());
Assert.AreEqual((byte)4, pos.Test2()); Assert.AreEqual((sbyte)4, pos.Test2());
var t = pos.Test3(); var t = pos.Test3();
Assert.AreEqual((short)5, t.A()); Assert.AreEqual((short)5, t.A());
Assert.AreEqual((byte)6, t.B()); Assert.AreEqual((sbyte)6, t.B());
Assert.AreEqual((byte)Any.Monster, monster.TestType()); Assert.AreEqual((byte)Any.Monster, monster.TestType());
...@@ -132,14 +132,14 @@ namespace FlatBuffers.Test ...@@ -132,14 +132,14 @@ namespace FlatBuffers.Test
Assert.AreEqual(2, monster.TestarrayofstringLength()); Assert.AreEqual(2, monster.TestarrayofstringLength());
Assert.AreEqual("test1", monster.Testarrayofstring(0)); Assert.AreEqual("test1", monster.Testarrayofstring(0));
Assert.AreEqual("test2", monster.Testarrayofstring(1)); Assert.AreEqual("test2", monster.Testarrayofstring(1));
} }
public void CanReadCppGeneratedWireFile() public void CanReadCppGeneratedWireFile()
{ {
var data = File.ReadAllBytes(@"Resources/monsterdata_test.bin"); var data = File.ReadAllBytes(@"Resources/monsterdata_test.bin");
var bb = new ByteBuffer(data); var bb = new ByteBuffer(data);
TestBuffer(bb, 0); TestBuffer(bb);
} }
} }
} }
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
namespace MyGame.Example namespace MyGame.Example
{ {
using FlatBuffers;
public class Any public class Any
{ {
public static byte NONE = 0; public static byte NONE = 0;
......
...@@ -3,13 +3,11 @@ ...@@ -3,13 +3,11 @@
namespace MyGame.Example namespace MyGame.Example
{ {
using FlatBuffers;
public class Color public class Color
{ {
public static byte Red = 1; public static sbyte Red = 1;
public static byte Green = 2; public static sbyte Green = 2;
public static byte Blue = 8; public static sbyte Blue = 8;
}; };
......
This diff is collapsed.
...@@ -9,14 +9,14 @@ public class Test : Struct { ...@@ -9,14 +9,14 @@ public class Test : Struct {
public Test __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; } public Test __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; return this; }
public short A() { return bb.GetShort(bb_pos + 0); } public short A() { return bb.GetShort(bb_pos + 0); }
public byte B() { return bb.Get(bb_pos + 2); } public sbyte B() { return bb.GetSbyte(bb_pos + 2); }
public static int CreateTest(FlatBufferBuilder builder, short A, byte B) { public static int CreateTest(FlatBufferBuilder builder, short A, sbyte B) {
builder.Prep(2, 4); builder.Prep(2, 4);
builder.Pad(1); builder.Pad(1);
builder.PutByte(B); builder.PutSbyte(B);
builder.PutShort(A); builder.PutShort(A);
return builder.Offset; return builder.Offset();
} }
}; };
......
...@@ -12,25 +12,25 @@ public class Vec3 : Struct { ...@@ -12,25 +12,25 @@ public class Vec3 : Struct {
public float Y() { return bb.GetFloat(bb_pos + 4); } public float Y() { return bb.GetFloat(bb_pos + 4); }
public float Z() { return bb.GetFloat(bb_pos + 8); } public float Z() { return bb.GetFloat(bb_pos + 8); }
public double Test1() { return bb.GetDouble(bb_pos + 16); } public double Test1() { return bb.GetDouble(bb_pos + 16); }
public byte Test2() { return bb.Get(bb_pos + 24); } public sbyte Test2() { return bb.GetSbyte(bb_pos + 24); }
public Test Test3() { return Test3(new Test()); } public Test Test3() { return Test3(new Test()); }
public Test Test3(Test obj) { return obj.__init(bb_pos + 26, bb); } public Test Test3(Test obj) { return obj.__init(bb_pos + 26, bb); }
public static int CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z, double Test1, byte Test2, short Test_A, byte Test_B) { public static int CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z, double Test1, sbyte Test2, short Test_A, sbyte Test_B) {
builder.Prep(16, 32); builder.Prep(16, 32);
builder.Pad(2); builder.Pad(2);
builder.Prep(2, 4); builder.Prep(2, 4);
builder.Pad(1); builder.Pad(1);
builder.PutByte(Test_B); builder.PutSbyte(Test_B);
builder.PutShort(Test_A); builder.PutShort(Test_A);
builder.Pad(1); builder.Pad(1);
builder.PutByte(Test2); builder.PutSbyte(Test2);
builder.PutDouble(Test1); builder.PutDouble(Test1);
builder.Pad(4); builder.Pad(4);
builder.PutFloat(Z); builder.PutFloat(Z);
builder.PutFloat(Y); builder.PutFloat(Y);
builder.PutFloat(X); builder.PutFloat(X);
return builder.Offset; return builder.Offset();
} }
}; };
......
...@@ -36,5 +36,7 @@ ...@@ -36,5 +36,7 @@
testarrayofstring: [ testarrayofstring: [
"test1", "test1",
"test2" "test2"
] ],
testempty: {
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment