diff --git a/include/flatbuffers/reflection_generated.h b/include/flatbuffers/reflection_generated.h index 869a9f3f2..55ab79cc3 100644 --- a/include/flatbuffers/reflection_generated.h +++ b/include/flatbuffers/reflection_generated.h @@ -70,7 +70,7 @@ inline const BaseType (&EnumValuesBaseType())[17] { } inline const char * const *EnumNamesBaseType() { - static const char * const names[] = { + static const char * const names[18] = { "None", "UType", "Bool", diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 7026116d9..70c41baee 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -48,7 +48,7 @@ inline const Color (&EnumValuesColor())[3] { } inline const char * const *EnumNamesColor() { - static const char * const names[] = { + static const char * const names[4] = { "Red", "Green", "Blue", @@ -79,7 +79,7 @@ inline const Equipment (&EnumValuesEquipment())[2] { } inline const char * const *EnumNamesEquipment() { - static const char * const names[] = { + static const char * const names[3] = { "NONE", "Weapon", nullptr diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index d42ebe3ef..cfd25267a 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1019,7 +1019,8 @@ class CppGenerator : public BaseGenerator { static const uint64_t kMaxSparseness = 5; if (range / static_cast(enum_def.size()) < kMaxSparseness) { code_ += "inline const char * const *EnumNames{{ENUM_NAME}}() {"; - code_ += " static const char * const names[] = {"; + code_ += " static const char * const names[" + + NumToString(range + 1 + 1) + "] = {"; auto val = enum_def.Vals().front(); for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); diff --git a/tests/JavaTest.java b/tests/JavaTest.java index 1a9b70182..cc0795061 100644 --- a/tests/JavaTest.java +++ b/tests/JavaTest.java @@ -101,7 +101,8 @@ class JavaTest { TestEq(pos.y(), 2.0f); TestEq(pos.z(), 3.0f); TestEq(pos.test1(), 3.0); - TestEq(pos.test2(), Color.Green); + // issue: int != byte + TestEq(pos.test2(), (int) Color.Green); Test t = pos.test3(); TestEq(t.a(), (short)5); TestEq(t.b(), (byte)6); diff --git a/tests/MyGame/Example/Color.cs b/tests/MyGame/Example/Color.cs index f40d60ba7..654b16315 100644 --- a/tests/MyGame/Example/Color.cs +++ b/tests/MyGame/Example/Color.cs @@ -5,7 +5,7 @@ namespace MyGame.Example { -public enum Color : sbyte +public enum Color : byte { Red = 1, Green = 2, diff --git a/tests/MyGame/Example/Color.go b/tests/MyGame/Example/Color.go index cc0833488..67718b281 100644 --- a/tests/MyGame/Example/Color.go +++ b/tests/MyGame/Example/Color.go @@ -2,7 +2,7 @@ package Example -type Color = int8 +type Color = byte const ( ColorRed Color = 1 ColorGreen Color = 2 diff --git a/tests/MyGame/Example/Monster.cs b/tests/MyGame/Example/Monster.cs index 54900866a..596cdce0a 100644 --- a/tests/MyGame/Example/Monster.cs +++ b/tests/MyGame/Example/Monster.cs @@ -40,8 +40,8 @@ public struct Monster : IFlatbufferObject #endif public byte[] GetInventoryArray() { return __p.__vector_as_array(14); } public bool MutateInventory(int j, byte inventory) { int o = __p.__offset(14); if (o != 0) { __p.bb.Put(__p.__vector(o) + j * 1, inventory); return true; } else { return false; } } - public Color Color { get { int o = __p.__offset(16); return o != 0 ? (Color)__p.bb.GetSbyte(o + __p.bb_pos) : Color.Blue; } } - public bool MutateColor(Color color) { int o = __p.__offset(16); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)color); return true; } else { return false; } } + public Color Color { get { int o = __p.__offset(16); return o != 0 ? (Color)__p.bb.Get(o + __p.bb_pos) : Color.Blue; } } + public bool MutateColor(Color color) { int o = __p.__offset(16); if (o != 0) { __p.bb.Put(o + __p.bb_pos, (byte)color); return true; } else { return false; } } public Any TestType { get { int o = __p.__offset(18); return o != 0 ? (Any)__p.bb.Get(o + __p.bb_pos) : Any.NONE; } } public bool MutateTestType(Any test_type) { int o = __p.__offset(18); if (o != 0) { __p.bb.Put(o + __p.bb_pos, (byte)test_type); return true; } else { return false; } } public TTable? Test() where TTable : struct, IFlatbufferObject { int o = __p.__offset(20); return o != 0 ? (TTable?)__p.__union(o) : null; } @@ -178,7 +178,7 @@ public struct Monster : IFlatbufferObject public AnyAmbiguousAliases AnyAmbiguousType { get { int o = __p.__offset(94); return o != 0 ? (AnyAmbiguousAliases)__p.bb.Get(o + __p.bb_pos) : AnyAmbiguousAliases.NONE; } } public bool MutateAnyAmbiguousType(AnyAmbiguousAliases any_ambiguous_type) { int o = __p.__offset(94); if (o != 0) { __p.bb.Put(o + __p.bb_pos, (byte)any_ambiguous_type); return true; } else { return false; } } public TTable? AnyAmbiguous() where TTable : struct, IFlatbufferObject { int o = __p.__offset(96); return o != 0 ? (TTable?)__p.__union(o) : null; } - public Color VectorOfEnums(int j) { int o = __p.__offset(98); return o != 0 ? (Color)__p.bb.GetSbyte(__p.__vector(o) + j * 1) : (Color)0; } + public Color VectorOfEnums(int j) { int o = __p.__offset(98); return o != 0 ? (Color)__p.bb.Get(__p.__vector(o) + j * 1) : (Color)0; } public int VectorOfEnumsLength { get { int o = __p.__offset(98); return o != 0 ? __p.__vector_len(o) : 0; } } #if ENABLE_SPAN_T public Span GetVectorOfEnumsBytes() { return __p.__vector_as_span(98); } @@ -186,7 +186,7 @@ public struct Monster : IFlatbufferObject public ArraySegment? GetVectorOfEnumsBytes() { return __p.__vector_as_arraysegment(98); } #endif public Color[] GetVectorOfEnumsArray() { return __p.__vector_as_array(98); } - public bool MutateVectorOfEnums(int j, Color vector_of_enums) { int o = __p.__offset(98); if (o != 0) { __p.bb.PutSbyte(__p.__vector(o) + j * 1, (sbyte)vector_of_enums); return true; } else { return false; } } + public bool MutateVectorOfEnums(int j, 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 static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(48); } public static void AddPos(FlatBufferBuilder builder, Offset posOffset) { builder.AddStruct(0, posOffset.Value, 0); } @@ -197,7 +197,7 @@ public struct Monster : IFlatbufferObject 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 VectorOffset CreateInventoryVectorBlock(FlatBufferBuilder builder, byte[] data) { builder.StartVector(1, data.Length, 1); builder.Add(data); 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 AddColor(FlatBufferBuilder builder, Color color) { builder.AddByte(6, (byte)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); } @@ -281,7 +281,7 @@ public struct Monster : IFlatbufferObject public static void AddAnyAmbiguousType(FlatBufferBuilder builder, AnyAmbiguousAliases anyAmbiguousType) { builder.AddByte(45, (byte)anyAmbiguousType, 0); } public static void AddAnyAmbiguous(FlatBufferBuilder builder, int anyAmbiguousOffset) { builder.AddOffset(46, anyAmbiguousOffset, 0); } public static void AddVectorOfEnums(FlatBufferBuilder builder, VectorOffset vectorOfEnumsOffset) { builder.AddOffset(47, vectorOfEnumsOffset.Value, 0); } - public static VectorOffset CreateVectorOfEnumsVector(FlatBufferBuilder builder, Color[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddSbyte((sbyte)data[i]); return builder.EndVector(); } + public static VectorOffset CreateVectorOfEnumsVector(FlatBufferBuilder builder, 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 VectorOffset CreateVectorOfEnumsVectorBlock(FlatBufferBuilder builder, Color[] data) { builder.StartVector(1, data.Length, 1); builder.Add(data); return builder.EndVector(); } public static void StartVectorOfEnumsVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); } public static Offset EndMonster(FlatBufferBuilder builder) { diff --git a/tests/MyGame/Example/Monster.go b/tests/MyGame/Example/Monster.go index 1eedc5ebb..1f146b0f1 100644 --- a/tests/MyGame/Example/Monster.go +++ b/tests/MyGame/Example/Monster.go @@ -111,13 +111,13 @@ func (rcv *Monster) MutateInventory(j int, n byte) bool { func (rcv *Monster) Color() Color { o := flatbuffers.UOffsetT(rcv._tab.Offset(16)) if o != 0 { - return rcv._tab.GetInt8(o + rcv._tab.Pos) + return rcv._tab.GetByte(o + rcv._tab.Pos) } return 8 } func (rcv *Monster) MutateColor(n Color) bool { - return rcv._tab.MutateInt8Slot(16, n) + return rcv._tab.MutateByteSlot(16, n) } func (rcv *Monster) TestType() byte { @@ -785,7 +785,7 @@ func (rcv *Monster) VectorOfEnums(j int) Color { o := flatbuffers.UOffsetT(rcv._tab.Offset(98)) if o != 0 { a := rcv._tab.Vector(o) - return rcv._tab.GetInt8(a + flatbuffers.UOffsetT(j*1)) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1)) } return 0 } @@ -798,11 +798,19 @@ func (rcv *Monster) VectorOfEnumsLength() int { return 0 } +func (rcv *Monster) VectorOfEnumsBytes() []byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(98)) + if o != 0 { + return rcv._tab.ByteVector(o + rcv._tab.Pos) + } + return nil +} + func (rcv *Monster) MutateVectorOfEnums(j int, n Color) bool { o := flatbuffers.UOffsetT(rcv._tab.Offset(98)) if o != 0 { a := rcv._tab.Vector(o) - return rcv._tab.MutateInt8(a+flatbuffers.UOffsetT(j*1), n) + return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n) } return false } @@ -828,8 +836,8 @@ func MonsterAddInventory(builder *flatbuffers.Builder, inventory flatbuffers.UOf func MonsterStartInventoryVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1) } -func MonsterAddColor(builder *flatbuffers.Builder, color int8) { - builder.PrependInt8Slot(6, color, 8) +func MonsterAddColor(builder *flatbuffers.Builder, color byte) { + builder.PrependByteSlot(6, color, 8) } func MonsterAddTestType(builder *flatbuffers.Builder, testType byte) { builder.PrependByteSlot(7, testType, 0) diff --git a/tests/MyGame/Example/Monster.java b/tests/MyGame/Example/Monster.java index 848f9a7a9..967b4a728 100644 --- a/tests/MyGame/Example/Monster.java +++ b/tests/MyGame/Example/Monster.java @@ -32,8 +32,8 @@ public final class Monster extends Table { public ByteBuffer inventoryAsByteBuffer() { return __vector_as_bytebuffer(14, 1); } public ByteBuffer inventoryInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 14, 1); } public boolean mutateInventory(int j, int inventory) { int o = __offset(14); if (o != 0) { bb.put(__vector(o) + j * 1, (byte)inventory); return true; } else { return false; } } - public byte color() { int o = __offset(16); return o != 0 ? bb.get(o + bb_pos) : 8; } - public boolean mutateColor(byte color) { int o = __offset(16); if (o != 0) { bb.put(o + bb_pos, color); return true; } else { return false; } } + public int color() { int o = __offset(16); return o != 0 ? bb.get(o + bb_pos) & 0xFF : 8; } + public boolean mutateColor(int color) { int o = __offset(16); if (o != 0) { bb.put(o + bb_pos, (byte)color); return true; } else { return false; } } public byte testType() { int o = __offset(18); return o != 0 ? bb.get(o + bb_pos) : 0; } public boolean mutateTestType(byte test_type) { int o = __offset(18); if (o != 0) { bb.put(o + bb_pos, test_type); return true; } else { return false; } } public Table test(Table obj) { int o = __offset(20); return o != 0 ? __union(obj, o) : null; } @@ -153,11 +153,11 @@ public final class Monster extends Table { public byte anyAmbiguousType() { int o = __offset(94); return o != 0 ? bb.get(o + bb_pos) : 0; } public boolean mutateAnyAmbiguousType(byte any_ambiguous_type) { int o = __offset(94); if (o != 0) { bb.put(o + bb_pos, any_ambiguous_type); return true; } else { return false; } } public Table anyAmbiguous(Table obj) { int o = __offset(96); return o != 0 ? __union(obj, o) : null; } - public byte vectorOfEnums(int j) { int o = __offset(98); return o != 0 ? bb.get(__vector(o) + j * 1) : 0; } + public int vectorOfEnums(int j) { int o = __offset(98); return o != 0 ? bb.get(__vector(o) + j * 1) & 0xFF : 0; } public int vectorOfEnumsLength() { int o = __offset(98); return o != 0 ? __vector_len(o) : 0; } 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, byte vector_of_enums) { int o = __offset(98); if (o != 0) { bb.put(__vector(o) + j * 1, vector_of_enums); return true; } else { return false; } } + 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 static void startMonster(FlatBufferBuilder builder) { builder.startObject(48); } public static void addPos(FlatBufferBuilder builder, int posOffset) { builder.addStruct(0, posOffset, 0); } @@ -167,7 +167,7 @@ public final class Monster extends Table { public static void addInventory(FlatBufferBuilder builder, int inventoryOffset) { builder.addOffset(5, inventoryOffset, 0); } public static int 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, byte color) { builder.addByte(6, color, 8); } + public static void addColor(FlatBufferBuilder builder, int color) { builder.addByte(6, (byte)color, (byte)8); } public static void addTestType(FlatBufferBuilder builder, byte testType) { builder.addByte(7, testType, 0); } public static void addTest(FlatBufferBuilder builder, int testOffset) { builder.addOffset(8, testOffset, 0); } public static void addTest4(FlatBufferBuilder builder, int test4Offset) { builder.addOffset(9, test4Offset, 0); } diff --git a/tests/MyGame/Example/Monster.lua b/tests/MyGame/Example/Monster.lua index f12808b47..3fd778c0a 100644 --- a/tests/MyGame/Example/Monster.lua +++ b/tests/MyGame/Example/Monster.lua @@ -69,7 +69,7 @@ end function Monster_mt:Color() local o = self.view:Offset(16) if o ~= 0 then - return self.view:Get(flatbuffers.N.Int8, o + self.view.pos) + return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos) end return 8 end @@ -511,7 +511,7 @@ function Monster_mt:VectorOfEnums(j) local o = self.view:Offset(98) if o ~= 0 then local a = self.view:Vector(o) - return self.view:Get(flatbuffers.N.Int8, a + ((j-1) * 1)) + return self.view:Get(flatbuffers.N.Uint8, a + ((j-1) * 1)) end return 0 end @@ -529,7 +529,7 @@ function Monster.AddHp(builder, hp) builder:PrependInt16Slot(2, hp, 100) end function Monster.AddName(builder, name) builder:PrependUOffsetTRelativeSlot(3, name, 0) end function Monster.AddInventory(builder, inventory) builder:PrependUOffsetTRelativeSlot(5, inventory, 0) end function Monster.StartInventoryVector(builder, numElems) return builder:StartVector(1, numElems, 1) end -function Monster.AddColor(builder, color) builder:PrependInt8Slot(6, color, 8) end +function Monster.AddColor(builder, color) builder:PrependUint8Slot(6, color, 8) end function Monster.AddTestType(builder, testType) builder:PrependUint8Slot(7, testType, 0) end function Monster.AddTest(builder, test) builder:PrependUOffsetTRelativeSlot(8, test, 0) end function Monster.AddTest4(builder, test4) builder:PrependUOffsetTRelativeSlot(9, test4, 0) end diff --git a/tests/MyGame/Example/Monster.php b/tests/MyGame/Example/Monster.php index 311f0174f..c50ad3fdb 100644 --- a/tests/MyGame/Example/Monster.php +++ b/tests/MyGame/Example/Monster.php @@ -107,12 +107,12 @@ class Monster extends Table } /** - * @return sbyte + * @return byte */ public function getColor() { $o = $this->__offset(16); - return $o != 0 ? $this->bb->getSbyte($o + $this->bb_pos) : \MyGame\Example\Color::Blue; + return $o != 0 ? $this->bb->getByte($o + $this->bb_pos) : \MyGame\Example\Color::Blue; } /** @@ -649,12 +649,12 @@ class Monster extends Table /** * @param int offset - * @return sbyte + * @return byte */ public function getVectorOfEnums($j) { $o = $this->__offset(98); - return $o != 0 ? $this->bb->getSbyte($this->__vector($o) + $j * 1) : 0; + return $o != 0 ? $this->bb->getByte($this->__vector($o) + $j * 1) : 0; } /** @@ -666,6 +666,14 @@ class Monster extends Table return $o != 0 ? $this->__vector_len($o) : 0; } + /** + * @return string + */ + public function getVectorOfEnumsBytes() + { + return $this->__vector_as_bytes(98); + } + /** * @param FlatBufferBuilder $builder * @return void @@ -810,12 +818,12 @@ class Monster extends Table /** * @param FlatBufferBuilder $builder - * @param sbyte + * @param byte * @return void */ public static function addColor(FlatBufferBuilder $builder, $color) { - $builder->addSbyteX(6, $color, 8); + $builder->addByteX(6, $color, 8); } /** @@ -1606,7 +1614,7 @@ class Monster extends Table { $builder->startVector(1, count($data), 1); for ($i = count($data) - 1; $i >= 0; $i--) { - $builder->putSbyte($data[$i]); + $builder->putByte($data[$i]); } return $builder->endVector(); } diff --git a/tests/MyGame/Example/Monster.py b/tests/MyGame/Example/Monster.py index bcc8a6341..29ec7f27e 100644 --- a/tests/MyGame/Example/Monster.py +++ b/tests/MyGame/Example/Monster.py @@ -77,7 +77,7 @@ class Monster(object): def Color(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) if o != 0: - return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) return 8 # Monster @@ -599,14 +599,14 @@ class Monster(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(98)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) + return self._tab.Get(flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) return 0 # Monster def VectorOfEnumsAsNumpy(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(98)) if o != 0: - return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int8Flags, o) + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o) return 0 # Monster @@ -623,7 +623,7 @@ def MonsterAddHp(builder, hp): builder.PrependInt16Slot(2, hp, 100) def MonsterAddName(builder, name): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) def MonsterAddInventory(builder, inventory): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(inventory), 0) def MonsterStartInventoryVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def MonsterAddColor(builder, color): builder.PrependInt8Slot(6, color, 8) +def MonsterAddColor(builder, color): builder.PrependUint8Slot(6, color, 8) def MonsterAddTestType(builder, testType): builder.PrependUint8Slot(7, testType, 0) def MonsterAddTest(builder, test): builder.PrependUOffsetTRelativeSlot(8, flatbuffers.number_types.UOffsetTFlags.py_type(test), 0) def MonsterAddTest4(builder, test4): builder.PrependUOffsetTRelativeSlot(9, flatbuffers.number_types.UOffsetTFlags.py_type(test4), 0) diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.cs b/tests/MyGame/Example/TestSimpleTableWithEnum.cs index 9e405ef8c..e58d66993 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.cs +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.cs @@ -17,8 +17,8 @@ internal partial struct TestSimpleTableWithEnum : IFlatbufferObject public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; } public TestSimpleTableWithEnum __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - public Color Color { get { int o = __p.__offset(4); return o != 0 ? (Color)__p.bb.GetSbyte(o + __p.bb_pos) : Color.Green; } } - public bool MutateColor(Color color) { int o = __p.__offset(4); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)color); return true; } else { return false; } } + public Color Color { get { int o = __p.__offset(4); return o != 0 ? (Color)__p.bb.Get(o + __p.bb_pos) : Color.Green; } } + public bool MutateColor(Color color) { int o = __p.__offset(4); if (o != 0) { __p.bb.Put(o + __p.bb_pos, (byte)color); return true; } else { return false; } } public static Offset CreateTestSimpleTableWithEnum(FlatBufferBuilder builder, Color color = Color.Green) { @@ -28,7 +28,7 @@ internal partial struct TestSimpleTableWithEnum : IFlatbufferObject } 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.AddByte(0, (byte)color, 2); } public static Offset EndTestSimpleTableWithEnum(FlatBufferBuilder builder) { int o = builder.EndObject(); return new Offset(o); diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.go b/tests/MyGame/Example/TestSimpleTableWithEnum.go index cf9da5e9d..638ed4db7 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.go +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.go @@ -29,20 +29,20 @@ func (rcv *TestSimpleTableWithEnum) Table() flatbuffers.Table { func (rcv *TestSimpleTableWithEnum) Color() Color { o := flatbuffers.UOffsetT(rcv._tab.Offset(4)) if o != 0 { - return rcv._tab.GetInt8(o + rcv._tab.Pos) + return rcv._tab.GetByte(o + rcv._tab.Pos) } return 2 } func (rcv *TestSimpleTableWithEnum) MutateColor(n Color) bool { - return rcv._tab.MutateInt8Slot(4, n) + return rcv._tab.MutateByteSlot(4, n) } func TestSimpleTableWithEnumStart(builder *flatbuffers.Builder) { builder.StartObject(1) } -func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color int8) { - builder.PrependInt8Slot(0, color, 2) +func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color byte) { + builder.PrependByteSlot(0, color, 2) } func TestSimpleTableWithEnumEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.java b/tests/MyGame/Example/TestSimpleTableWithEnum.java index 974e44ea0..9a9d600dc 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.java +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.java @@ -14,18 +14,18 @@ final class TestSimpleTableWithEnum extends Table { public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; vtable_start = bb_pos - bb.getInt(bb_pos); vtable_size = bb.getShort(vtable_start); } public TestSimpleTableWithEnum __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } - public byte color() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) : 2; } - public boolean mutateColor(byte color) { int o = __offset(4); if (o != 0) { bb.put(o + bb_pos, color); return true; } else { return false; } } + public int color() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) & 0xFF : 2; } + public boolean mutateColor(int color) { int o = __offset(4); if (o != 0) { bb.put(o + bb_pos, (byte)color); return true; } else { return false; } } public static int createTestSimpleTableWithEnum(FlatBufferBuilder builder, - byte color) { + int 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 void addColor(FlatBufferBuilder builder, int color) { builder.addByte(0, (byte)color, (byte)2); } public static int endTestSimpleTableWithEnum(FlatBufferBuilder builder) { int o = builder.endObject(); return o; diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.lua b/tests/MyGame/Example/TestSimpleTableWithEnum.lua index c17fb9670..32c8251d7 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.lua +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.lua @@ -24,12 +24,12 @@ end function TestSimpleTableWithEnum_mt:Color() local o = self.view:Offset(4) if o ~= 0 then - return self.view:Get(flatbuffers.N.Int8, o + self.view.pos) + return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos) end return 2 end function TestSimpleTableWithEnum.Start(builder) builder:StartObject(1) end -function TestSimpleTableWithEnum.AddColor(builder, color) builder:PrependInt8Slot(0, color, 2) end +function TestSimpleTableWithEnum.AddColor(builder, color) builder:PrependUint8Slot(0, color, 2) end function TestSimpleTableWithEnum.End(builder) return builder:EndObject() end return TestSimpleTableWithEnum -- return the module \ No newline at end of file diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.php b/tests/MyGame/Example/TestSimpleTableWithEnum.php index d37481fc3..6429f8d8e 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.php +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.php @@ -48,12 +48,12 @@ class TestSimpleTableWithEnum extends Table } /** - * @return sbyte + * @return byte */ public function getColor() { $o = $this->__offset(4); - return $o != 0 ? $this->bb->getSbyte($o + $this->bb_pos) : \MyGame\Example\Color::Green; + return $o != 0 ? $this->bb->getByte($o + $this->bb_pos) : \MyGame\Example\Color::Green; } /** @@ -79,12 +79,12 @@ class TestSimpleTableWithEnum extends Table /** * @param FlatBufferBuilder $builder - * @param sbyte + * @param byte * @return void */ public static function addColor(FlatBufferBuilder $builder, $color) { - $builder->addSbyteX(0, $color, 2); + $builder->addByteX(0, $color, 2); } /** diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.py b/tests/MyGame/Example/TestSimpleTableWithEnum.py index 8d64e971d..70a3c1d57 100644 --- a/tests/MyGame/Example/TestSimpleTableWithEnum.py +++ b/tests/MyGame/Example/TestSimpleTableWithEnum.py @@ -22,9 +22,9 @@ class TestSimpleTableWithEnum(object): def Color(self): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: - return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) return 2 def TestSimpleTableWithEnumStart(builder): builder.StartObject(1) -def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependInt8Slot(0, color, 2) +def TestSimpleTableWithEnumAddColor(builder, color): builder.PrependUint8Slot(0, color, 2) def TestSimpleTableWithEnumEnd(builder): return builder.EndObject() diff --git a/tests/MyGame/Example/Vec3.cs b/tests/MyGame/Example/Vec3.cs index b0f95a097..88e1c57da 100644 --- a/tests/MyGame/Example/Vec3.cs +++ b/tests/MyGame/Example/Vec3.cs @@ -23,8 +23,8 @@ public struct Vec3 : IFlatbufferObject public void MutateZ(float z) { __p.bb.PutFloat(__p.bb_pos + 8, z); } public double Test1 { get { return __p.bb.GetDouble(__p.bb_pos + 16); } } public void MutateTest1(double test1) { __p.bb.PutDouble(__p.bb_pos + 16, test1); } - public Color Test2 { get { return (Color)__p.bb.GetSbyte(__p.bb_pos + 24); } } - public void MutateTest2(Color test2) { __p.bb.PutSbyte(__p.bb_pos + 24, (sbyte)test2); } + public Color Test2 { get { return (Color)__p.bb.Get(__p.bb_pos + 24); } } + public void MutateTest2(Color test2) { __p.bb.Put(__p.bb_pos + 24, (byte)test2); } public Test Test3 { get { return (new Test()).__assign(__p.bb_pos + 26, __p.bb); } } public static Offset CreateVec3(FlatBufferBuilder builder, float X, float Y, float Z, double Test1, Color Test2, short test3_A, sbyte test3_B) { @@ -35,7 +35,7 @@ public struct Vec3 : IFlatbufferObject builder.PutSbyte(test3_B); builder.PutShort(test3_A); builder.Pad(1); - builder.PutSbyte((sbyte)Test2); + builder.PutByte((byte)Test2); builder.PutDouble(Test1); builder.Pad(4); builder.PutFloat(Z); diff --git a/tests/MyGame/Example/Vec3.go b/tests/MyGame/Example/Vec3.go index 520b9cc40..81b5c396d 100644 --- a/tests/MyGame/Example/Vec3.go +++ b/tests/MyGame/Example/Vec3.go @@ -48,10 +48,10 @@ func (rcv *Vec3) MutateTest1(n float64) bool { } func (rcv *Vec3) Test2() Color { - return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(24)) + return rcv._tab.GetByte(rcv._tab.Pos + flatbuffers.UOffsetT(24)) } func (rcv *Vec3) MutateTest2(n Color) bool { - return rcv._tab.MutateInt8(rcv._tab.Pos+flatbuffers.UOffsetT(24), n) + return rcv._tab.MutateByte(rcv._tab.Pos+flatbuffers.UOffsetT(24), n) } func (rcv *Vec3) Test3(obj *Test) *Test { @@ -62,7 +62,7 @@ func (rcv *Vec3) Test3(obj *Test) *Test { return obj } -func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 int8, test3_a int16, test3_b int8) flatbuffers.UOffsetT { +func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 byte, test3_a int16, test3_b int8) flatbuffers.UOffsetT { builder.Prep(8, 32) builder.Pad(2) builder.Prep(2, 4) @@ -70,7 +70,7 @@ func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, t builder.PrependInt8(test3_b) builder.PrependInt16(test3_a) builder.Pad(1) - builder.PrependInt8(test2) + builder.PrependByte(test2) builder.PrependFloat64(test1) builder.Pad(4) builder.PrependFloat32(z) diff --git a/tests/MyGame/Example/Vec3.java b/tests/MyGame/Example/Vec3.java index 2e43f0516..f97e02268 100644 --- a/tests/MyGame/Example/Vec3.java +++ b/tests/MyGame/Example/Vec3.java @@ -20,12 +20,12 @@ public final class Vec3 extends Struct { public void mutateZ(float z) { bb.putFloat(bb_pos + 8, z); } public double test1() { return bb.getDouble(bb_pos + 16); } public void mutateTest1(double test1) { bb.putDouble(bb_pos + 16, test1); } - public byte test2() { return bb.get(bb_pos + 24); } - public void mutateTest2(byte test2) { bb.put(bb_pos + 24, test2); } + public int test2() { return bb.get(bb_pos + 24) & 0xFF; } + public void mutateTest2(int test2) { bb.put(bb_pos + 24, (byte)test2); } public Test test3() { return test3(new Test()); } public Test test3(Test obj) { return obj.__assign(bb_pos + 26, bb); } - public static int createVec3(FlatBufferBuilder builder, float x, float y, float z, double test1, byte test2, short test3_a, byte test3_b) { + public static int createVec3(FlatBufferBuilder builder, float x, float y, float z, double test1, int test2, short test3_a, byte test3_b) { builder.prep(8, 32); builder.pad(2); builder.prep(2, 4); @@ -33,7 +33,7 @@ public final class Vec3 extends Struct { builder.putByte(test3_b); builder.putShort(test3_a); builder.pad(1); - builder.putByte(test2); + builder.putByte((byte)test2); builder.putDouble(test1); builder.pad(4); builder.putFloat(z); diff --git a/tests/MyGame/Example/Vec3.lua b/tests/MyGame/Example/Vec3.lua index 85e02d70b..24d4cc143 100644 --- a/tests/MyGame/Example/Vec3.lua +++ b/tests/MyGame/Example/Vec3.lua @@ -28,7 +28,7 @@ function Vec3_mt:Test1() return self.view:Get(flatbuffers.N.Float64, self.view.pos + 16) end function Vec3_mt:Test2() - return self.view:Get(flatbuffers.N.Int8, self.view.pos + 24) + return self.view:Get(flatbuffers.N.Uint8, self.view.pos + 24) end function Vec3_mt:Test3(obj) obj:Init(self.view.bytes, self.view.pos + 26) @@ -42,7 +42,7 @@ function Vec3.CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b) builder:PrependInt8(test3_b) builder:PrependInt16(test3_a) builder:Pad(1) - builder:PrependInt8(test2) + builder:PrependUint8(test2) builder:PrependFloat64(test1) builder:Pad(4) builder:PrependFloat32(z) diff --git a/tests/MyGame/Example/Vec3.php b/tests/MyGame/Example/Vec3.php index 288c1834d..4d149e6f5 100644 --- a/tests/MyGame/Example/Vec3.php +++ b/tests/MyGame/Example/Vec3.php @@ -55,11 +55,11 @@ class Vec3 extends Struct } /** - * @return sbyte + * @return byte */ public function GetTest2() { - return $this->bb->getSbyte($this->bb_pos + 24); + return $this->bb->getByte($this->bb_pos + 24); } /** @@ -85,7 +85,7 @@ class Vec3 extends Struct $builder->putSbyte($test3_b); $builder->putShort($test3_a); $builder->pad(1); - $builder->putSbyte($test2); + $builder->putByte($test2); $builder->putDouble($test1); $builder->pad(4); $builder->putFloat($z); diff --git a/tests/MyGame/Example/Vec3.py b/tests/MyGame/Example/Vec3.py index 20399edd6..1f32390fc 100644 --- a/tests/MyGame/Example/Vec3.py +++ b/tests/MyGame/Example/Vec3.py @@ -20,7 +20,7 @@ class Vec3(object): # Vec3 def Test1(self): return self._tab.Get(flatbuffers.number_types.Float64Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(16)) # Vec3 - def Test2(self): return self._tab.Get(flatbuffers.number_types.Int8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(24)) + def Test2(self): return self._tab.Get(flatbuffers.number_types.Uint8Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(24)) # Vec3 def Test3(self, obj): obj.Init(self._tab.Bytes, self._tab.Pos + 26) @@ -35,7 +35,7 @@ def CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b): builder.PrependInt8(test3_b) builder.PrependInt16(test3_a) builder.Pad(1) - builder.PrependInt8(test2) + builder.PrependUint8(test2) builder.PrependFloat64(test1) builder.Pad(4) builder.PrependFloat32(z) diff --git a/tests/generate_code.bat b/tests/generate_code.bat index 0ddcddddc..712e76d07 100644 --- a/tests/generate_code.bat +++ b/tests/generate_code.bat @@ -15,9 +15,9 @@ set buildtype=Release if "%1"=="-b" set buildtype=%2 -..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --lobster --lua --js --rust --ts --php --grpc --gen-mutable --reflect-names --gen-object-api --gen-compare --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json || goto FAIL -..\%buildtype%\flatc.exe --cpp --java --csharp --go --binary --python --lobster --lua --js --rust --ts --php --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs || goto FAIL -..\%buildtype%\flatc.exe --cpp --java --js --ts --php --gen-mutable --reflect-names --gen-object-api --gen-compare --cpp-ptr-type flatbuffers::unique_ptr -o union_vector ./union_vector/union_vector.fbs || goto FAIL +..\%buildtype%\flatc.exe --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --rust --grpc --gen-mutable --reflect-names --gen-object-api --gen-compare --no-includes --cpp-ptr-type flatbuffers::unique_ptr --no-fb-import -I include_test monster_test.fbs monsterdata_test.json || goto FAIL +..\%buildtype%\flatc.exe --cpp --java --csharp --dart --go --binary --lobster --lua --python --js --ts --php --rust --gen-mutable --reflect-names --no-fb-import --cpp-ptr-type flatbuffers::unique_ptr -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs || goto FAIL +..\%buildtype%\flatc.exe --cpp --java --csharp --js --ts --php --gen-mutable --reflect-names --gen-object-api --gen-compare --cpp-ptr-type flatbuffers::unique_ptr -o union_vector ./union_vector/union_vector.fbs || goto FAIL ..\%buildtype%\flatc.exe -b --schema --bfbs-comments --bfbs-builtins -I include_test monster_test.fbs || goto FAIL ..\%buildtype%\flatc.exe --jsonschema --schema -I include_test monster_test.fbs || goto FAIL diff --git a/tests/go_test.go b/tests/go_test.go index 0c16da911..fffb0ebcf 100644 --- a/tests/go_test.go +++ b/tests/go_test.go @@ -199,8 +199,8 @@ func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string, fail(FailString("Pos.Test1", float64(3.0), got)) } - if got := vec.Test2(); int8(2) != got { - fail(FailString("Pos.Test2", int8(2), got)) + if got := vec.Test2(); uint8(2) != got { + fail(FailString("Pos.Test2", uint8(2), got)) } // initialize a Test from Test3(...) @@ -331,7 +331,7 @@ func CheckMutateBuffer(org []byte, offset flatbuffers.UOffsetT, fail func(string testcase{"Pos.Y'", func() bool { return monster.Pos(nil).Y() == float32(2.0) }}, testcase{"Pos.Z'", func() bool { return monster.Pos(nil).Z() == float32(3.0) }}, testcase{"Pos.Test1'", func() bool { return monster.Pos(nil).Test1() == float64(3.0) }}, - testcase{"Pos.Test2'", func() bool { return monster.Pos(nil).Test2() == int8(2) }}, + testcase{"Pos.Test2'", func() bool { return monster.Pos(nil).Test2() == uint8(2) }}, testcase{"Pos.Test3.A", func() bool { return monster.Pos(nil).Test3(nil).A() == int16(5) }}, testcase{"Pos.Test3.B", func() bool { return monster.Pos(nil).Test3(nil).B() == int8(6) }}, testcase{"Inventory[2]", func() bool { return monster.Inventory(2) == byte(2) }}, @@ -359,7 +359,7 @@ func CheckMutateBuffer(org []byte, offset flatbuffers.UOffsetT, fail func(string testcase{"Pos.Y'", func() bool { return monster.Pos(nil).Y() == float32(20.0) }}, testcase{"Pos.Z'", func() bool { return monster.Pos(nil).Z() == float32(30.0) }}, testcase{"Pos.Test1'", func() bool { return monster.Pos(nil).Test1() == float64(30.0) }}, - testcase{"Pos.Test2'", func() bool { return monster.Pos(nil).Test2() == int8(20) }}, + testcase{"Pos.Test2'", func() bool { return monster.Pos(nil).Test2() == uint8(20) }}, testcase{"Pos.Test3.A", func() bool { return monster.Pos(nil).Test3(nil).A() == int16(50) }}, testcase{"Pos.Test3.B", func() bool { return monster.Pos(nil).Test3(nil).B() == int8(60) }}, testcase{"Inventory[2]", func() bool { return monster.Inventory(2) == byte(200) }}, diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index fefdd2c73..4bb3af062 100644 Binary files a/tests/monster_test.bfbs and b/tests/monster_test.bfbs differ diff --git a/tests/monster_test.fbs b/tests/monster_test.fbs index d57185347..082e85046 100644 --- a/tests/monster_test.fbs +++ b/tests/monster_test.fbs @@ -14,7 +14,7 @@ namespace MyGame.Example; attribute "priority"; -enum Color:byte (bit_flags) { Red = 0, Green, Blue = 3, } +enum Color:ubyte (bit_flags) { Red = 0, Green, Blue = 3, } union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster } diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index 3deadd930..693271b24 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -117,7 +117,7 @@ inline const Color (&EnumValuesColor())[3] { } inline const char * const *EnumNamesColor() { - static const char * const names[] = { + static const char * const names[9] = { "Red", "Green", "", @@ -157,7 +157,7 @@ inline const Any (&EnumValuesAny())[4] { } inline const char * const *EnumNamesAny() { - static const char * const names[] = { + static const char * const names[5] = { "NONE", "Monster", "TestSimpleTableWithEnum", @@ -299,7 +299,7 @@ inline const AnyUniqueAliases (&EnumValuesAnyUniqueAliases())[4] { } inline const char * const *EnumNamesAnyUniqueAliases() { - static const char * const names[] = { + static const char * const names[5] = { "NONE", "M", "T", @@ -441,7 +441,7 @@ inline const AnyAmbiguousAliases (&EnumValuesAnyAmbiguousAliases())[4] { } inline const char * const *EnumNamesAnyAmbiguousAliases() { - static const char * const names[] = { + static const char * const names[5] = { "NONE", "M1", "M2", @@ -587,7 +587,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Vec3 FLATBUFFERS_FINAL_CLASS { float z_; int32_t padding0__; double test1_; - int8_t test2_; + uint8_t test2_; int8_t padding1__; Test test3_; int16_t padding2__; @@ -605,7 +605,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Vec3 FLATBUFFERS_FINAL_CLASS { z_(flatbuffers::EndianScalar(_z)), padding0__(0), test1_(flatbuffers::EndianScalar(_test1)), - test2_(flatbuffers::EndianScalar(static_cast(_test2))), + test2_(flatbuffers::EndianScalar(static_cast(_test2))), padding1__(0), test3_(_test3), padding2__(0) { @@ -641,7 +641,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Vec3 FLATBUFFERS_FINAL_CLASS { return static_cast(flatbuffers::EndianScalar(test2_)); } void mutate_test2(Color _test2) { - flatbuffers::WriteScalar(&test2_, static_cast(_test2)); + flatbuffers::WriteScalar(&test2_, static_cast(_test2)); } const Test &test3() const { return test3_; @@ -854,14 +854,14 @@ struct TestSimpleTableWithEnum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Ta VT_COLOR = 4 }; Color color() const { - return static_cast(GetField(VT_COLOR, 2)); + return static_cast(GetField(VT_COLOR, 2)); } bool mutate_color(Color _color) { - return SetField(VT_COLOR, static_cast(_color), 2); + return SetField(VT_COLOR, static_cast(_color), 2); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && - VerifyField(verifier, VT_COLOR) && + VerifyField(verifier, VT_COLOR) && verifier.EndTable(); } TestSimpleTableWithEnumT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; @@ -873,7 +873,7 @@ struct TestSimpleTableWithEnumBuilder { flatbuffers::FlatBufferBuilder &fbb_; flatbuffers::uoffset_t start_; void add_color(Color color) { - fbb_.AddElement(TestSimpleTableWithEnum::VT_COLOR, static_cast(color), 2); + fbb_.AddElement(TestSimpleTableWithEnum::VT_COLOR, static_cast(color), 2); } explicit TestSimpleTableWithEnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { @@ -1301,10 +1301,10 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { return GetPointer *>(VT_INVENTORY); } Color color() const { - return static_cast(GetField(VT_COLOR, 8)); + return static_cast(GetField(VT_COLOR, 8)); } bool mutate_color(Color _color) { - return SetField(VT_COLOR, static_cast(_color), 8); + return SetField(VT_COLOR, static_cast(_color), 8); } Any test_type() const { return static_cast(GetField(VT_TEST_TYPE, 0)); @@ -1583,11 +1583,11 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { void *mutable_any_ambiguous() { return GetPointer(VT_ANY_AMBIGUOUS); } - const flatbuffers::Vector *vector_of_enums() const { - return GetPointer *>(VT_VECTOR_OF_ENUMS); + const flatbuffers::Vector *vector_of_enums() const { + return GetPointer *>(VT_VECTOR_OF_ENUMS); } - flatbuffers::Vector *mutable_vector_of_enums() { - return GetPointer *>(VT_VECTOR_OF_ENUMS); + flatbuffers::Vector *mutable_vector_of_enums() { + return GetPointer *>(VT_VECTOR_OF_ENUMS); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && @@ -1598,7 +1598,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { verifier.VerifyString(name()) && VerifyOffset(verifier, VT_INVENTORY) && verifier.VerifyVector(inventory()) && - VerifyField(verifier, VT_COLOR) && + VerifyField(verifier, VT_COLOR) && VerifyField(verifier, VT_TEST_TYPE) && VerifyOffset(verifier, VT_TEST) && VerifyAny(verifier, test(), test_type()) && @@ -1718,7 +1718,7 @@ struct MonsterBuilder { fbb_.AddOffset(Monster::VT_INVENTORY, inventory); } void add_color(Color color) { - fbb_.AddElement(Monster::VT_COLOR, static_cast(color), 8); + fbb_.AddElement(Monster::VT_COLOR, static_cast(color), 8); } void add_test_type(Any test_type) { fbb_.AddElement(Monster::VT_TEST_TYPE, static_cast(test_type), 0); @@ -1840,7 +1840,7 @@ struct MonsterBuilder { void add_any_ambiguous(flatbuffers::Offset any_ambiguous) { fbb_.AddOffset(Monster::VT_ANY_AMBIGUOUS, any_ambiguous); } - void add_vector_of_enums(flatbuffers::Offset> vector_of_enums) { + void add_vector_of_enums(flatbuffers::Offset> vector_of_enums) { fbb_.AddOffset(Monster::VT_VECTOR_OF_ENUMS, vector_of_enums); } explicit MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) @@ -1904,7 +1904,7 @@ inline flatbuffers::Offset CreateMonster( flatbuffers::Offset any_unique = 0, AnyAmbiguousAliases any_ambiguous_type = AnyAmbiguousAliases_NONE, flatbuffers::Offset any_ambiguous = 0, - flatbuffers::Offset> vector_of_enums = 0) { + flatbuffers::Offset> vector_of_enums = 0) { MonsterBuilder builder_(_fbb); builder_.add_non_owning_reference(non_owning_reference); builder_.add_co_owning_reference(co_owning_reference); @@ -2004,7 +2004,7 @@ inline flatbuffers::Offset CreateMonsterDirect( flatbuffers::Offset any_unique = 0, AnyAmbiguousAliases any_ambiguous_type = AnyAmbiguousAliases_NONE, flatbuffers::Offset any_ambiguous = 0, - const std::vector *vector_of_enums = nullptr) { + const std::vector *vector_of_enums = nullptr) { auto name__ = name ? _fbb.CreateString(name) : 0; auto inventory__ = inventory ? _fbb.CreateVector(*inventory) : 0; auto test4__ = test4 ? _fbb.CreateVectorOfStructs(*test4) : 0; @@ -2023,7 +2023,7 @@ inline flatbuffers::Offset CreateMonsterDirect( auto vector_of_strong_referrables__ = vector_of_strong_referrables ? _fbb.CreateVector>(*vector_of_strong_referrables) : 0; auto vector_of_co_owning_references__ = vector_of_co_owning_references ? _fbb.CreateVector(*vector_of_co_owning_references) : 0; auto vector_of_non_owning_references__ = vector_of_non_owning_references ? _fbb.CreateVector(*vector_of_non_owning_references) : 0; - auto vector_of_enums__ = vector_of_enums ? _fbb.CreateVector(*vector_of_enums) : 0; + auto vector_of_enums__ = vector_of_enums ? _fbb.CreateVector(*vector_of_enums) : 0; return MyGame::Example::CreateMonster( _fbb, pos, @@ -2612,7 +2612,7 @@ inline flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder auto _any_unique = _o->any_unique.Pack(_fbb); 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(flatbuffers::data(_o->vector_of_enums), _o->vector_of_enums.size()) : 0; + auto _vector_of_enums = _o->vector_of_enums.size() ? _fbb.CreateVectorScalarCast(flatbuffers::data(_o->vector_of_enums), _o->vector_of_enums.size()) : 0; return MyGame::Example::CreateMonster( _fbb, _pos, @@ -3058,9 +3058,9 @@ inline void AnyAmbiguousAliasesUnion::Reset() { inline const flatbuffers::TypeTable *ColorTypeTable() { static const flatbuffers::TypeCode type_codes[] = { - { flatbuffers::ET_CHAR, 0, 0 }, - { flatbuffers::ET_CHAR, 0, 0 }, - { flatbuffers::ET_CHAR, 0, 0 } + { flatbuffers::ET_UCHAR, 0, 0 }, + { flatbuffers::ET_UCHAR, 0, 0 }, + { flatbuffers::ET_UCHAR, 0, 0 } }; static const flatbuffers::TypeFunction type_refs[] = { ColorTypeTable @@ -3187,7 +3187,7 @@ inline const flatbuffers::TypeTable *TestTypeTable() { inline const flatbuffers::TypeTable *TestSimpleTableWithEnumTypeTable() { static const flatbuffers::TypeCode type_codes[] = { - { flatbuffers::ET_CHAR, 0, 0 } + { flatbuffers::ET_UCHAR, 0, 0 } }; static const flatbuffers::TypeFunction type_refs[] = { ColorTypeTable @@ -3207,7 +3207,7 @@ inline const flatbuffers::TypeTable *Vec3TypeTable() { { flatbuffers::ET_FLOAT, 0, -1 }, { flatbuffers::ET_FLOAT, 0, -1 }, { flatbuffers::ET_DOUBLE, 0, -1 }, - { flatbuffers::ET_CHAR, 0, 0 }, + { flatbuffers::ET_UCHAR, 0, 0 }, { flatbuffers::ET_SEQUENCE, 0, 1 } }; static const flatbuffers::TypeFunction type_refs[] = { @@ -3283,7 +3283,7 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() { { flatbuffers::ET_STRING, 0, -1 }, { flatbuffers::ET_BOOL, 0, -1 }, { flatbuffers::ET_UCHAR, 1, -1 }, - { flatbuffers::ET_CHAR, 0, 1 }, + { flatbuffers::ET_UCHAR, 0, 1 }, { flatbuffers::ET_UTYPE, 0, 2 }, { flatbuffers::ET_SEQUENCE, 0, 2 }, { flatbuffers::ET_SEQUENCE, 1, 3 }, @@ -3324,7 +3324,7 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() { { flatbuffers::ET_SEQUENCE, 0, 9 }, { flatbuffers::ET_UTYPE, 0, 10 }, { flatbuffers::ET_SEQUENCE, 0, 10 }, - { flatbuffers::ET_CHAR, 1, 1 } + { flatbuffers::ET_UCHAR, 1, 1 } }; static const flatbuffers::TypeFunction type_refs[] = { Vec3TypeTable, diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index cfa82d1f1..44925440b 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -346,7 +346,7 @@ MyGame.Example.TestSimpleTableWithEnum.getRootAsTestSimpleTableWithEnum = functi */ MyGame.Example.TestSimpleTableWithEnum.prototype.color = function() { var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Green; + return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readUint8(this.bb_pos + offset)) : MyGame.Example.Color.Green; }; /** @@ -360,7 +360,7 @@ MyGame.Example.TestSimpleTableWithEnum.prototype.mutate_color = function(value) return false; } - this.bb.writeInt8(this.bb_pos + offset, value); + this.bb.writeUint8(this.bb_pos + offset, value); return true; }; @@ -517,7 +517,7 @@ MyGame.Example.Vec3.prototype.mutate_test1 = function(value) { * @returns {MyGame.Example.Color} */ MyGame.Example.Vec3.prototype.test2 = function() { - return /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb_pos + 24)); + return /** @type {MyGame.Example.Color} */ (this.bb.readUint8(this.bb_pos + 24)); }; /** @@ -531,7 +531,7 @@ MyGame.Example.Vec3.prototype.mutate_test2 = function(value) { return false; } - this.bb.writeInt8(this.bb_pos + offset, value); + this.bb.writeUint8(this.bb_pos + offset, value); return true; }; @@ -1031,7 +1031,7 @@ MyGame.Example.Monster.prototype.inventoryArray = function() { */ MyGame.Example.Monster.prototype.color = function() { var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Blue; + return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readUint8(this.bb_pos + offset)) : MyGame.Example.Color.Blue; }; /** @@ -1045,7 +1045,7 @@ MyGame.Example.Monster.prototype.mutate_color = function(value) { return false; } - this.bb.writeInt8(this.bb_pos + offset, value); + this.bb.writeUint8(this.bb_pos + offset, value); return true; }; @@ -1838,7 +1838,7 @@ MyGame.Example.Monster.prototype.anyAmbiguous = function(obj) { */ MyGame.Example.Monster.prototype.vectorOfEnums = function(index) { var offset = this.bb.__offset(this.bb_pos, 98); - return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index)) : /** @type {MyGame.Example.Color} */ (0); + return offset ? /** @type {MyGame.Example.Color} */ (this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index)) : /** @type {MyGame.Example.Color} */ (0); }; /** @@ -1850,11 +1850,11 @@ MyGame.Example.Monster.prototype.vectorOfEnumsLength = function() { }; /** - * @returns {Int8Array} + * @returns {Uint8Array} */ MyGame.Example.Monster.prototype.vectorOfEnumsArray = function() { var offset = this.bb.__offset(this.bb_pos, 98); - return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : 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; }; /** diff --git a/tests/monster_test_generated.lobster b/tests/monster_test_generated.lobster index bda8b6a00..63902b8c7 100644 --- a/tests/monster_test_generated.lobster +++ b/tests/monster_test_generated.lobster @@ -99,7 +99,7 @@ def GetRootAsTestSimpleTableWithEnum(buf:string): TestSimpleTableWithEnum { buf, def TestSimpleTableWithEnumStart(b_:flatbuffers_builder): b_.StartObject(1) def TestSimpleTableWithEnumAddColor(b_:flatbuffers_builder, color:int): - b_.PrependInt8Slot(0, color, 2) + b_.PrependUint8Slot(0, color, 2) def TestSimpleTableWithEnumEnd(b_:flatbuffers_builder): b_.EndObject() @@ -125,7 +125,7 @@ def CreateVec3(b_:flatbuffers_builder, x:float, y:float, z:float, test1:float, t b_.PrependInt8(test3_b) b_.PrependInt16(test3_a) b_.Pad(1) - b_.PrependInt8(test2) + b_.PrependUint8(test2) b_.PrependFloat64(test1) b_.Pad(4) b_.PrependFloat32(z) @@ -351,7 +351,7 @@ def MonsterCreateInventoryVector(b_:flatbuffers_builder, v_:[int]): reverse(v_) e_: b_.PrependUint8(e_) b_.EndVector(v_.length) def MonsterAddColor(b_:flatbuffers_builder, color:int): - b_.PrependInt8Slot(6, color, 8) + b_.PrependUint8Slot(6, color, 8) def MonsterAddTestType(b_:flatbuffers_builder, test_type:int): b_.PrependUint8Slot(7, test_type, 0) def MonsterAddTest(b_:flatbuffers_builder, test:int): @@ -522,7 +522,7 @@ def MonsterStartVectorOfEnumsVector(b_:flatbuffers_builder, n_:int): b_.StartVector(1, n_, 1) def MonsterCreateVectorOfEnumsVector(b_:flatbuffers_builder, v_:[int]): b_.StartVector(1, v_.length, 1) - reverse(v_) e_: b_.PrependInt8(e_) + reverse(v_) e_: b_.PrependUint8(e_) b_.EndVector(v_.length) def MonsterEnd(b_:flatbuffers_builder): b_.EndObject() diff --git a/tests/monster_test_generated.rs b/tests/monster_test_generated.rs index 6a0f37a51..97663915b 100644 --- a/tests/monster_test_generated.rs +++ b/tests/monster_test_generated.rs @@ -164,7 +164,7 @@ pub mod example { use self::flatbuffers::EndianScalar; #[allow(non_camel_case_types)] -#[repr(i8)] +#[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum Color { Red = 1, @@ -173,8 +173,8 @@ pub enum Color { } -const ENUM_MIN_COLOR: i8 = 1; -const ENUM_MAX_COLOR: i8 = 8; +const ENUM_MIN_COLOR: u8 = 1; +const ENUM_MAX_COLOR: u8 = 8; impl<'a> flatbuffers::Follow<'a> for Color { type Inner = Self; @@ -187,14 +187,14 @@ impl<'a> flatbuffers::Follow<'a> for Color { impl flatbuffers::EndianScalar for Color { #[inline] fn to_little_endian(self) -> Self { - let n = i8::to_le(self as i8); - let p = &n as *const i8 as *const Color; + let n = u8::to_le(self as u8); + let p = &n as *const u8 as *const Color; 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 Color; + let n = u8::from_le(self as u8); + let p = &n as *const u8 as *const Color; unsafe { *p } } } @@ -227,7 +227,7 @@ const ENUM_NAMES_COLOR:[&'static str; 8] = [ ]; pub fn enum_name_color(e: Color) -> &'static str { - let index = e as i8 - Color::Red as i8; + let index = e as u8 - Color::Red as u8; ENUM_NAMES_COLOR[index as usize] } diff --git a/tests/monster_test_generated.ts b/tests/monster_test_generated.ts index 3784a19a5..ad8bd4335 100644 --- a/tests/monster_test_generated.ts +++ b/tests/monster_test_generated.ts @@ -255,7 +255,7 @@ static getRootAsTestSimpleTableWithEnum(bb:flatbuffers.ByteBuffer, obj?:TestSimp */ color():MyGame.Example.Color { var offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? /** */ (this.bb!.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Green; + return offset ? /** */ (this.bb!.readUint8(this.bb_pos + offset)) : MyGame.Example.Color.Green; }; /** @@ -269,7 +269,7 @@ mutate_color(value:MyGame.Example.Color):boolean { return false; } - this.bb!.writeInt8(this.bb_pos + offset, value); + this.bb!.writeUint8(this.bb_pos + offset, value); return true; }; @@ -415,7 +415,7 @@ mutate_test1(value:number):boolean { * @returns MyGame.Example.Color */ test2():MyGame.Example.Color { - return /** */ (this.bb!.readInt8(this.bb_pos + 24)); + return /** */ (this.bb!.readUint8(this.bb_pos + 24)); }; /** @@ -429,7 +429,7 @@ mutate_test2(value:MyGame.Example.Color):boolean { return false; } - this.bb!.writeInt8(this.bb_pos + offset, value); + this.bb!.writeUint8(this.bb_pos + offset, value); return true; }; @@ -899,7 +899,7 @@ inventoryArray():Uint8Array|null { */ color():MyGame.Example.Color { var offset = this.bb!.__offset(this.bb_pos, 16); - return offset ? /** */ (this.bb!.readInt8(this.bb_pos + offset)) : MyGame.Example.Color.Blue; + return offset ? /** */ (this.bb!.readUint8(this.bb_pos + offset)) : MyGame.Example.Color.Blue; }; /** @@ -913,7 +913,7 @@ mutate_color(value:MyGame.Example.Color):boolean { return false; } - this.bb!.writeInt8(this.bb_pos + offset, value); + this.bb!.writeUint8(this.bb_pos + offset, value); return true; }; @@ -1710,7 +1710,7 @@ anyAmbiguous(obj:T):T|null { */ vectorOfEnums(index: number):MyGame.Example.Color|null { var offset = this.bb!.__offset(this.bb_pos, 98); - return offset ? /** */ (this.bb!.readInt8(this.bb!.__vector(this.bb_pos + offset) + index)) : /** */ (0); + return offset ? /** */ (this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index)) : /** */ (0); }; /** @@ -1722,11 +1722,11 @@ vectorOfEnumsLength():number { }; /** - * @returns Int8Array + * @returns Uint8Array */ -vectorOfEnumsArray():Int8Array|null { +vectorOfEnumsArray():Uint8Array|null { var offset = this.bb!.__offset(this.bb_pos, 98); - return offset ? new Int8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : 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; }; /** diff --git a/tests/monster_test_my_game.example_generated.dart b/tests/monster_test_my_game.example_generated.dart index d4acf8765..be668b5d9 100644 --- a/tests/monster_test_my_game.example_generated.dart +++ b/tests/monster_test_my_game.example_generated.dart @@ -44,7 +44,7 @@ class _ColorReader extends fb.Reader { @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 AnyTypeId { @@ -257,7 +257,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() { @@ -285,7 +285,7 @@ class TestSimpleTableWithEnumBuilder { } int addColor(Color color) { - fbBuilder.addInt8(0, color?.value); + fbBuilder.addUint8(0, color?.value); return fbBuilder.offset; } @@ -309,7 +309,7 @@ class TestSimpleTableWithEnumObjectBuilder extends fb.ObjectBuilder { assert(fbBuilder != null); fbBuilder.startTable(); - fbBuilder.addInt8(0, _color?.value); + fbBuilder.addUint8(0, _color?.value); return fbBuilder.endTable(); } @@ -333,7 +333,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 @@ -364,7 +364,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); @@ -407,7 +407,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); @@ -688,7 +688,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 get inventory => const fb.ListReader(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) { @@ -800,7 +800,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) { @@ -1183,7 +1183,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(); @@ -1198,7 +1198,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); diff --git a/tests/namespace_test/namespace_test1_generated.h b/tests/namespace_test/namespace_test1_generated.h index 239e6e4b4..a9cfed0a5 100644 --- a/tests/namespace_test/namespace_test1_generated.h +++ b/tests/namespace_test/namespace_test1_generated.h @@ -35,7 +35,7 @@ inline const EnumInNestedNS (&EnumValuesEnumInNestedNS())[3] { } inline const char * const *EnumNamesEnumInNestedNS() { - static const char * const names[] = { + static const char * const names[4] = { "A", "B", "C", diff --git a/tests/test.cpp b/tests/test.cpp index 4bf042047..911d1aa16 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -172,7 +172,7 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) { // We use this special creation function because we have an array of // pre-C++11 (enum class) enums whose size likely is int, yet its declared // type in the schema is byte. - auto vecofcolors = builder.CreateVectorScalarCast(colors, 2); + auto vecofcolors = builder.CreateVectorScalarCast(colors, 2); // shortcut for creating monster with all fields set: auto mloc = CreateMonster(builder, &vec, 150, 80, name, inventory, Color_Blue, diff --git a/tests/union_vector/union_vector_generated.h b/tests/union_vector/union_vector_generated.h index 757a9584f..60c80b01e 100644 --- a/tests/union_vector/union_vector_generated.h +++ b/tests/union_vector/union_vector_generated.h @@ -59,7 +59,7 @@ inline const Character (&EnumValuesCharacter())[7] { } inline const char * const *EnumNamesCharacter() { - static const char * const names[] = { + static const char * const names[8] = { "NONE", "MuLan", "Rapunzel",