mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 22:03:40 +00:00
Fix C# vector of enum code generation
Fixes a bug where the logic to determine when to use a C# enum flags both enums and vectors of enums. This causes the C# generator to generate code that doesn't compile for tables that contain vectors of enums. The fix also consolidates type generation functions a bit and adds some additional casting functions for clarity.
This commit is contained in:
@@ -22,9 +22,9 @@ public sealed class Monster : Table {
|
||||
public byte GetInventory(int j) { int o = __offset(14); return o != 0 ? bb.Get(__vector(o) + j * 1) : (byte)0; }
|
||||
public int InventoryLength { get { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } }
|
||||
public bool MutateInventory(int j, byte inventory) { int o = __offset(14); if (o != 0) { bb.Put(__vector(o) + j * 1, inventory); return true; } else { return false; } }
|
||||
public Color Color { get { int o = __offset(16); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : (Color)8; } }
|
||||
public Color Color { get { int o = __offset(16); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : Color.Blue; } }
|
||||
public bool MutateColor(Color color) { int o = __offset(16); if (o != 0) { bb.PutSbyte(o + bb_pos, (sbyte)color); return true; } else { return false; } }
|
||||
public Any TestType { get { int o = __offset(18); return o != 0 ? (Any)bb.Get(o + bb_pos) : (Any)0; } }
|
||||
public Any TestType { get { int o = __offset(18); return o != 0 ? (Any)bb.Get(o + bb_pos) : Any.NONE; } }
|
||||
public bool MutateTestType(Any test_type) { int o = __offset(18); if (o != 0) { bb.Put(o + bb_pos, (byte)test_type); return true; } else { return false; } }
|
||||
public TTable GetTest<TTable>(TTable obj) where TTable : Table { int o = __offset(20); return o != 0 ? __union(obj, o) : null; }
|
||||
public Test GetTest4(int j) { return GetTest4(new Test(), j); }
|
||||
@@ -74,8 +74,8 @@ public sealed class Monster : Table {
|
||||
public static void AddInventory(FlatBufferBuilder builder, VectorOffset inventoryOffset) { builder.AddOffset(5, inventoryOffset.Value, 0); }
|
||||
public static VectorOffset CreateInventoryVector(FlatBufferBuilder builder, byte[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddByte(data[i]); return builder.EndVector(); }
|
||||
public static void StartInventoryVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
|
||||
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(6, (sbyte)(color), 8); }
|
||||
public static void AddTestType(FlatBufferBuilder builder, Any testType) { builder.AddByte(7, (byte)(testType), 0); }
|
||||
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(6, (sbyte)color, 8); }
|
||||
public static void AddTestType(FlatBufferBuilder builder, Any testType) { builder.AddByte(7, (byte)testType, 0); }
|
||||
public static void AddTest(FlatBufferBuilder builder, int testOffset) { builder.AddOffset(8, testOffset, 0); }
|
||||
public static void AddTest4(FlatBufferBuilder builder, VectorOffset test4Offset) { builder.AddOffset(9, test4Offset.Value, 0); }
|
||||
public static void StartTest4Vector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 2); }
|
||||
|
||||
@@ -103,11 +103,11 @@ public final class Monster extends Table {
|
||||
public static void addTestempty(FlatBufferBuilder builder, int testemptyOffset) { builder.addOffset(14, testemptyOffset, 0); }
|
||||
public static void addTestbool(FlatBufferBuilder builder, boolean testbool) { builder.addBoolean(15, testbool, false); }
|
||||
public static void addTesthashs32Fnv1(FlatBufferBuilder builder, int testhashs32Fnv1) { builder.addInt(16, testhashs32Fnv1, 0); }
|
||||
public static void addTesthashu32Fnv1(FlatBufferBuilder builder, long testhashu32Fnv1) { builder.addInt(17, (int)(testhashu32Fnv1 & 0xFFFFFFFFL), 0); }
|
||||
public static void addTesthashu32Fnv1(FlatBufferBuilder builder, long testhashu32Fnv1) { builder.addInt(17, (int)testhashu32Fnv1, 0); }
|
||||
public static void addTesthashs64Fnv1(FlatBufferBuilder builder, long testhashs64Fnv1) { builder.addLong(18, testhashs64Fnv1, 0); }
|
||||
public static void addTesthashu64Fnv1(FlatBufferBuilder builder, long testhashu64Fnv1) { builder.addLong(19, testhashu64Fnv1, 0); }
|
||||
public static void addTesthashs32Fnv1a(FlatBufferBuilder builder, int testhashs32Fnv1a) { builder.addInt(20, testhashs32Fnv1a, 0); }
|
||||
public static void addTesthashu32Fnv1a(FlatBufferBuilder builder, long testhashu32Fnv1a) { builder.addInt(21, (int)(testhashu32Fnv1a & 0xFFFFFFFFL), 0); }
|
||||
public static void addTesthashu32Fnv1a(FlatBufferBuilder builder, long testhashu32Fnv1a) { builder.addInt(21, (int)testhashu32Fnv1a, 0); }
|
||||
public static void addTesthashs64Fnv1a(FlatBufferBuilder builder, long testhashs64Fnv1a) { builder.addLong(22, testhashs64Fnv1a, 0); }
|
||||
public static void addTesthashu64Fnv1a(FlatBufferBuilder builder, long testhashu64Fnv1a) { builder.addLong(23, testhashu64Fnv1a, 0); }
|
||||
public static void addTestarrayofbools(FlatBufferBuilder builder, int testarrayofboolsOffset) { builder.addOffset(24, testarrayofboolsOffset, 0); }
|
||||
|
||||
@@ -17,12 +17,12 @@ public sealed class Stat : Table {
|
||||
public bool MutateCount(ushort count) { int o = __offset(8); if (o != 0) { bb.PutUshort(o + bb_pos, count); return true; } else { return false; } }
|
||||
|
||||
public static Offset<Stat> CreateStat(FlatBufferBuilder builder,
|
||||
StringOffset id = default(StringOffset),
|
||||
StringOffset idOffset = default(StringOffset),
|
||||
long val = 0,
|
||||
ushort count = 0) {
|
||||
builder.StartObject(3);
|
||||
Stat.AddVal(builder, val);
|
||||
Stat.AddId(builder, id);
|
||||
Stat.AddId(builder, idOffset);
|
||||
Stat.AddCount(builder, count);
|
||||
return Stat.EndStat(builder);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ public final class Stat extends Table {
|
||||
public boolean mutateCount(int count) { int o = __offset(8); if (o != 0) { bb.putShort(o + bb_pos, (short)count); return true; } else { return false; } }
|
||||
|
||||
public static int createStat(FlatBufferBuilder builder,
|
||||
int id,
|
||||
int idOffset,
|
||||
long val,
|
||||
int count) {
|
||||
builder.startObject(3);
|
||||
Stat.addVal(builder, val);
|
||||
Stat.addId(builder, id);
|
||||
Stat.addId(builder, idOffset);
|
||||
Stat.addCount(builder, count);
|
||||
return Stat.endStat(builder);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public final class Stat extends Table {
|
||||
public static void startStat(FlatBufferBuilder builder) { builder.startObject(3); }
|
||||
public static void addId(FlatBufferBuilder builder, int idOffset) { builder.addOffset(0, idOffset, 0); }
|
||||
public static void addVal(FlatBufferBuilder builder, long val) { builder.addLong(1, val, 0); }
|
||||
public static void addCount(FlatBufferBuilder builder, int count) { builder.addShort(2, (short)(count & 0xFFFF), 0); }
|
||||
public static void addCount(FlatBufferBuilder builder, int count) { builder.addShort(2, (short)count, 0); }
|
||||
public static int endStat(FlatBufferBuilder builder) {
|
||||
int o = builder.endObject();
|
||||
return o;
|
||||
|
||||
@@ -10,7 +10,7 @@ public sealed class TestSimpleTableWithEnum : Table {
|
||||
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 Color Color { get { int o = __offset(4); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : Color.Green; } }
|
||||
public bool MutateColor(Color color) { int o = __offset(4); if (o != 0) { bb.PutSbyte(o + bb_pos, (sbyte)color); return true; } else { return false; } }
|
||||
|
||||
public static Offset<TestSimpleTableWithEnum> CreateTestSimpleTableWithEnum(FlatBufferBuilder builder,
|
||||
@@ -21,7 +21,7 @@ public sealed class TestSimpleTableWithEnum : Table {
|
||||
}
|
||||
|
||||
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 void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)color, 2); }
|
||||
public static Offset<TestSimpleTableWithEnum> EndTestSimpleTableWithEnum(FlatBufferBuilder builder) {
|
||||
int o = builder.EndObject();
|
||||
return new Offset<TestSimpleTableWithEnum>(o);
|
||||
|
||||
@@ -29,7 +29,7 @@ public sealed class Vec3 : Struct {
|
||||
builder.PutSbyte(test3_B);
|
||||
builder.PutShort(test3_A);
|
||||
builder.Pad(1);
|
||||
builder.PutSbyte((sbyte)(Test2));
|
||||
builder.PutSbyte((sbyte)Test2);
|
||||
builder.PutDouble(Test1);
|
||||
builder.Pad(4);
|
||||
builder.PutFloat(Z);
|
||||
|
||||
Reference in New Issue
Block a user