[Javascript] Fix syntax error for signed enum (#5503)
* wrap quotes to enum name map to prevent syntax errorn when enum value is negative * Add a test that covers signed enum case
This commit is contained in:
parent
d0e3870c0f
commit
4b870aca98
|
@ -11,6 +11,7 @@ import 'include_test2_my_game.example_generated.dart';
|
|||
import './monster_test_my_game_generated.dart' as my_game;
|
||||
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||
|
||||
/// Composite components of Monster color.
|
||||
class Color {
|
||||
final int value;
|
||||
const Color._(this.value);
|
||||
|
@ -26,7 +27,12 @@ class Color {
|
|||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Color Red = const Color._(1);
|
||||
|
||||
/// \brief color Green
|
||||
/// Green is bit_flag with value (1u << 1)
|
||||
static const Color Green = const Color._(2);
|
||||
|
||||
/// \brief color Blue (1u << 3)
|
||||
static const Color Blue = const Color._(8);
|
||||
static get values => {1: Red,2: Green,8: Blue,};
|
||||
|
||||
|
@ -46,7 +52,48 @@ class _ColorReader extends fb.Reader<Color> {
|
|||
|
||||
@override
|
||||
Color read(fb.BufferContext bc, int offset) =>
|
||||
new Color.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||
new Color.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class Race {
|
||||
final int value;
|
||||
const Race._(this.value);
|
||||
|
||||
factory Race.fromValue(int value) {
|
||||
if (value == null) value = 0;
|
||||
if (!values.containsKey(value)) {
|
||||
throw new StateError('Invalid value $value for bit flag enum Race');
|
||||
}
|
||||
return values[value];
|
||||
}
|
||||
|
||||
static const int minValue = -1;
|
||||
static const int maxValue = 2;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Race None = const Race._(-1);
|
||||
static const Race Human = const Race._(0);
|
||||
static const Race Dwarf = const Race._(1);
|
||||
static const Race Elf = const Race._(2);
|
||||
static get values => {-1: None,0: Human,1: Dwarf,2: Elf,};
|
||||
|
||||
static const fb.Reader<Race> reader = const _RaceReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Race{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _RaceReader extends fb.Reader<Race> {
|
||||
const _RaceReader();
|
||||
|
||||
@override
|
||||
int get size => 1;
|
||||
|
||||
@override
|
||||
Race read(fb.BufferContext bc, int offset) =>
|
||||
new Race.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class AnyTypeId {
|
||||
|
@ -108,9 +155,9 @@ class AnyUniqueAliasesTypeId {
|
|||
|
||||
static const AnyUniqueAliasesTypeId NONE = const AnyUniqueAliasesTypeId._(0);
|
||||
static const AnyUniqueAliasesTypeId M = const AnyUniqueAliasesTypeId._(1);
|
||||
static const AnyUniqueAliasesTypeId T = const AnyUniqueAliasesTypeId._(2);
|
||||
static const AnyUniqueAliasesTypeId TS = const AnyUniqueAliasesTypeId._(2);
|
||||
static const AnyUniqueAliasesTypeId M2 = const AnyUniqueAliasesTypeId._(3);
|
||||
static get values => {0: NONE,1: M,2: T,3: M2,};
|
||||
static get values => {0: NONE,1: M,2: TS,3: M2,};
|
||||
|
||||
static const fb.Reader<AnyUniqueAliasesTypeId> reader = const _AnyUniqueAliasesTypeIdReader();
|
||||
|
||||
|
@ -259,7 +306,7 @@ class TestSimpleTableWithEnum {
|
|||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 4, 2));
|
||||
Color get color => new Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 4, 2));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
@ -287,7 +334,7 @@ class TestSimpleTableWithEnumBuilder {
|
|||
}
|
||||
|
||||
int addColor(Color color) {
|
||||
fbBuilder.addInt8(0, color?.value);
|
||||
fbBuilder.addUint8(0, color?.value);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
|
@ -311,7 +358,7 @@ class TestSimpleTableWithEnumObjectBuilder extends fb.ObjectBuilder {
|
|||
assert(fbBuilder != null);
|
||||
|
||||
fbBuilder.startTable();
|
||||
fbBuilder.addInt8(0, _color?.value);
|
||||
fbBuilder.addUint8(0, _color?.value);
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
|
@ -335,7 +382,7 @@ class Vec3 {
|
|||
double get y => const fb.Float32Reader().read(_bc, _bcOffset + 4);
|
||||
double get z => const fb.Float32Reader().read(_bc, _bcOffset + 8);
|
||||
double get test1 => const fb.Float64Reader().read(_bc, _bcOffset + 16);
|
||||
Color get test2 => new Color.fromValue(const fb.Int8Reader().read(_bc, _bcOffset + 24));
|
||||
Color get test2 => new Color.fromValue(const fb.Uint8Reader().read(_bc, _bcOffset + 24));
|
||||
Test get test3 => Test.reader.read(_bc, _bcOffset + 26);
|
||||
|
||||
@override
|
||||
|
@ -366,7 +413,7 @@ class Vec3Builder {
|
|||
fbBuilder.pad(2);
|
||||
test3();
|
||||
fbBuilder.pad(1);
|
||||
fbBuilder.putInt8(test2?.value);
|
||||
fbBuilder.putUint8(test2?.value);
|
||||
fbBuilder.putFloat64(test1);
|
||||
fbBuilder.pad(4);
|
||||
fbBuilder.putFloat32(z);
|
||||
|
@ -409,7 +456,7 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||
fbBuilder.pad(2);
|
||||
_test3.finish(fbBuilder);
|
||||
fbBuilder.pad(1);
|
||||
fbBuilder.putInt8(_test2?.value);
|
||||
fbBuilder.putUint8(_test2?.value);
|
||||
fbBuilder.putFloat64(_test1);
|
||||
fbBuilder.pad(4);
|
||||
fbBuilder.putFloat32(_z);
|
||||
|
@ -690,7 +737,7 @@ class Monster {
|
|||
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
|
||||
String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 10, null);
|
||||
List<int> get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 14, null);
|
||||
Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 8));
|
||||
Color get color => new Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 16, 8));
|
||||
AnyTypeId get testType => new AnyTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 18, 0));
|
||||
dynamic get test {
|
||||
switch (testType?.value) {
|
||||
|
@ -702,8 +749,8 @@ class Monster {
|
|||
}
|
||||
List<Test> get test4 => const fb.ListReader<Test>(Test.reader).vTableGet(_bc, _bcOffset, 22, null);
|
||||
List<String> get testarrayofstring => const fb.ListReader<String>(const fb.StringReader()).vTableGet(_bc, _bcOffset, 24, null);
|
||||
/// an example documentation comment: this will end up in the generated code
|
||||
/// multiline too
|
||||
/// an example documentation comment: this will end up in the generated code
|
||||
/// multiline too
|
||||
List<Monster> get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGet(_bc, _bcOffset, 26, null);
|
||||
Monster get enemy => Monster.reader.vTableGet(_bc, _bcOffset, 28, null);
|
||||
List<int> get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 30, null);
|
||||
|
@ -740,7 +787,7 @@ class Monster {
|
|||
dynamic get anyUnique {
|
||||
switch (anyUniqueType?.value) {
|
||||
case 1: return M.reader.vTableGet(_bc, _bcOffset, 92, null);
|
||||
case 2: return T.reader.vTableGet(_bc, _bcOffset, 92, null);
|
||||
case 2: return TS.reader.vTableGet(_bc, _bcOffset, 92, null);
|
||||
case 3: return M2.reader.vTableGet(_bc, _bcOffset, 92, null);
|
||||
default: return null;
|
||||
}
|
||||
|
@ -755,10 +802,11 @@ class Monster {
|
|||
}
|
||||
}
|
||||
List<Color> get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGet(_bc, _bcOffset, 98, null);
|
||||
Race get signedEnum => new Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums}';
|
||||
return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum}';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -802,7 +850,7 @@ class MonsterBuilder {
|
|||
return fbBuilder.offset;
|
||||
}
|
||||
int addColor(Color color) {
|
||||
fbBuilder.addInt8(6, color?.value);
|
||||
fbBuilder.addUint8(6, color?.value);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
int addTestType(AnyTypeId testType) {
|
||||
|
@ -969,6 +1017,10 @@ class MonsterBuilder {
|
|||
fbBuilder.addOffset(47, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
int addSignedEnum(Race signedEnum) {
|
||||
fbBuilder.addInt8(48, signedEnum?.value);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int finish() {
|
||||
return fbBuilder.endTable();
|
||||
|
@ -1023,6 +1075,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
final AnyAmbiguousAliasesTypeId _anyAmbiguousType;
|
||||
final dynamic _anyAmbiguous;
|
||||
final List<Color> _vectorOfEnums;
|
||||
final Race _signedEnum;
|
||||
|
||||
MonsterObjectBuilder({
|
||||
Vec3ObjectBuilder pos,
|
||||
|
@ -1072,6 +1125,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
AnyAmbiguousAliasesTypeId anyAmbiguousType,
|
||||
dynamic anyAmbiguous,
|
||||
List<Color> vectorOfEnums,
|
||||
Race signedEnum,
|
||||
})
|
||||
: _pos = pos,
|
||||
_mana = mana,
|
||||
|
@ -1119,7 +1173,8 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
_anyUnique = anyUnique,
|
||||
_anyAmbiguousType = anyAmbiguousType,
|
||||
_anyAmbiguous = anyAmbiguous,
|
||||
_vectorOfEnums = vectorOfEnums;
|
||||
_vectorOfEnums = vectorOfEnums,
|
||||
_signedEnum = signedEnum;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
|
@ -1185,7 +1240,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
final int anyUniqueOffset = _anyUnique?.getOrCreateOffset(fbBuilder);
|
||||
final int anyAmbiguousOffset = _anyAmbiguous?.getOrCreateOffset(fbBuilder);
|
||||
final int vectorOfEnumsOffset = _vectorOfEnums?.isNotEmpty == true
|
||||
? fbBuilder.writeListInt8(_vectorOfEnums.map((f) => f.value))
|
||||
? fbBuilder.writeListUint8(_vectorOfEnums.map((f) => f.value))
|
||||
: null;
|
||||
|
||||
fbBuilder.startTable();
|
||||
|
@ -1200,7 +1255,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
if (inventoryOffset != null) {
|
||||
fbBuilder.addOffset(5, inventoryOffset);
|
||||
}
|
||||
fbBuilder.addInt8(6, _color?.value);
|
||||
fbBuilder.addUint8(6, _color?.value);
|
||||
fbBuilder.addUint8(7, _testType?.value);
|
||||
if (testOffset != null) {
|
||||
fbBuilder.addOffset(8, testOffset);
|
||||
|
@ -1288,6 +1343,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
if (vectorOfEnumsOffset != null) {
|
||||
fbBuilder.addOffset(47, vectorOfEnumsOffset);
|
||||
}
|
||||
fbBuilder.addInt8(48, _signedEnum?.value);
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ class JsTsGenerator : public BaseGenerator {
|
|||
|
||||
// Generate mapping between EnumName: EnumValue(int)
|
||||
if (reverse) {
|
||||
code += " " + enum_def.ToString(ev);
|
||||
code += " '" + enum_def.ToString(ev) + "'";
|
||||
code += lang_.language == IDLOptions::kTs ? "= " : ": ";
|
||||
code += "'" + ev.name + "'";
|
||||
} else {
|
||||
|
|
|
@ -78,6 +78,9 @@
|
|||
<Compile Include="..\MyGame\Example\Color.cs">
|
||||
<Link>MyGame\Example\Color.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Race.cs">
|
||||
<Link>MyGame\Example\Race.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\Monster.cs">
|
||||
<Link>MyGame\Example\Monster.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -188,8 +188,10 @@ public struct Monster : IFlatbufferObject
|
|||
#endif
|
||||
public MyGame.Example.Color[] GetVectorOfEnumsArray() { int o = __p.__offset(98); if (o == 0) return null; int p = __p.__vector(o); int l = __p.__vector_len(o); MyGame.Example.Color[] a = new MyGame.Example.Color[l]; for (int i = 0; i < l; i++) { a[i] = (MyGame.Example.Color)__p.bb.Get(p + i * 1); } return a; }
|
||||
public bool MutateVectorOfEnums(int j, MyGame.Example.Color vector_of_enums) { int o = __p.__offset(98); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, (byte)vector_of_enums); return true; } else { return false; } }
|
||||
public MyGame.Example.Race SignedEnum { get { int o = __p.__offset(100); return o != 0 ? (MyGame.Example.Race)__p.bb.GetSbyte(o + __p.bb_pos) : MyGame.Example.Race.None; } }
|
||||
public bool MutateSignedEnum(MyGame.Example.Race signed_enum) { int o = __p.__offset(100); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)signed_enum); return true; } else { return false; } }
|
||||
|
||||
public static void StartMonster(FlatBufferBuilder builder) { builder.StartTable(48); }
|
||||
public static void StartMonster(FlatBufferBuilder builder) { builder.StartTable(49); }
|
||||
public static void AddPos(FlatBufferBuilder builder, Offset<MyGame.Example.Vec3> posOffset) { builder.AddStruct(0, posOffset.Value, 0); }
|
||||
public static void AddMana(FlatBufferBuilder builder, short mana) { builder.AddShort(1, mana, 150); }
|
||||
public static void AddHp(FlatBufferBuilder builder, short hp) { builder.AddShort(2, hp, 100); }
|
||||
|
@ -284,6 +286,7 @@ public struct Monster : IFlatbufferObject
|
|||
public static void AddVectorOfEnums(FlatBufferBuilder builder, VectorOffset vectorOfEnumsOffset) { builder.AddOffset(47, vectorOfEnumsOffset.Value, 0); }
|
||||
public static VectorOffset CreateVectorOfEnumsVector(FlatBufferBuilder builder, MyGame.Example.Color[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddByte((byte)data[i]); return builder.EndVector(); }
|
||||
public static void StartVectorOfEnumsVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
|
||||
public static void AddSignedEnum(FlatBufferBuilder builder, MyGame.Example.Race signedEnum) { builder.AddSbyte(48, (sbyte)signedEnum, -1); }
|
||||
public static Offset<MyGame.Example.Monster> EndMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
builder.Required(o, 10); // name
|
||||
|
|
|
@ -815,8 +815,20 @@ func (rcv *Monster) MutateVectorOfEnums(j int, n Color) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (rcv *Monster) SignedEnum() Race {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(100))
|
||||
if o != 0 {
|
||||
return Race(rcv._tab.GetInt8(o + rcv._tab.Pos))
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func (rcv *Monster) MutateSignedEnum(n Race) bool {
|
||||
return rcv._tab.MutateInt8Slot(100, int8(n))
|
||||
}
|
||||
|
||||
func MonsterStart(builder *flatbuffers.Builder) {
|
||||
builder.StartObject(48)
|
||||
builder.StartObject(49)
|
||||
}
|
||||
func MonsterAddPos(builder *flatbuffers.Builder, pos flatbuffers.UOffsetT) {
|
||||
builder.PrependStructSlot(0, flatbuffers.UOffsetT(pos), 0)
|
||||
|
@ -1013,6 +1025,9 @@ func MonsterAddVectorOfEnums(builder *flatbuffers.Builder, vectorOfEnums flatbuf
|
|||
func MonsterStartVectorOfEnumsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
|
||||
return builder.StartVector(1, numElems, 1)
|
||||
}
|
||||
func MonsterAddSignedEnum(builder *flatbuffers.Builder, signedEnum Race) {
|
||||
builder.PrependInt8Slot(48, int8(signedEnum), -1)
|
||||
}
|
||||
func MonsterEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
return builder.EndObject()
|
||||
}
|
||||
|
|
|
@ -159,8 +159,10 @@ public final class Monster extends Table {
|
|||
public ByteBuffer vectorOfEnumsAsByteBuffer() { return __vector_as_bytebuffer(98, 1); }
|
||||
public ByteBuffer vectorOfEnumsInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 98, 1); }
|
||||
public boolean mutateVectorOfEnums(int j, int vector_of_enums) { int o = __offset(98); if (o != 0) { bb.put(__vector(o) + j * 1, (byte)vector_of_enums); return true; } else { return false; } }
|
||||
public byte signedEnum() { int o = __offset(100); return o != 0 ? bb.get(o + bb_pos) : -1; }
|
||||
public boolean mutateSignedEnum(byte signed_enum) { int o = __offset(100); if (o != 0) { bb.put(o + bb_pos, signed_enum); return true; } else { return false; } }
|
||||
|
||||
public static void startMonster(FlatBufferBuilder builder) { builder.startTable(48); }
|
||||
public static void startMonster(FlatBufferBuilder builder) { builder.startTable(49); }
|
||||
public static void addPos(FlatBufferBuilder builder, int posOffset) { builder.addStruct(0, posOffset, 0); }
|
||||
public static void addMana(FlatBufferBuilder builder, short mana) { builder.addShort(1, mana, 150); }
|
||||
public static void addHp(FlatBufferBuilder builder, short hp) { builder.addShort(2, hp, 100); }
|
||||
|
@ -241,6 +243,7 @@ public final class Monster extends Table {
|
|||
public static void addVectorOfEnums(FlatBufferBuilder builder, int vectorOfEnumsOffset) { builder.addOffset(47, vectorOfEnumsOffset, 0); }
|
||||
public static int createVectorOfEnumsVector(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 startVectorOfEnumsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(1, numElems, 1); }
|
||||
public static void addSignedEnum(FlatBufferBuilder builder, byte signedEnum) { builder.addByte(48, signedEnum, -1); }
|
||||
public static int endMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 10); // name
|
||||
|
|
|
@ -759,6 +759,20 @@ class Monster : Table() {
|
|||
false
|
||||
}
|
||||
}
|
||||
val signedEnum : Byte
|
||||
get() {
|
||||
val o = __offset(100)
|
||||
return if(o != 0) bb.get(o + bb_pos) else -1
|
||||
}
|
||||
fun mutateSignedEnum(signedEnum: Byte) : Boolean {
|
||||
val o = __offset(100)
|
||||
return if (o != 0) {
|
||||
bb.put(o + bb_pos, signedEnum)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
override fun keysCompare(o1: Int, o2: Int, _bb: ByteBuffer) : Int {
|
||||
return compareStrings(__offset(10, o1, _bb), __offset(10, o2, _bb), _bb)
|
||||
}
|
||||
|
@ -770,7 +784,7 @@ class Monster : Table() {
|
|||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun MonsterBufferHasIdentifier(_bb: ByteBuffer) : Boolean = __has_identifier(_bb, "MONS")
|
||||
fun startMonster(builder: FlatBufferBuilder) = builder.startTable(48)
|
||||
fun startMonster(builder: FlatBufferBuilder) = builder.startTable(49)
|
||||
fun addPos(builder: FlatBufferBuilder, pos: Int) = builder.addStruct(0, pos, 0)
|
||||
fun addMana(builder: FlatBufferBuilder, mana: Short) = builder.addShort(1, mana, 150)
|
||||
fun addHp(builder: FlatBufferBuilder, hp: Short) = builder.addShort(2, hp, 100)
|
||||
|
@ -941,6 +955,7 @@ class Monster : Table() {
|
|||
return builder.endVector()
|
||||
}
|
||||
fun startVectorOfEnumsVector(builder: FlatBufferBuilder, numElems: Int) = builder.startVector(1, numElems, 1)
|
||||
fun addSignedEnum(builder: FlatBufferBuilder, signedEnum: Byte) = builder.addByte(48, signedEnum, -1)
|
||||
fun endMonster(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
builder.required(o, 10)
|
||||
|
|
|
@ -522,7 +522,14 @@ function Monster_mt:VectorOfEnumsLength()
|
|||
end
|
||||
return 0
|
||||
end
|
||||
function Monster.Start(builder) builder:StartObject(48) end
|
||||
function Monster_mt:SignedEnum()
|
||||
local o = self.view:Offset(100)
|
||||
if o ~= 0 then
|
||||
return self.view:Get(flatbuffers.N.Int8, o + self.view.pos)
|
||||
end
|
||||
return -1
|
||||
end
|
||||
function Monster.Start(builder) builder:StartObject(49) end
|
||||
function Monster.AddPos(builder, pos) builder:PrependStructSlot(0, pos, 0) end
|
||||
function Monster.AddMana(builder, mana) builder:PrependInt16Slot(1, mana, 150) end
|
||||
function Monster.AddHp(builder, hp) builder:PrependInt16Slot(2, hp, 100) end
|
||||
|
@ -588,6 +595,7 @@ function Monster.AddAnyAmbiguousType(builder, anyAmbiguousType) builder:PrependU
|
|||
function Monster.AddAnyAmbiguous(builder, anyAmbiguous) builder:PrependUOffsetTRelativeSlot(46, anyAmbiguous, 0) end
|
||||
function Monster.AddVectorOfEnums(builder, vectorOfEnums) builder:PrependUOffsetTRelativeSlot(47, vectorOfEnums, 0) end
|
||||
function Monster.StartVectorOfEnumsVector(builder, numElems) return builder:StartVector(1, numElems, 1) end
|
||||
function Monster.AddSignedEnum(builder, signedEnum) builder:PrependInt8Slot(48, signedEnum, -1) end
|
||||
function Monster.End(builder) return builder:EndObject() end
|
||||
|
||||
return Monster -- return the module
|
|
@ -674,22 +674,31 @@ class Monster extends Table
|
|||
return $this->__vector_as_bytes(98);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sbyte
|
||||
*/
|
||||
public function getSignedEnum()
|
||||
{
|
||||
$o = $this->__offset(100);
|
||||
return $o != 0 ? $this->bb->getSbyte($o + $this->bb_pos) : \MyGame\Example\Race::None;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startMonster(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(48);
|
||||
$builder->StartObject(49);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return Monster
|
||||
*/
|
||||
public static function createMonster(FlatBufferBuilder $builder, $pos, $mana, $hp, $name, $inventory, $color, $test_type, $test, $test4, $testarrayofstring, $testarrayoftables, $enemy, $testnestedflatbuffer, $testempty, $testbool, $testhashs32_fnv1, $testhashu32_fnv1, $testhashs64_fnv1, $testhashu64_fnv1, $testhashs32_fnv1a, $testhashu32_fnv1a, $testhashs64_fnv1a, $testhashu64_fnv1a, $testarrayofbools, $testf, $testf2, $testf3, $testarrayofstring2, $testarrayofsortedstruct, $flex, $test5, $vector_of_longs, $vector_of_doubles, $parent_namespace_test, $vector_of_referrables, $single_weak_reference, $vector_of_weak_references, $vector_of_strong_referrables, $co_owning_reference, $vector_of_co_owning_references, $non_owning_reference, $vector_of_non_owning_references, $any_unique_type, $any_unique, $any_ambiguous_type, $any_ambiguous, $vector_of_enums)
|
||||
public static function createMonster(FlatBufferBuilder $builder, $pos, $mana, $hp, $name, $inventory, $color, $test_type, $test, $test4, $testarrayofstring, $testarrayoftables, $enemy, $testnestedflatbuffer, $testempty, $testbool, $testhashs32_fnv1, $testhashu32_fnv1, $testhashs64_fnv1, $testhashu64_fnv1, $testhashs32_fnv1a, $testhashu32_fnv1a, $testhashs64_fnv1a, $testhashu64_fnv1a, $testarrayofbools, $testf, $testf2, $testf3, $testarrayofstring2, $testarrayofsortedstruct, $flex, $test5, $vector_of_longs, $vector_of_doubles, $parent_namespace_test, $vector_of_referrables, $single_weak_reference, $vector_of_weak_references, $vector_of_strong_referrables, $co_owning_reference, $vector_of_co_owning_references, $non_owning_reference, $vector_of_non_owning_references, $any_unique_type, $any_unique, $any_ambiguous_type, $any_ambiguous, $vector_of_enums, $signed_enum)
|
||||
{
|
||||
$builder->startObject(48);
|
||||
$builder->startObject(49);
|
||||
self::addPos($builder, $pos);
|
||||
self::addMana($builder, $mana);
|
||||
self::addHp($builder, $hp);
|
||||
|
@ -737,6 +746,7 @@ class Monster extends Table
|
|||
self::addAnyAmbiguousType($builder, $any_ambiguous_type);
|
||||
self::addAnyAmbiguous($builder, $any_ambiguous);
|
||||
self::addVectorOfEnums($builder, $vector_of_enums);
|
||||
self::addSignedEnum($builder, $signed_enum);
|
||||
$o = $builder->endObject();
|
||||
$builder->required($o, 10); // name
|
||||
return $o;
|
||||
|
@ -1629,6 +1639,16 @@ class Monster extends Table
|
|||
$builder->startVector(1, $numElems, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param sbyte
|
||||
* @return void
|
||||
*/
|
||||
public static function addSignedEnum(FlatBufferBuilder $builder, $signedEnum)
|
||||
{
|
||||
$builder->addSbyteX(48, $signedEnum, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
|
|
|
@ -620,7 +620,14 @@ class Monster(object):
|
|||
return self._tab.VectorLen(o)
|
||||
return 0
|
||||
|
||||
def MonsterStart(builder): builder.StartObject(48)
|
||||
# Monster
|
||||
def SignedEnum(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(100))
|
||||
if o != 0:
|
||||
return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos)
|
||||
return -1
|
||||
|
||||
def MonsterStart(builder): builder.StartObject(49)
|
||||
def MonsterAddPos(builder, pos): builder.PrependStructSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(pos), 0)
|
||||
def MonsterAddMana(builder, mana): builder.PrependInt16Slot(1, mana, 150)
|
||||
def MonsterAddHp(builder, hp): builder.PrependInt16Slot(2, hp, 100)
|
||||
|
@ -686,4 +693,5 @@ def MonsterAddAnyAmbiguousType(builder, anyAmbiguousType): builder.PrependUint8S
|
|||
def MonsterAddAnyAmbiguous(builder, anyAmbiguous): builder.PrependUOffsetTRelativeSlot(46, flatbuffers.number_types.UOffsetTFlags.py_type(anyAmbiguous), 0)
|
||||
def MonsterAddVectorOfEnums(builder, vectorOfEnums): builder.PrependUOffsetTRelativeSlot(47, flatbuffers.number_types.UOffsetTFlags.py_type(vectorOfEnums), 0)
|
||||
def MonsterStartVectorOfEnumsVector(builder, numElems): return builder.StartVector(1, numElems, 1)
|
||||
def MonsterAddSignedEnum(builder, signedEnum): builder.PrependInt8Slot(48, signedEnum, -1)
|
||||
def MonsterEnd(builder): return builder.EndObject()
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace MyGame.Example
|
||||
{
|
||||
|
||||
public enum Race : sbyte
|
||||
{
|
||||
None = -1,
|
||||
Human = 0,
|
||||
Dwarf = 1,
|
||||
Elf = 2,
|
||||
};
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Example
|
||||
|
||||
import "strconv"
|
||||
|
||||
type Race int8
|
||||
|
||||
const (
|
||||
RaceNone Race = -1
|
||||
RaceHuman Race = 0
|
||||
RaceDwarf Race = 1
|
||||
RaceElf Race = 2
|
||||
)
|
||||
|
||||
var EnumNamesRace = map[Race]string{
|
||||
RaceNone: "None",
|
||||
RaceHuman: "Human",
|
||||
RaceDwarf: "Dwarf",
|
||||
RaceElf: "Elf",
|
||||
}
|
||||
|
||||
var EnumValuesRace = map[string]Race{
|
||||
"None": RaceNone,
|
||||
"Human": RaceHuman,
|
||||
"Dwarf": RaceDwarf,
|
||||
"Elf": RaceElf,
|
||||
}
|
||||
|
||||
func (v Race) String() string {
|
||||
if s, ok := EnumNamesRace[v]; ok {
|
||||
return s
|
||||
}
|
||||
return "Race(" + strconv.FormatInt(int64(v), 10) + ")"
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example;
|
||||
|
||||
public final class Race {
|
||||
private Race() { }
|
||||
public static final byte None = -1;
|
||||
public static final byte Human = 0;
|
||||
public static final byte Dwarf = 1;
|
||||
public static final byte Elf = 2;
|
||||
|
||||
public static final String[] names = { "None", "Human", "Dwarf", "Elf", };
|
||||
|
||||
public static String name(int e) { return names[e - None]; }
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Example
|
||||
|
||||
@Suppress("unused")
|
||||
@ExperimentalUnsignedTypes
|
||||
class Race private constructor() {
|
||||
companion object {
|
||||
const val None: Byte = -1
|
||||
const val Human: Byte = 0
|
||||
const val Dwarf: Byte = 1
|
||||
const val Elf: Byte = 2
|
||||
val names : Array<String> = arrayOf("None", "Human", "Dwarf", "Elf")
|
||||
fun name(e: Int) : String = names[e - None.toInt()]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
-- automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
-- namespace: Example
|
||||
|
||||
local Race = {
|
||||
None = -1,
|
||||
Human = 0,
|
||||
Dwarf = 1,
|
||||
Elf = 2,
|
||||
}
|
||||
|
||||
return Race -- return the module
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace MyGame\Example;
|
||||
|
||||
class Race
|
||||
{
|
||||
const None = -1;
|
||||
const Human = 0;
|
||||
const Dwarf = 1;
|
||||
const Elf = 2;
|
||||
|
||||
private static $names = array(
|
||||
Race::None=>"None",
|
||||
Race::Human=>"Human",
|
||||
Race::Dwarf=>"Dwarf",
|
||||
Race::Elf=>"Elf",
|
||||
);
|
||||
|
||||
public static function Name($e)
|
||||
{
|
||||
if (!isset(self::$names[$e])) {
|
||||
throw new \Exception();
|
||||
}
|
||||
return self::$names[$e];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: Example
|
||||
|
||||
class Race(object):
|
||||
None_ = -1
|
||||
Human = 0
|
||||
Dwarf = 1
|
||||
Elf = 2
|
||||
|
Binary file not shown.
Binary file not shown.
|
@ -24,6 +24,13 @@ enum Color:ubyte (bit_flags) {
|
|||
Blue = 3,
|
||||
}
|
||||
|
||||
enum Race:byte {
|
||||
None = -1,
|
||||
Human = 0,
|
||||
Dwarf,
|
||||
Elf,
|
||||
}
|
||||
|
||||
union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster }
|
||||
|
||||
union AnyUniqueAliases { M: Monster, TS: TestSimpleTableWithEnum, M2: MyGame.Example2.Monster }
|
||||
|
@ -108,6 +115,7 @@ table Monster {
|
|||
any_unique:AnyUniqueAliases(id:44);
|
||||
any_ambiguous:AnyAmbiguousAliases (id:46);
|
||||
vector_of_enums:[Color] (id:47);
|
||||
signed_enum:Race = None (id:48);
|
||||
}
|
||||
|
||||
table TypeAliases {
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
"type" : "string",
|
||||
"enum": ["Red", "Green", "Blue"]
|
||||
},
|
||||
"MyGame_Example_Race" : {
|
||||
"type" : "string",
|
||||
"enum": ["None", "Human", "Dwarf", "Elf"]
|
||||
},
|
||||
"MyGame_Example_Any" : {
|
||||
"type" : "string",
|
||||
"enum": ["NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster"]
|
||||
|
@ -288,6 +292,9 @@
|
|||
},
|
||||
"vector_of_enums" : {
|
||||
"$ref" : "#/definitions/MyGame_Example_Color"
|
||||
},
|
||||
"signed_enum" : {
|
||||
"$ref" : "#/definitions/MyGame_Example_Race"
|
||||
}
|
||||
},
|
||||
"required" : ["name"],
|
||||
|
|
|
@ -141,6 +141,42 @@ inline const char *EnumNameColor(Color e) {
|
|||
return EnumNamesColor()[index];
|
||||
}
|
||||
|
||||
enum Race {
|
||||
Race_None = -1,
|
||||
Race_Human = 0,
|
||||
Race_Dwarf = 1,
|
||||
Race_Elf = 2,
|
||||
Race_MIN = Race_None,
|
||||
Race_MAX = Race_Elf
|
||||
};
|
||||
|
||||
inline const Race (&EnumValuesRace())[4] {
|
||||
static const Race values[] = {
|
||||
Race_None,
|
||||
Race_Human,
|
||||
Race_Dwarf,
|
||||
Race_Elf
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesRace() {
|
||||
static const char * const names[5] = {
|
||||
"None",
|
||||
"Human",
|
||||
"Dwarf",
|
||||
"Elf",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameRace(Race e) {
|
||||
if (e < Race_None || e > Race_Elf) return "";
|
||||
const size_t index = static_cast<size_t>(e) - static_cast<size_t>(Race_None);
|
||||
return EnumNamesRace()[index];
|
||||
}
|
||||
|
||||
enum Any {
|
||||
Any_NONE = 0,
|
||||
Any_Monster = 1,
|
||||
|
@ -1138,6 +1174,7 @@ struct MonsterT : public flatbuffers::NativeTable {
|
|||
AnyUniqueAliasesUnion any_unique;
|
||||
AnyAmbiguousAliasesUnion any_ambiguous;
|
||||
std::vector<MyGame::Example::Color> vector_of_enums;
|
||||
MyGame::Example::Race signed_enum;
|
||||
MonsterT()
|
||||
: mana(150),
|
||||
hp(100),
|
||||
|
@ -1156,7 +1193,8 @@ struct MonsterT : public flatbuffers::NativeTable {
|
|||
testf3(0.0f),
|
||||
single_weak_reference(nullptr),
|
||||
co_owning_reference(nullptr),
|
||||
non_owning_reference(nullptr) {
|
||||
non_owning_reference(nullptr),
|
||||
signed_enum(MyGame::Example::Race_None) {
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1205,7 +1243,8 @@ inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
|||
(lhs.vector_of_non_owning_references == rhs.vector_of_non_owning_references) &&
|
||||
(lhs.any_unique == rhs.any_unique) &&
|
||||
(lhs.any_ambiguous == rhs.any_ambiguous) &&
|
||||
(lhs.vector_of_enums == rhs.vector_of_enums);
|
||||
(lhs.vector_of_enums == rhs.vector_of_enums) &&
|
||||
(lhs.signed_enum == rhs.signed_enum);
|
||||
}
|
||||
|
||||
inline bool operator!=(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
|
@ -1266,7 +1305,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||
VT_ANY_UNIQUE = 92,
|
||||
VT_ANY_AMBIGUOUS_TYPE = 94,
|
||||
VT_ANY_AMBIGUOUS = 96,
|
||||
VT_VECTOR_OF_ENUMS = 98
|
||||
VT_VECTOR_OF_ENUMS = 98,
|
||||
VT_SIGNED_ENUM = 100
|
||||
};
|
||||
const MyGame::Example::Vec3 *pos() const {
|
||||
return GetStruct<const MyGame::Example::Vec3 *>(VT_POS);
|
||||
|
@ -1593,6 +1633,12 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||
flatbuffers::Vector<uint8_t> *mutable_vector_of_enums() {
|
||||
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_VECTOR_OF_ENUMS);
|
||||
}
|
||||
MyGame::Example::Race signed_enum() const {
|
||||
return static_cast<MyGame::Example::Race>(GetField<int8_t>(VT_SIGNED_ENUM, -1));
|
||||
}
|
||||
bool mutate_signed_enum(MyGame::Example::Race _signed_enum) {
|
||||
return SetField<int8_t>(VT_SIGNED_ENUM, static_cast<int8_t>(_signed_enum), -1);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<MyGame::Example::Vec3>(verifier, VT_POS) &&
|
||||
|
@ -1672,6 +1718,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||
VerifyAnyAmbiguousAliases(verifier, any_ambiguous(), any_ambiguous_type()) &&
|
||||
VerifyOffset(verifier, VT_VECTOR_OF_ENUMS) &&
|
||||
verifier.VerifyVector(vector_of_enums()) &&
|
||||
VerifyField<int8_t>(verifier, VT_SIGNED_ENUM) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
|
@ -1847,6 +1894,9 @@ struct MonsterBuilder {
|
|||
void add_vector_of_enums(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> vector_of_enums) {
|
||||
fbb_.AddOffset(Monster::VT_VECTOR_OF_ENUMS, vector_of_enums);
|
||||
}
|
||||
void add_signed_enum(MyGame::Example::Race signed_enum) {
|
||||
fbb_.AddElement<int8_t>(Monster::VT_SIGNED_ENUM, static_cast<int8_t>(signed_enum), -1);
|
||||
}
|
||||
explicit MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
|
@ -1908,7 +1958,8 @@ inline flatbuffers::Offset<Monster> CreateMonster(
|
|||
flatbuffers::Offset<void> any_unique = 0,
|
||||
MyGame::Example::AnyAmbiguousAliases any_ambiguous_type = MyGame::Example::AnyAmbiguousAliases_NONE,
|
||||
flatbuffers::Offset<void> any_ambiguous = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> vector_of_enums = 0) {
|
||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> vector_of_enums = 0,
|
||||
MyGame::Example::Race signed_enum = MyGame::Example::Race_None) {
|
||||
MonsterBuilder builder_(_fbb);
|
||||
builder_.add_non_owning_reference(non_owning_reference);
|
||||
builder_.add_co_owning_reference(co_owning_reference);
|
||||
|
@ -1952,6 +2003,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(
|
|||
builder_.add_pos(pos);
|
||||
builder_.add_hp(hp);
|
||||
builder_.add_mana(mana);
|
||||
builder_.add_signed_enum(signed_enum);
|
||||
builder_.add_any_ambiguous_type(any_ambiguous_type);
|
||||
builder_.add_any_unique_type(any_unique_type);
|
||||
builder_.add_testbool(testbool);
|
||||
|
@ -2008,7 +2060,8 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
|||
flatbuffers::Offset<void> any_unique = 0,
|
||||
MyGame::Example::AnyAmbiguousAliases any_ambiguous_type = MyGame::Example::AnyAmbiguousAliases_NONE,
|
||||
flatbuffers::Offset<void> any_ambiguous = 0,
|
||||
const std::vector<uint8_t> *vector_of_enums = nullptr) {
|
||||
const std::vector<uint8_t> *vector_of_enums = nullptr,
|
||||
MyGame::Example::Race signed_enum = MyGame::Example::Race_None) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
auto inventory__ = inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 0;
|
||||
auto test4__ = test4 ? _fbb.CreateVectorOfStructs<MyGame::Example::Test>(*test4) : 0;
|
||||
|
@ -2076,7 +2129,8 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
|||
any_unique,
|
||||
any_ambiguous_type,
|
||||
any_ambiguous,
|
||||
vector_of_enums__);
|
||||
vector_of_enums__,
|
||||
signed_enum);
|
||||
}
|
||||
|
||||
flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
@ -2560,6 +2614,7 @@ if (_resolver) (*_resolver)(reinterpret_cast<void **>(&_o->vector_of_non_owning_
|
|||
{ auto _e = any_ambiguous_type(); _o->any_ambiguous.type = _e; }
|
||||
{ auto _e = any_ambiguous(); if (_e) _o->any_ambiguous.value = AnyAmbiguousAliasesUnion::UnPack(_e, any_ambiguous_type(), _resolver); }
|
||||
{ auto _e = vector_of_enums(); if (_e) { _o->vector_of_enums.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->vector_of_enums[_i] = static_cast<MyGame::Example::Color>(_e->Get(_i)); } } }
|
||||
{ auto _e = signed_enum(); _o->signed_enum = _e; }
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
|
@ -2617,6 +2672,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
|||
auto _any_ambiguous_type = _o->any_ambiguous.type;
|
||||
auto _any_ambiguous = _o->any_ambiguous.Pack(_fbb);
|
||||
auto _vector_of_enums = _o->vector_of_enums.size() ? _fbb.CreateVectorScalarCast<uint8_t>(flatbuffers::data(_o->vector_of_enums), _o->vector_of_enums.size()) : 0;
|
||||
auto _signed_enum = _o->signed_enum;
|
||||
return MyGame::Example::CreateMonster(
|
||||
_fbb,
|
||||
_pos,
|
||||
|
@ -2665,7 +2721,8 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
|||
_any_unique,
|
||||
_any_ambiguous_type,
|
||||
_any_ambiguous,
|
||||
_vector_of_enums);
|
||||
_vector_of_enums,
|
||||
_signed_enum);
|
||||
}
|
||||
|
||||
inline TypeAliasesT *TypeAliases::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
|
@ -3081,6 +3138,29 @@ inline const flatbuffers::TypeTable *ColorTypeTable() {
|
|||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *RaceTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Example::RaceTypeTable
|
||||
};
|
||||
static const int64_t values[] = { -1, 0, 1, 2 };
|
||||
static const char * const names[] = {
|
||||
"None",
|
||||
"Human",
|
||||
"Dwarf",
|
||||
"Elf"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_ENUM, 4, type_codes, type_refs, values, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *AnyTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||
|
@ -3328,7 +3408,8 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
|||
{ flatbuffers::ET_SEQUENCE, 0, 9 },
|
||||
{ flatbuffers::ET_UTYPE, 0, 10 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 10 },
|
||||
{ flatbuffers::ET_UCHAR, 1, 1 }
|
||||
{ flatbuffers::ET_UCHAR, 1, 1 },
|
||||
{ flatbuffers::ET_CHAR, 0, 11 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Example::Vec3TypeTable,
|
||||
|
@ -3341,7 +3422,8 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
|||
MyGame::InParentNamespaceTypeTable,
|
||||
MyGame::Example::ReferrableTypeTable,
|
||||
MyGame::Example::AnyUniqueAliasesTypeTable,
|
||||
MyGame::Example::AnyAmbiguousAliasesTypeTable
|
||||
MyGame::Example::AnyAmbiguousAliasesTypeTable,
|
||||
MyGame::Example::RaceTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"pos",
|
||||
|
@ -3391,10 +3473,11 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
|||
"any_unique",
|
||||
"any_ambiguous_type",
|
||||
"any_ambiguous",
|
||||
"vector_of_enums"
|
||||
"vector_of_enums",
|
||||
"signed_enum"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 48, type_codes, type_refs, nullptr, names
|
||||
flatbuffers::ST_TABLE, 49, type_codes, type_refs, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
|
|
@ -50,18 +50,38 @@ MyGame.Example.Color = {
|
|||
* @enum {string}
|
||||
*/
|
||||
MyGame.Example.ColorName = {
|
||||
1: 'Red',
|
||||
'1': 'Red',
|
||||
|
||||
/**
|
||||
* \brief color Green
|
||||
* Green is bit_flag with value (1u << 1)
|
||||
*/
|
||||
2: 'Green',
|
||||
'2': 'Green',
|
||||
|
||||
/**
|
||||
* \brief color Blue (1u << 3)
|
||||
*/
|
||||
8: 'Blue'
|
||||
'8': 'Blue'
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
MyGame.Example.Race = {
|
||||
None: -1,
|
||||
Human: 0,
|
||||
Dwarf: 1,
|
||||
Elf: 2
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
MyGame.Example.RaceName = {
|
||||
'-1': 'None',
|
||||
'0': 'Human',
|
||||
'1': 'Dwarf',
|
||||
'2': 'Elf'
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -78,10 +98,10 @@ MyGame.Example.Any = {
|
|||
* @enum {string}
|
||||
*/
|
||||
MyGame.Example.AnyName = {
|
||||
0: 'NONE',
|
||||
1: 'Monster',
|
||||
2: 'TestSimpleTableWithEnum',
|
||||
3: 'MyGame_Example2_Monster'
|
||||
'0': 'NONE',
|
||||
'1': 'Monster',
|
||||
'2': 'TestSimpleTableWithEnum',
|
||||
'3': 'MyGame_Example2_Monster'
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -98,10 +118,10 @@ MyGame.Example.AnyUniqueAliases = {
|
|||
* @enum {string}
|
||||
*/
|
||||
MyGame.Example.AnyUniqueAliasesName = {
|
||||
0: 'NONE',
|
||||
1: 'M',
|
||||
2: 'TS',
|
||||
3: 'M2'
|
||||
'0': 'NONE',
|
||||
'1': 'M',
|
||||
'2': 'TS',
|
||||
'3': 'M2'
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -118,10 +138,10 @@ MyGame.Example.AnyAmbiguousAliases = {
|
|||
* @enum {string}
|
||||
*/
|
||||
MyGame.Example.AnyAmbiguousAliasesName = {
|
||||
0: 'NONE',
|
||||
1: 'M1',
|
||||
2: 'M2',
|
||||
3: 'M3'
|
||||
'0': 'NONE',
|
||||
'1': 'M1',
|
||||
'2': 'M2',
|
||||
'3': 'M3'
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1933,11 +1953,34 @@ MyGame.Example.Monster.prototype.vectorOfEnumsArray = function() {
|
|||
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {MyGame.Example.Race}
|
||||
*/
|
||||
MyGame.Example.Monster.prototype.signedEnum = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 100);
|
||||
return offset ? /** @type {MyGame.Example.Race} */ (this.bb.readInt8(this.bb_pos + offset)) : MyGame.Example.Race.None;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MyGame.Example.Race} value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
MyGame.Example.Monster.prototype.mutate_signed_enum = function(value) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 100);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
*/
|
||||
MyGame.Example.Monster.startMonster = function(builder) {
|
||||
builder.startObject(48);
|
||||
builder.startObject(49);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2655,6 +2698,14 @@ MyGame.Example.Monster.startVectorOfEnumsVector = function(builder, numElems) {
|
|||
builder.startVector(1, numElems, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {MyGame.Example.Race} signedEnum
|
||||
*/
|
||||
MyGame.Example.Monster.addSignedEnum = function(builder, signedEnum) {
|
||||
builder.addFieldInt8(48, signedEnum, MyGame.Example.Race.None);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @returns {flatbuffers.Offset}
|
||||
|
@ -2730,9 +2781,10 @@ MyGame.Example.Monster.finishSizePrefixedMonsterBuffer = function(builder, offse
|
|||
* @param {MyGame.Example.AnyAmbiguousAliases} anyAmbiguousType
|
||||
* @param {flatbuffers.Offset} anyAmbiguousOffset
|
||||
* @param {flatbuffers.Offset} vectorOfEnumsOffset
|
||||
* @param {MyGame.Example.Race} signedEnum
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Example.Monster.createMonster = function(builder, posOffset, mana, hp, nameOffset, inventoryOffset, color, testType, testOffset, test4Offset, testarrayofstringOffset, testarrayoftablesOffset, enemyOffset, testnestedflatbufferOffset, testemptyOffset, testbool, testhashs32Fnv1, testhashu32Fnv1, testhashs64Fnv1, testhashu64Fnv1, testhashs32Fnv1a, testhashu32Fnv1a, testhashs64Fnv1a, testhashu64Fnv1a, testarrayofboolsOffset, testf, testf2, testf3, testarrayofstring2Offset, testarrayofsortedstructOffset, flexOffset, test5Offset, vectorOfLongsOffset, vectorOfDoublesOffset, parentNamespaceTestOffset, vectorOfReferrablesOffset, singleWeakReference, vectorOfWeakReferencesOffset, vectorOfStrongReferrablesOffset, coOwningReference, vectorOfCoOwningReferencesOffset, nonOwningReference, vectorOfNonOwningReferencesOffset, anyUniqueType, anyUniqueOffset, anyAmbiguousType, anyAmbiguousOffset, vectorOfEnumsOffset) {
|
||||
MyGame.Example.Monster.createMonster = function(builder, posOffset, mana, hp, nameOffset, inventoryOffset, color, testType, testOffset, test4Offset, testarrayofstringOffset, testarrayoftablesOffset, enemyOffset, testnestedflatbufferOffset, testemptyOffset, testbool, testhashs32Fnv1, testhashu32Fnv1, testhashs64Fnv1, testhashu64Fnv1, testhashs32Fnv1a, testhashu32Fnv1a, testhashs64Fnv1a, testhashu64Fnv1a, testarrayofboolsOffset, testf, testf2, testf3, testarrayofstring2Offset, testarrayofsortedstructOffset, flexOffset, test5Offset, vectorOfLongsOffset, vectorOfDoublesOffset, parentNamespaceTestOffset, vectorOfReferrablesOffset, singleWeakReference, vectorOfWeakReferencesOffset, vectorOfStrongReferrablesOffset, coOwningReference, vectorOfCoOwningReferencesOffset, nonOwningReference, vectorOfNonOwningReferencesOffset, anyUniqueType, anyUniqueOffset, anyAmbiguousType, anyAmbiguousOffset, vectorOfEnumsOffset, signedEnum) {
|
||||
MyGame.Example.Monster.startMonster(builder);
|
||||
MyGame.Example.Monster.addPos(builder, posOffset);
|
||||
MyGame.Example.Monster.addMana(builder, mana);
|
||||
|
@ -2781,6 +2833,7 @@ MyGame.Example.Monster.createMonster = function(builder, posOffset, mana, hp, na
|
|||
MyGame.Example.Monster.addAnyAmbiguousType(builder, anyAmbiguousType);
|
||||
MyGame.Example.Monster.addAnyAmbiguous(builder, anyAmbiguousOffset);
|
||||
MyGame.Example.Monster.addVectorOfEnums(builder, vectorOfEnumsOffset);
|
||||
MyGame.Example.Monster.addSignedEnum(builder, signedEnum);
|
||||
return MyGame.Example.Monster.endMonster(builder);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,12 @@ enum Color:
|
|||
/// \brief color Blue (1u << 3)
|
||||
Color_Blue = 8
|
||||
|
||||
enum Race:
|
||||
Race_None = -1
|
||||
Race_Human = 0
|
||||
Race_Dwarf = 1
|
||||
Race_Elf = 2
|
||||
|
||||
enum Any:
|
||||
Any_NONE = 0
|
||||
Any_Monster = 1
|
||||
|
@ -352,13 +358,15 @@ class Monster : flatbuffers_handle
|
|||
return buf_.read_int8_le(buf_.flatbuffers_field_vector(pos_, 98) + i * 1)
|
||||
def vector_of_enums_length():
|
||||
return buf_.flatbuffers_field_vector_len(pos_, 98)
|
||||
def signed_enum():
|
||||
return Race(buf_.flatbuffers_field_int8(pos_, 100, -1))
|
||||
|
||||
def GetRootAsMonster(buf:string): return Monster { buf, buf.flatbuffers_indirect(0) }
|
||||
|
||||
struct MonsterBuilder:
|
||||
b_:flatbuffers_builder
|
||||
def start():
|
||||
b_.StartObject(48)
|
||||
b_.StartObject(49)
|
||||
return this
|
||||
def add_pos(pos:flatbuffers_offset):
|
||||
b_.PrependStructSlot(0, pos)
|
||||
|
@ -501,6 +509,9 @@ struct MonsterBuilder:
|
|||
def add_vector_of_enums(vector_of_enums:flatbuffers_offset):
|
||||
b_.PrependUOffsetTRelativeSlot(47, vector_of_enums)
|
||||
return this
|
||||
def add_signed_enum(signed_enum:Race):
|
||||
b_.PrependInt8Slot(48, signed_enum, -1)
|
||||
return this
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
|
|
|
@ -235,6 +235,72 @@ pub fn enum_name_color(e: Color) -> &'static str {
|
|||
ENUM_NAMES_COLOR[index as usize]
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(i8)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
pub enum Race {
|
||||
None = -1,
|
||||
Human = 0,
|
||||
Dwarf = 1,
|
||||
Elf = 2,
|
||||
|
||||
}
|
||||
|
||||
const ENUM_MIN_RACE: i8 = -1;
|
||||
const ENUM_MAX_RACE: i8 = 2;
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Race {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::read_scalar_at::<Self>(buf, loc)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Race {
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let n = i8::to_le(self as i8);
|
||||
let p = &n as *const i8 as *const Race;
|
||||
unsafe { *p }
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let n = i8::from_le(self as i8);
|
||||
let p = &n as *const i8 as *const Race;
|
||||
unsafe { *p }
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Race {
|
||||
type Output = Race;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
flatbuffers::emplace_scalar::<Race>(dst, *self);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
const ENUM_VALUES_RACE:[Race; 4] = [
|
||||
Race::None,
|
||||
Race::Human,
|
||||
Race::Dwarf,
|
||||
Race::Elf
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
const ENUM_NAMES_RACE:[&'static str; 4] = [
|
||||
"None",
|
||||
"Human",
|
||||
"Dwarf",
|
||||
"Elf"
|
||||
];
|
||||
|
||||
pub fn enum_name_race(e: Race) -> &'static str {
|
||||
let index = e as i8 - Race::None as i8;
|
||||
ENUM_NAMES_RACE[index as usize]
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
|
@ -991,6 +1057,7 @@ impl<'a> Monster<'a> {
|
|||
if let Some(x) = args.pos { builder.add_pos(x); }
|
||||
builder.add_hp(args.hp);
|
||||
builder.add_mana(args.mana);
|
||||
builder.add_signed_enum(args.signed_enum);
|
||||
builder.add_any_ambiguous_type(args.any_ambiguous_type);
|
||||
builder.add_any_unique_type(args.any_unique_type);
|
||||
builder.add_testbool(args.testbool);
|
||||
|
@ -1046,6 +1113,7 @@ impl<'a> Monster<'a> {
|
|||
pub const VT_ANY_AMBIGUOUS_TYPE: flatbuffers::VOffsetT = 94;
|
||||
pub const VT_ANY_AMBIGUOUS: flatbuffers::VOffsetT = 96;
|
||||
pub const VT_VECTOR_OF_ENUMS: flatbuffers::VOffsetT = 98;
|
||||
pub const VT_SIGNED_ENUM: flatbuffers::VOffsetT = 100;
|
||||
|
||||
#[inline]
|
||||
pub fn pos(&self) -> Option<&'a Vec3> {
|
||||
|
@ -1257,6 +1325,10 @@ impl<'a> Monster<'a> {
|
|||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Color>>>(Monster::VT_VECTOR_OF_ENUMS, None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn signed_enum(&self) -> Race {
|
||||
self._tab.get::<Race>(Monster::VT_SIGNED_ENUM, Some(Race::None)).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn test_as_monster(&self) -> Option<Monster<'a>> {
|
||||
if self.test_type() == Any::Monster {
|
||||
|
@ -1396,6 +1468,7 @@ pub struct MonsterArgs<'a> {
|
|||
pub any_ambiguous_type: AnyAmbiguousAliases,
|
||||
pub any_ambiguous: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
|
||||
pub vector_of_enums: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a , Color>>>,
|
||||
pub signed_enum: Race,
|
||||
}
|
||||
impl<'a> Default for MonsterArgs<'a> {
|
||||
#[inline]
|
||||
|
@ -1448,6 +1521,7 @@ impl<'a> Default for MonsterArgs<'a> {
|
|||
any_ambiguous_type: AnyAmbiguousAliases::NONE,
|
||||
any_ambiguous: None,
|
||||
vector_of_enums: None,
|
||||
signed_enum: Race::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1645,6 +1719,10 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
|
|||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_VECTOR_OF_ENUMS, vector_of_enums);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_signed_enum(&mut self, signed_enum: Race) {
|
||||
self.fbb_.push_slot::<Race>(Monster::VT_SIGNED_ENUM, signed_enum, Race::None);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MonsterBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
MonsterBuilder {
|
||||
|
|
|
@ -21,6 +21,17 @@ export enum Color{
|
|||
Blue= 8
|
||||
}};
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
export namespace MyGame.Example{
|
||||
export enum Race{
|
||||
None= -1,
|
||||
Human= 0,
|
||||
Dwarf= 1,
|
||||
Elf= 2
|
||||
}};
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
|
@ -1794,11 +1805,34 @@ vectorOfEnumsArray():Uint8Array|null {
|
|||
return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns MyGame.Example.Race
|
||||
*/
|
||||
signedEnum():MyGame.Example.Race {
|
||||
var offset = this.bb!.__offset(this.bb_pos, 100);
|
||||
return offset ? /** */ (this.bb!.readInt8(this.bb_pos + offset)) : MyGame.Example.Race.None;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param MyGame.Example.Race value
|
||||
* @returns boolean
|
||||
*/
|
||||
mutate_signed_enum(value:MyGame.Example.Race):boolean {
|
||||
var offset = this.bb!.__offset(this.bb_pos, 100);
|
||||
|
||||
if (offset === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.bb!.writeInt8(this.bb_pos + offset, value);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
*/
|
||||
static startMonster(builder:flatbuffers.Builder) {
|
||||
builder.startObject(48);
|
||||
builder.startObject(49);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2516,6 +2550,14 @@ static startVectorOfEnumsVector(builder:flatbuffers.Builder, numElems:number) {
|
|||
builder.startVector(1, numElems, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @param MyGame.Example.Race signedEnum
|
||||
*/
|
||||
static addSignedEnum(builder:flatbuffers.Builder, signedEnum:MyGame.Example.Race) {
|
||||
builder.addFieldInt8(48, signedEnum, MyGame.Example.Race.None);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param flatbuffers.Builder builder
|
||||
* @returns flatbuffers.Offset
|
||||
|
@ -2542,7 +2584,7 @@ static finishSizePrefixedMonsterBuffer(builder:flatbuffers.Builder, offset:flatb
|
|||
builder.finish(offset, 'MONS', true);
|
||||
};
|
||||
|
||||
static createMonster(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset, mana:number, hp:number, nameOffset:flatbuffers.Offset, inventoryOffset:flatbuffers.Offset, color:MyGame.Example.Color, testType:MyGame.Example.Any, testOffset:flatbuffers.Offset, test4Offset:flatbuffers.Offset, testarrayofstringOffset:flatbuffers.Offset, testarrayoftablesOffset:flatbuffers.Offset, enemyOffset:flatbuffers.Offset, testnestedflatbufferOffset:flatbuffers.Offset, testemptyOffset:flatbuffers.Offset, testbool:boolean, testhashs32Fnv1:number, testhashu32Fnv1:number, testhashs64Fnv1:flatbuffers.Long, testhashu64Fnv1:flatbuffers.Long, testhashs32Fnv1a:number, testhashu32Fnv1a:number, testhashs64Fnv1a:flatbuffers.Long, testhashu64Fnv1a:flatbuffers.Long, testarrayofboolsOffset:flatbuffers.Offset, testf:number, testf2:number, testf3:number, testarrayofstring2Offset:flatbuffers.Offset, testarrayofsortedstructOffset:flatbuffers.Offset, flexOffset:flatbuffers.Offset, test5Offset:flatbuffers.Offset, vectorOfLongsOffset:flatbuffers.Offset, vectorOfDoublesOffset:flatbuffers.Offset, parentNamespaceTestOffset:flatbuffers.Offset, vectorOfReferrablesOffset:flatbuffers.Offset, singleWeakReference:flatbuffers.Long, vectorOfWeakReferencesOffset:flatbuffers.Offset, vectorOfStrongReferrablesOffset:flatbuffers.Offset, coOwningReference:flatbuffers.Long, vectorOfCoOwningReferencesOffset:flatbuffers.Offset, nonOwningReference:flatbuffers.Long, vectorOfNonOwningReferencesOffset:flatbuffers.Offset, anyUniqueType:MyGame.Example.AnyUniqueAliases, anyUniqueOffset:flatbuffers.Offset, anyAmbiguousType:MyGame.Example.AnyAmbiguousAliases, anyAmbiguousOffset:flatbuffers.Offset, vectorOfEnumsOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
static createMonster(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset, mana:number, hp:number, nameOffset:flatbuffers.Offset, inventoryOffset:flatbuffers.Offset, color:MyGame.Example.Color, testType:MyGame.Example.Any, testOffset:flatbuffers.Offset, test4Offset:flatbuffers.Offset, testarrayofstringOffset:flatbuffers.Offset, testarrayoftablesOffset:flatbuffers.Offset, enemyOffset:flatbuffers.Offset, testnestedflatbufferOffset:flatbuffers.Offset, testemptyOffset:flatbuffers.Offset, testbool:boolean, testhashs32Fnv1:number, testhashu32Fnv1:number, testhashs64Fnv1:flatbuffers.Long, testhashu64Fnv1:flatbuffers.Long, testhashs32Fnv1a:number, testhashu32Fnv1a:number, testhashs64Fnv1a:flatbuffers.Long, testhashu64Fnv1a:flatbuffers.Long, testarrayofboolsOffset:flatbuffers.Offset, testf:number, testf2:number, testf3:number, testarrayofstring2Offset:flatbuffers.Offset, testarrayofsortedstructOffset:flatbuffers.Offset, flexOffset:flatbuffers.Offset, test5Offset:flatbuffers.Offset, vectorOfLongsOffset:flatbuffers.Offset, vectorOfDoublesOffset:flatbuffers.Offset, parentNamespaceTestOffset:flatbuffers.Offset, vectorOfReferrablesOffset:flatbuffers.Offset, singleWeakReference:flatbuffers.Long, vectorOfWeakReferencesOffset:flatbuffers.Offset, vectorOfStrongReferrablesOffset:flatbuffers.Offset, coOwningReference:flatbuffers.Long, vectorOfCoOwningReferencesOffset:flatbuffers.Offset, nonOwningReference:flatbuffers.Long, vectorOfNonOwningReferencesOffset:flatbuffers.Offset, anyUniqueType:MyGame.Example.AnyUniqueAliases, anyUniqueOffset:flatbuffers.Offset, anyAmbiguousType:MyGame.Example.AnyAmbiguousAliases, anyAmbiguousOffset:flatbuffers.Offset, vectorOfEnumsOffset:flatbuffers.Offset, signedEnum:MyGame.Example.Race):flatbuffers.Offset {
|
||||
Monster.startMonster(builder);
|
||||
Monster.addPos(builder, posOffset);
|
||||
Monster.addMana(builder, mana);
|
||||
|
@ -2591,6 +2633,7 @@ static createMonster(builder:flatbuffers.Builder, posOffset:flatbuffers.Offset,
|
|||
Monster.addAnyAmbiguousType(builder, anyAmbiguousType);
|
||||
Monster.addAnyAmbiguous(builder, anyAmbiguousOffset);
|
||||
Monster.addVectorOfEnums(builder, vectorOfEnumsOffset);
|
||||
Monster.addSignedEnum(builder, signedEnum);
|
||||
return Monster.endMonster(builder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,47 @@ class _ColorReader extends fb.Reader<Color> {
|
|||
new Color.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class Race {
|
||||
final int value;
|
||||
const Race._(this.value);
|
||||
|
||||
factory Race.fromValue(int value) {
|
||||
if (value == null) value = 0;
|
||||
if (!values.containsKey(value)) {
|
||||
throw new StateError('Invalid value $value for bit flag enum Race');
|
||||
}
|
||||
return values[value];
|
||||
}
|
||||
|
||||
static const int minValue = -1;
|
||||
static const int maxValue = 2;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const Race None = const Race._(-1);
|
||||
static const Race Human = const Race._(0);
|
||||
static const Race Dwarf = const Race._(1);
|
||||
static const Race Elf = const Race._(2);
|
||||
static get values => {-1: None,0: Human,1: Dwarf,2: Elf,};
|
||||
|
||||
static const fb.Reader<Race> reader = const _RaceReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Race{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _RaceReader extends fb.Reader<Race> {
|
||||
const _RaceReader();
|
||||
|
||||
@override
|
||||
int get size => 1;
|
||||
|
||||
@override
|
||||
Race read(fb.BufferContext bc, int offset) =>
|
||||
new Race.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class AnyTypeId {
|
||||
final int value;
|
||||
const AnyTypeId._(this.value);
|
||||
|
@ -759,10 +800,11 @@ class Monster {
|
|||
}
|
||||
}
|
||||
List<Color> get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGet(_bc, _bcOffset, 98, null);
|
||||
Race get signedEnum => new Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums}';
|
||||
return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum}';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -973,6 +1015,10 @@ class MonsterBuilder {
|
|||
fbBuilder.addOffset(47, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
int addSignedEnum(Race signedEnum) {
|
||||
fbBuilder.addInt8(48, signedEnum?.value);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int finish() {
|
||||
return fbBuilder.endTable();
|
||||
|
@ -1027,6 +1073,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
final AnyAmbiguousAliasesTypeId _anyAmbiguousType;
|
||||
final dynamic _anyAmbiguous;
|
||||
final List<Color> _vectorOfEnums;
|
||||
final Race _signedEnum;
|
||||
|
||||
MonsterObjectBuilder({
|
||||
Vec3ObjectBuilder pos,
|
||||
|
@ -1076,6 +1123,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
AnyAmbiguousAliasesTypeId anyAmbiguousType,
|
||||
dynamic anyAmbiguous,
|
||||
List<Color> vectorOfEnums,
|
||||
Race signedEnum,
|
||||
})
|
||||
: _pos = pos,
|
||||
_mana = mana,
|
||||
|
@ -1123,7 +1171,8 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
_anyUnique = anyUnique,
|
||||
_anyAmbiguousType = anyAmbiguousType,
|
||||
_anyAmbiguous = anyAmbiguous,
|
||||
_vectorOfEnums = vectorOfEnums;
|
||||
_vectorOfEnums = vectorOfEnums,
|
||||
_signedEnum = signedEnum;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
|
@ -1292,6 +1341,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||
if (vectorOfEnumsOffset != null) {
|
||||
fbBuilder.addOffset(47, vectorOfEnumsOffset);
|
||||
}
|
||||
fbBuilder.addInt8(48, _signedEnum?.value);
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ NamespaceA.NamespaceB.EnumInNestedNS = {
|
|||
* @enum {string}
|
||||
*/
|
||||
NamespaceA.NamespaceB.EnumInNestedNSName = {
|
||||
0: 'A',
|
||||
1: 'B',
|
||||
2: 'C'
|
||||
'0': 'A',
|
||||
'1': 'B',
|
||||
'2': 'C'
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,13 +17,13 @@ var Character = {
|
|||
* @enum {string}
|
||||
*/
|
||||
var CharacterName = {
|
||||
0: 'NONE',
|
||||
1: 'MuLan',
|
||||
2: 'Rapunzel',
|
||||
3: 'Belle',
|
||||
4: 'BookFan',
|
||||
5: 'Other',
|
||||
6: 'Unused'
|
||||
'0': 'NONE',
|
||||
'1': 'MuLan',
|
||||
'2': 'Rapunzel',
|
||||
'3': 'Belle',
|
||||
'4': 'BookFan',
|
||||
'5': 'Other',
|
||||
'6': 'Unused'
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue