Fixed whole-number float default values missing a .0 suffix.
A previous commit that added "f" for C++/Java/C# would break on gcc of constants like 3f, which are now output as 3.0f Tested: on Linux Change-Id: If9cabbe3c6d6948a5050b8b123bda9c06e181f52
This commit is contained in:
parent
791c83aa7e
commit
4d7890c2c9
|
@ -543,6 +543,10 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
|||
if (!IsScalar(type.base_type))
|
||||
return Error("default values currently only supported for scalars");
|
||||
ECHECK(ParseSingleValue(field->value));
|
||||
if (IsFloat(field->value.type.base_type)) {
|
||||
if (!strpbrk(field->value.constant.c_str(), ".eE"))
|
||||
field->value.constant += ".0";
|
||||
}
|
||||
}
|
||||
|
||||
if (type.enum_def &&
|
||||
|
|
|
@ -74,8 +74,10 @@ public sealed class Monster : Table {
|
|||
public bool MutateTestarrayofbools(int j, bool testarrayofbools) { int o = __offset(52); if (o != 0) { bb.Put(__vector(o) + j * 1, (byte)(testarrayofbools ? 1 : 0)); return true; } else { return false; } }
|
||||
public float Testf { get { int o = __offset(54); return o != 0 ? bb.GetFloat(o + bb_pos) : (float)3.14159f; } }
|
||||
public bool MutateTestf(float testf) { int o = __offset(54); if (o != 0) { bb.PutFloat(o + bb_pos, testf); return true; } else { return false; } }
|
||||
public float Testf2 { get { int o = __offset(56); return o != 0 ? bb.GetFloat(o + bb_pos) : (float)3.0f; } }
|
||||
public bool MutateTestf2(float testf2) { int o = __offset(56); if (o != 0) { bb.PutFloat(o + bb_pos, testf2); return true; } else { return false; } }
|
||||
|
||||
public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(26); }
|
||||
public static void StartMonster(FlatBufferBuilder builder) { builder.StartObject(27); }
|
||||
public static void AddPos(FlatBufferBuilder builder, Offset<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); }
|
||||
|
@ -112,6 +114,7 @@ public sealed class Monster : Table {
|
|||
public static VectorOffset CreateTestarrayofboolsVector(FlatBufferBuilder builder, bool[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddBool(data[i]); return builder.EndVector(); }
|
||||
public static void StartTestarrayofboolsVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
|
||||
public static void AddTestf(FlatBufferBuilder builder, float testf) { builder.AddFloat(25, testf, 3.14159f); }
|
||||
public static void AddTestf2(FlatBufferBuilder builder, float testf2) { builder.AddFloat(26, testf2, 3.0f); }
|
||||
public static Offset<Monster> EndMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.EndObject();
|
||||
builder.Required(o, 10); // name
|
||||
|
|
|
@ -321,7 +321,15 @@ func (rcv *Monster) Testf() float32 {
|
|||
return 3.14159
|
||||
}
|
||||
|
||||
func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(26) }
|
||||
func (rcv *Monster) Testf2() float32 {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(56))
|
||||
if o != 0 {
|
||||
return rcv._tab.GetFloat32(o + rcv._tab.Pos)
|
||||
}
|
||||
return 3.0
|
||||
}
|
||||
|
||||
func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(27) }
|
||||
func MonsterAddPos(builder *flatbuffers.Builder, pos flatbuffers.UOffsetT) { builder.PrependStructSlot(0, flatbuffers.UOffsetT(pos), 0) }
|
||||
func MonsterAddMana(builder *flatbuffers.Builder, mana int16) { builder.PrependInt16Slot(1, mana, 150) }
|
||||
func MonsterAddHp(builder *flatbuffers.Builder, hp int16) { builder.PrependInt16Slot(2, hp, 100) }
|
||||
|
@ -359,4 +367,5 @@ func MonsterAddTestarrayofbools(builder *flatbuffers.Builder, testarrayofbools f
|
|||
func MonsterStartTestarrayofboolsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems, 1)
|
||||
}
|
||||
func MonsterAddTestf(builder *flatbuffers.Builder, testf float32) { builder.PrependFloat32Slot(25, testf, 3.14159) }
|
||||
func MonsterAddTestf2(builder *flatbuffers.Builder, testf2 float32) { builder.PrependFloat32Slot(26, testf2, 3.0) }
|
||||
func MonsterEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() }
|
||||
|
|
|
@ -80,8 +80,10 @@ public final class Monster extends Table {
|
|||
public boolean mutateTestarrayofbools(int j, boolean testarrayofbools) { int o = __offset(52); if (o != 0) { bb.put(__vector(o) + j * 1, (byte)(testarrayofbools ? 1 : 0)); return true; } else { return false; } }
|
||||
public float testf() { int o = __offset(54); return o != 0 ? bb.getFloat(o + bb_pos) : 3.14159f; }
|
||||
public boolean mutateTestf(float testf) { int o = __offset(54); if (o != 0) { bb.putFloat(o + bb_pos, testf); return true; } else { return false; } }
|
||||
public float testf2() { int o = __offset(56); return o != 0 ? bb.getFloat(o + bb_pos) : 3.0f; }
|
||||
public boolean mutateTestf2(float testf2) { int o = __offset(56); if (o != 0) { bb.putFloat(o + bb_pos, testf2); return true; } else { return false; } }
|
||||
|
||||
public static void startMonster(FlatBufferBuilder builder) { builder.startObject(26); }
|
||||
public static void startMonster(FlatBufferBuilder builder) { builder.startObject(27); }
|
||||
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); }
|
||||
|
@ -118,6 +120,7 @@ public final class Monster extends Table {
|
|||
public static int createTestarrayofboolsVector(FlatBufferBuilder builder, boolean[] data) { builder.startVector(1, data.length, 1); for (int i = data.length - 1; i >= 0; i--) builder.addBoolean(data[i]); return builder.endVector(); }
|
||||
public static void startTestarrayofboolsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(1, numElems, 1); }
|
||||
public static void addTestf(FlatBufferBuilder builder, float testf) { builder.addFloat(25, testf, 3.14159f); }
|
||||
public static void addTestf2(FlatBufferBuilder builder, float testf2) { builder.addFloat(26, testf2, 3.0f); }
|
||||
public static int endMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.endObject();
|
||||
builder.required(o, 10); // name
|
||||
|
|
|
@ -342,22 +342,31 @@ class Monster extends Table
|
|||
return $o != 0 ? $this->bb->getFloat($o + $this->bb_pos) : 3.14159;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTestf2()
|
||||
{
|
||||
$o = $this->__offset(56);
|
||||
return $o != 0 ? $this->bb->getFloat($o + $this->bb_pos) : 3.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startMonster(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(26);
|
||||
$builder->StartObject(27);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
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)
|
||||
{
|
||||
$builder->startObject(26);
|
||||
$builder->startObject(27);
|
||||
self::addPos($builder, $pos);
|
||||
self::addMana($builder, $mana);
|
||||
self::addHp($builder, $hp);
|
||||
|
@ -383,6 +392,7 @@ class Monster extends Table
|
|||
self::addTesthashu64Fnv1a($builder, $testhashu64_fnv1a);
|
||||
self::addTestarrayofbools($builder, $testarrayofbools);
|
||||
self::addTestf($builder, $testf);
|
||||
self::addTestf2($builder, $testf2);
|
||||
$o = $builder->endObject();
|
||||
$builder->required($o, 10); // name
|
||||
return $o;
|
||||
|
@ -777,6 +787,16 @@ class Monster extends Table
|
|||
$builder->addFloatX(25, $testf, 3.14159);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param float
|
||||
* @return void
|
||||
*/
|
||||
public static function addTestf2(FlatBufferBuilder $builder, $testf2)
|
||||
{
|
||||
$builder->addFloatX(26, $testf2, 3.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
|
|
|
@ -269,7 +269,14 @@ class Monster(object):
|
|||
return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos)
|
||||
return 3.14159
|
||||
|
||||
def MonsterStart(builder): builder.StartObject(26)
|
||||
# Monster
|
||||
def Testf2(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(56))
|
||||
if o != 0:
|
||||
return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos)
|
||||
return 3.0
|
||||
|
||||
def MonsterStart(builder): builder.StartObject(27)
|
||||
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)
|
||||
|
@ -301,4 +308,5 @@ def MonsterAddTesthashu64Fnv1a(builder, testhashu64Fnv1a): builder.PrependUint64
|
|||
def MonsterAddTestarrayofbools(builder, testarrayofbools): builder.PrependUOffsetTRelativeSlot(24, flatbuffers.number_types.UOffsetTFlags.py_type(testarrayofbools), 0)
|
||||
def MonsterStartTestarrayofboolsVector(builder, numElems): return builder.StartVector(1, numElems, 1)
|
||||
def MonsterAddTestf(builder, testf): builder.PrependFloat32Slot(25, testf, 3.14159)
|
||||
def MonsterAddTestf2(builder, testf2): builder.PrependFloat32Slot(26, testf2, 3.0)
|
||||
def MonsterEnd(builder): return builder.EndObject()
|
||||
|
|
Binary file not shown.
|
@ -60,6 +60,7 @@ table Monster {
|
|||
testhashs64_fnv1a:long (id:22, hash:"fnv1a_64");
|
||||
testhashu64_fnv1a:ulong (id:23, hash:"fnv1a_64");
|
||||
testf:float = 3.14159 (id:25);
|
||||
testf2:float = 3 (id:26);
|
||||
}
|
||||
|
||||
rpc_service MonsterStorage {
|
||||
|
|
|
@ -204,7 +204,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||
VT_TESTHASHS64_FNV1A = 48,
|
||||
VT_TESTHASHU64_FNV1A = 50,
|
||||
VT_TESTARRAYOFBOOLS = 52,
|
||||
VT_TESTF = 54
|
||||
VT_TESTF = 54,
|
||||
VT_TESTF2 = 56
|
||||
};
|
||||
const Vec3 *pos() const { return GetStruct<const Vec3 *>(VT_POS); }
|
||||
Vec3 *mutable_pos() { return GetStruct<Vec3 *>(VT_POS); }
|
||||
|
@ -261,6 +262,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||
flatbuffers::Vector<uint8_t> *mutable_testarrayofbools() { return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_TESTARRAYOFBOOLS); }
|
||||
float testf() const { return GetField<float>(VT_TESTF, 3.14159f); }
|
||||
bool mutate_testf(float _testf) { return SetField(VT_TESTF, _testf); }
|
||||
float testf2() const { return GetField<float>(VT_TESTF2, 3.0f); }
|
||||
bool mutate_testf2(float _testf2) { return SetField(VT_TESTF2, _testf2); }
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<Vec3>(verifier, VT_POS) &&
|
||||
|
@ -300,6 +303,7 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||
VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTARRAYOFBOOLS) &&
|
||||
verifier.Verify(testarrayofbools()) &&
|
||||
VerifyField<float>(verifier, VT_TESTF) &&
|
||||
VerifyField<float>(verifier, VT_TESTF2) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
@ -332,10 +336,11 @@ struct MonsterBuilder {
|
|||
void add_testhashu64_fnv1a(uint64_t testhashu64_fnv1a) { fbb_.AddElement<uint64_t>(Monster::VT_TESTHASHU64_FNV1A, testhashu64_fnv1a, 0); }
|
||||
void add_testarrayofbools(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> testarrayofbools) { fbb_.AddOffset(Monster::VT_TESTARRAYOFBOOLS, testarrayofbools); }
|
||||
void add_testf(float testf) { fbb_.AddElement<float>(Monster::VT_TESTF, testf, 3.14159f); }
|
||||
void add_testf2(float testf2) { fbb_.AddElement<float>(Monster::VT_TESTF2, testf2, 3.0f); }
|
||||
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||
MonsterBuilder &operator=(const MonsterBuilder &);
|
||||
flatbuffers::Offset<Monster> Finish() {
|
||||
auto o = flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 26));
|
||||
auto o = flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 27));
|
||||
fbb_.Required(o, Monster::VT_NAME); // name
|
||||
return o;
|
||||
}
|
||||
|
@ -366,12 +371,14 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
|||
int64_t testhashs64_fnv1a = 0,
|
||||
uint64_t testhashu64_fnv1a = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> testarrayofbools = 0,
|
||||
float testf = 3.14159f) {
|
||||
float testf = 3.14159f,
|
||||
float testf2 = 3.0f) {
|
||||
MonsterBuilder builder_(_fbb);
|
||||
builder_.add_testhashu64_fnv1a(testhashu64_fnv1a);
|
||||
builder_.add_testhashs64_fnv1a(testhashs64_fnv1a);
|
||||
builder_.add_testhashu64_fnv1(testhashu64_fnv1);
|
||||
builder_.add_testhashs64_fnv1(testhashs64_fnv1);
|
||||
builder_.add_testf2(testf2);
|
||||
builder_.add_testf(testf);
|
||||
builder_.add_testarrayofbools(testarrayofbools);
|
||||
builder_.add_testhashu32_fnv1a(testhashu32_fnv1a);
|
||||
|
|
|
@ -685,11 +685,19 @@ MyGame.Example.Monster.prototype.testf = function() {
|
|||
return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.14159;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Example.Monster.prototype.testf2 = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 56);
|
||||
return offset ? this.bb.readFloat32(this.bb_pos + offset) : 3.0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
*/
|
||||
MyGame.Example.Monster.startMonster = function(builder) {
|
||||
builder.startObject(26);
|
||||
builder.startObject(27);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1005,6 +1013,14 @@ MyGame.Example.Monster.addTestf = function(builder, testf) {
|
|||
builder.addFieldFloat32(25, testf, 3.14159);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} testf2
|
||||
*/
|
||||
MyGame.Example.Monster.addTestf2 = function(builder, testf2) {
|
||||
builder.addFieldFloat32(26, testf2, 3.0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @returns {flatbuffers.Offset}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue