forked from google/flatbuffers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 252] Add type cast for default enum values in C#
When creating a �CreateXxx(...)� method for a �simple table� type, enum-type fields with a non-zero default must have an explicit cast for the respective argument default value, because in C#, there is an implicit cast from int to an enum only for 0. Also, added an example of such type into the example monster_test type, so that we test this feature.
- Loading branch information
1 parent
e151160
commit 25c9927
Showing
10 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ public enum Any : byte | |
{ | ||
NONE = 0, | ||
Monster = 1, | ||
TestSimpleTableWithEnum = 2, | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ package Example | |
const ( | ||
AnyNONE = 0 | ||
AnyMonster = 1 | ||
AnyTestSimpleTableWithEnum = 2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestSimpleTableWithEnum> 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<TestSimpleTableWithEnum> EndTestSimpleTableWithEnum(FlatBufferBuilder builder) { | ||
int o = builder.EndObject(); | ||
return new Offset<TestSimpleTableWithEnum>(o); | ||
} | ||
}; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters