From f575b02fda04fe579fb23442234feb8129b77ee2 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 16 Nov 2018 16:22:18 -0800 Subject: [PATCH] Make string/vector field serialization order not depend on optimizer. Multiple calls of e.g. CreateString inside a call to a CreateTable could cause those strings to end up in different locations in the wire format, since order or argument evaluation is undefined. This is allowed by the FlatBuffer format, but it is not helpful, especially when debugging the contents of binaries, or comparing against a "golden" binary for tests etc. Now making sure that all the CreateTableDirect calls first serialize sub strings/vectors before calling CreateTable. Also made similar changes to the serialization of "binary schemas". Change-Id: I5747c4038b37a0d400aca2bc592bec751cf5c172 --- include/flatbuffers/reflection_generated.h | 81 ++++++++----- samples/monster_generated.h | 12 +- src/idl_gen_cpp.cpp | 34 +++--- src/idl_parser.cpp | 126 ++++++++++---------- tests/monster_test.bfbs | Bin 7288 -> 7280 bytes tests/monster_test_generated.h | 66 ++++++---- tests/union_vector/union_vector_generated.h | 6 +- 7 files changed, 192 insertions(+), 133 deletions(-) diff --git a/include/flatbuffers/reflection_generated.h b/include/flatbuffers/reflection_generated.h index 0424d6ae9..fc720599c 100644 --- a/include/flatbuffers/reflection_generated.h +++ b/include/flatbuffers/reflection_generated.h @@ -222,10 +222,12 @@ inline flatbuffers::Offset CreateKeyValueDirect( flatbuffers::FlatBufferBuilder &_fbb, const char *key = nullptr, const char *value = nullptr) { + auto key__ = key ? _fbb.CreateString(key) : 0; + auto value__ = value ? _fbb.CreateString(value) : 0; return reflection::CreateKeyValue( _fbb, - key ? _fbb.CreateString(key) : 0, - value ? _fbb.CreateString(value) : 0); + key__, + value__); } struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -327,13 +329,15 @@ inline flatbuffers::Offset CreateEnumValDirect( flatbuffers::Offset object = 0, flatbuffers::Offset union_type = 0, const std::vector> *documentation = nullptr) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; return reflection::CreateEnumVal( _fbb, - name ? _fbb.CreateString(name) : 0, + name__, value, object, union_type, - documentation ? _fbb.CreateVector>(*documentation) : 0); + documentation__); } struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -451,14 +455,18 @@ inline flatbuffers::Offset CreateEnumDirect( flatbuffers::Offset underlying_type = 0, const std::vector> *attributes = nullptr, const std::vector> *documentation = nullptr) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto values__ = values ? _fbb.CreateVector>(*values) : 0; + auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; return reflection::CreateEnum( _fbb, - name ? _fbb.CreateString(name) : 0, - values ? _fbb.CreateVector>(*values) : 0, + name__, + values__, is_union, underlying_type, - attributes ? _fbb.CreateVector>(*attributes) : 0, - documentation ? _fbb.CreateVector>(*documentation) : 0); + attributes__, + documentation__); } struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -628,9 +636,12 @@ inline flatbuffers::Offset CreateFieldDirect( bool key = false, const std::vector> *attributes = nullptr, const std::vector> *documentation = nullptr) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; return reflection::CreateField( _fbb, - name ? _fbb.CreateString(name) : 0, + name__, type, id, offset, @@ -639,8 +650,8 @@ inline flatbuffers::Offset CreateFieldDirect( deprecated, required, key, - attributes ? _fbb.CreateVector>(*attributes) : 0, - documentation ? _fbb.CreateVector>(*documentation) : 0); + attributes__, + documentation__); } struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -767,15 +778,19 @@ inline flatbuffers::Offset CreateObjectDirect( int32_t bytesize = 0, const std::vector> *attributes = nullptr, const std::vector> *documentation = nullptr) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto fields__ = fields ? _fbb.CreateVector>(*fields) : 0; + auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; return reflection::CreateObject( _fbb, - name ? _fbb.CreateString(name) : 0, - fields ? _fbb.CreateVector>(*fields) : 0, + name__, + fields__, is_struct, minalign, bytesize, - attributes ? _fbb.CreateVector>(*attributes) : 0, - documentation ? _fbb.CreateVector>(*documentation) : 0); + attributes__, + documentation__); } struct RPCCall FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -881,13 +896,16 @@ inline flatbuffers::Offset CreateRPCCallDirect( flatbuffers::Offset response = 0, const std::vector> *attributes = nullptr, const std::vector> *documentation = nullptr) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; return reflection::CreateRPCCall( _fbb, - name ? _fbb.CreateString(name) : 0, + name__, request, response, - attributes ? _fbb.CreateVector>(*attributes) : 0, - documentation ? _fbb.CreateVector>(*documentation) : 0); + attributes__, + documentation__); } struct Service FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -980,12 +998,16 @@ inline flatbuffers::Offset CreateServiceDirect( const std::vector> *calls = nullptr, const std::vector> *attributes = nullptr, const std::vector> *documentation = nullptr) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto calls__ = calls ? _fbb.CreateVector>(*calls) : 0; + auto attributes__ = attributes ? _fbb.CreateVector>(*attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector>(*documentation) : 0; return reflection::CreateService( _fbb, - name ? _fbb.CreateString(name) : 0, - calls ? _fbb.CreateVector>(*calls) : 0, - attributes ? _fbb.CreateVector>(*attributes) : 0, - documentation ? _fbb.CreateVector>(*documentation) : 0); + name__, + calls__, + attributes__, + documentation__); } struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -1097,14 +1119,19 @@ inline flatbuffers::Offset CreateSchemaDirect( const char *file_ext = nullptr, flatbuffers::Offset root_table = 0, const std::vector> *services = nullptr) { + auto objects__ = objects ? _fbb.CreateVector>(*objects) : 0; + auto enums__ = enums ? _fbb.CreateVector>(*enums) : 0; + auto file_ident__ = file_ident ? _fbb.CreateString(file_ident) : 0; + auto file_ext__ = file_ext ? _fbb.CreateString(file_ext) : 0; + auto services__ = services ? _fbb.CreateVector>(*services) : 0; return reflection::CreateSchema( _fbb, - objects ? _fbb.CreateVector>(*objects) : 0, - enums ? _fbb.CreateVector>(*enums) : 0, - file_ident ? _fbb.CreateString(file_ident) : 0, - file_ext ? _fbb.CreateString(file_ext) : 0, + objects__, + enums__, + file_ident__, + file_ext__, root_table, - services ? _fbb.CreateVector>(*services) : 0); + services__); } inline const reflection::Schema *GetSchema(const void *buf) { diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 153eac666..db79c2e5d 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -408,15 +408,18 @@ inline flatbuffers::Offset CreateMonsterDirect( const std::vector> *weapons = nullptr, Equipment equipped_type = Equipment_NONE, flatbuffers::Offset equipped = 0) { + auto name__ = name ? _fbb.CreateString(name) : 0; + auto inventory__ = inventory ? _fbb.CreateVector(*inventory) : 0; + auto weapons__ = weapons ? _fbb.CreateVector>(*weapons) : 0; return MyGame::Sample::CreateMonster( _fbb, pos, mana, hp, - name ? _fbb.CreateString(name) : 0, - inventory ? _fbb.CreateVector(*inventory) : 0, + name__, + inventory__, color, - weapons ? _fbb.CreateVector>(*weapons) : 0, + weapons__, equipped_type, equipped); } @@ -506,9 +509,10 @@ inline flatbuffers::Offset CreateWeaponDirect( flatbuffers::FlatBufferBuilder &_fbb, const char *name = nullptr, int16_t damage = 0) { + auto name__ = name ? _fbb.CreateString(name) : 0; return MyGame::Sample::CreateWeapon( _fbb, - name ? _fbb.CreateString(name) : 0, + name__, damage); } diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 4c4cd43d3..f91f14e1f 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -2060,36 +2060,30 @@ class CppGenerator : public BaseGenerator { // Generate a CreateXDirect function with vector types as parameters if (has_string_or_vector_fields) { - code_ += - "inline flatbuffers::Offset<{{STRUCT_NAME}}> " - "Create{{STRUCT_NAME}}Direct("; + code_ += "inline flatbuffers::Offset<{{STRUCT_NAME}}> " + "Create{{STRUCT_NAME}}Direct("; code_ += " flatbuffers::FlatBufferBuilder &_fbb\\"; for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { const auto &field = **it; if (!field.deprecated) { GenParam(field, true, ",\n "); } } - // Need to call "Create" with the struct namespace. const auto qualified_create_name = struct_def.defined_namespace->GetFullyQualifiedName("Create"); code_.SetValue("CREATE_NAME", TranslateNameSpace(qualified_create_name)); - code_ += ") {"; - code_ += " return {{CREATE_NAME}}{{STRUCT_NAME}}("; - code_ += " _fbb\\"; for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { const auto &field = **it; if (!field.deprecated) { code_.SetValue("FIELD_NAME", Name(field)); - if (field.value.type.base_type == BASE_TYPE_STRING) { code_ += - ",\n {{FIELD_NAME}} ? " - "_fbb.CreateString({{FIELD_NAME}}) : 0\\"; + " auto {{FIELD_NAME}}__ = {{FIELD_NAME}} ? " + "_fbb.CreateString({{FIELD_NAME}}) : 0;"; } else if (field.value.type.base_type == BASE_TYPE_VECTOR) { - code_ += ",\n {{FIELD_NAME}} ? \\"; + code_ += " auto {{FIELD_NAME}}__ = {{FIELD_NAME}} ? \\"; const auto vtype = field.value.type.VectorType(); if (IsStruct(vtype)) { const auto type = WrapInNameSpace(*vtype.struct_def); @@ -2098,9 +2092,21 @@ class CppGenerator : public BaseGenerator { const auto type = GenTypeWire(vtype, "", false); code_ += "_fbb.CreateVector<" + type + ">\\"; } - code_ += "(*{{FIELD_NAME}}) : 0\\"; - } else { - code_ += ",\n {{FIELD_NAME}}\\"; + code_ += "(*{{FIELD_NAME}}) : 0;"; + } + } + } + code_ += " return {{CREATE_NAME}}{{STRUCT_NAME}}("; + code_ += " _fbb\\"; + for (auto it = struct_def.fields.vec.begin(); + it != struct_def.fields.vec.end(); ++it) { + const auto &field = **it; + if (!field.deprecated) { + code_.SetValue("FIELD_NAME", Name(field)); + code_ += ",\n {{FIELD_NAME}}\\"; + if (field.value.type.base_type == BASE_TYPE_STRING || + field.value.type.base_type == BASE_TYPE_VECTOR) { + code_ += "__\\"; } } } diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 919681235..9e9f77c53 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -2652,14 +2652,15 @@ void Parser::Serialize() { service_offsets.push_back(offset); (*it)->serialized_location = offset.o; } - auto schema_offset = reflection::CreateSchema( - builder_, - builder_.CreateVectorOfSortedTables(&object_offsets), - builder_.CreateVectorOfSortedTables(&enum_offsets), - builder_.CreateString(file_identifier_), - builder_.CreateString(file_extension_), - (root_struct_def_ ? root_struct_def_->serialized_location : 0), - builder_.CreateVectorOfSortedTables(&service_offsets)); + auto objs__ = builder_.CreateVectorOfSortedTables(&object_offsets); + auto enum__ = builder_.CreateVectorOfSortedTables(&enum_offsets); + auto fiid__ = builder_.CreateString(file_identifier_); + auto fext__ = builder_.CreateString(file_extension_); + auto serv__ = builder_.CreateVectorOfSortedTables(&service_offsets); + auto schema_offset = + reflection::CreateSchema(builder_, objs__, enum__, fiid__, fext__, + (root_struct_def_ ? root_struct_def_->serialized_location : 0), + serv__); if (opts.size_prefixed) { builder_.FinishSizePrefixed(schema_offset, reflection::SchemaIdentifier()); } else { @@ -2675,49 +2676,49 @@ Offset StructDef::Serialize(FlatBufferBuilder *builder, builder, static_cast(it - fields.vec.begin()), parser)); } auto qualified_name = defined_namespace->GetFullyQualifiedName(name); - return reflection::CreateObject( - *builder, - builder->CreateString(qualified_name), - builder->CreateVectorOfSortedTables(&field_offsets), - fixed, - static_cast(minalign), - static_cast(bytesize), - SerializeAttributes(builder, parser), - parser.opts.binary_schema_comments - ? builder->CreateVectorOfStrings(doc_comment) - : 0); + auto name__ = builder->CreateString(qualified_name); + auto flds__ = builder->CreateVectorOfSortedTables(&field_offsets); + auto attr__ = SerializeAttributes(builder, parser); + auto docs__ = parser.opts.binary_schema_comments + ? builder->CreateVectorOfStrings(doc_comment) + : 0; + return reflection::CreateObject(*builder, name__, flds__, fixed, + static_cast(minalign), + static_cast(bytesize), + attr__, docs__); } Offset FieldDef::Serialize(FlatBufferBuilder *builder, uint16_t id, const Parser &parser) const { - return reflection::CreateField( - *builder, builder->CreateString(name), value.type.Serialize(builder), id, - value.offset, + auto name__ = builder->CreateString(name); + auto type__ = value.type.Serialize(builder); + auto attr__ = SerializeAttributes(builder, parser); + auto docs__ = parser.opts.binary_schema_comments + ? builder->CreateVectorOfStrings(doc_comment) + : 0; + return reflection::CreateField(*builder, name__, type__, id, value.offset, // Is uint64>max(int64) tested? IsInteger(value.type.base_type) ? StringToInt(value.constant.c_str()) : 0, // result may be platform-dependent if underlying is float (not double) IsFloat(value.type.base_type) ? strtod(value.constant.c_str(), nullptr) : 0.0, - deprecated, required, key, SerializeAttributes(builder, parser), - parser.opts.binary_schema_comments - ? builder->CreateVectorOfStrings(doc_comment) - : 0); + deprecated, required, key, attr__, docs__); // TODO: value.constant is almost always "0", we could save quite a bit of // space by sharing it. Same for common values of value.type. } Offset RPCCall::Serialize(FlatBufferBuilder *builder, const Parser &parser) const { - return reflection::CreateRPCCall( - *builder, - builder->CreateString(name), - request->serialized_location, - response->serialized_location, - SerializeAttributes(builder, parser), - parser.opts.binary_schema_comments - ? builder->CreateVectorOfStrings(doc_comment) - : 0); + auto name__ = builder->CreateString(name); + auto attr__ = SerializeAttributes(builder, parser); + auto docs__ = parser.opts.binary_schema_comments + ? builder->CreateVectorOfStrings(doc_comment) + : 0; + return reflection::CreateRPCCall(*builder, name__, + request->serialized_location, + response->serialized_location, + attr__, docs__); } Offset ServiceDef::Serialize(FlatBufferBuilder *builder, @@ -2727,14 +2728,13 @@ Offset ServiceDef::Serialize(FlatBufferBuilder *builder, servicecall_offsets.push_back((*it)->Serialize(builder, parser)); } auto qualified_name = defined_namespace->GetFullyQualifiedName(name); - return reflection::CreateService( - *builder, - builder->CreateString(qualified_name), - builder->CreateVector(servicecall_offsets), - SerializeAttributes(builder, parser), - parser.opts.binary_schema_comments - ? builder->CreateVectorOfStrings(doc_comment) - : 0); + auto name__ = builder->CreateString(qualified_name); + auto call__ = builder->CreateVector(servicecall_offsets); + auto attr__ = SerializeAttributes(builder, parser); + auto docs__ = parser.opts.binary_schema_comments + ? builder->CreateVectorOfStrings(doc_comment) + : 0; + return reflection::CreateService(*builder, name__, call__, attr__, docs__); } Offset EnumDef::Serialize(FlatBufferBuilder *builder, @@ -2744,29 +2744,27 @@ Offset EnumDef::Serialize(FlatBufferBuilder *builder, enumval_offsets.push_back((*it)->Serialize(builder, parser)); } auto qualified_name = defined_namespace->GetFullyQualifiedName(name); - return reflection::CreateEnum( - *builder, - builder->CreateString(qualified_name), - builder->CreateVector(enumval_offsets), - is_union, - underlying_type.Serialize(builder), - SerializeAttributes(builder, parser), - parser.opts.binary_schema_comments - ? builder->CreateVectorOfStrings(doc_comment) - : 0); + auto name__ = builder->CreateString(qualified_name); + auto vals__ = builder->CreateVector(enumval_offsets); + auto type__ = underlying_type.Serialize(builder); + auto attr__ = SerializeAttributes(builder, parser); + auto docs__ = parser.opts.binary_schema_comments + ? builder->CreateVectorOfStrings(doc_comment) + : 0; + return reflection::CreateEnum(*builder, name__, vals__, is_union, type__, + attr__, docs__); } Offset EnumVal::Serialize(FlatBufferBuilder *builder, const Parser &parser) const { - return reflection::CreateEnumVal( - *builder, - builder->CreateString(name), - value, + auto name__ = builder->CreateString(name); + auto type__ = union_type.Serialize(builder); + auto docs__ = parser.opts.binary_schema_comments + ? builder->CreateVectorOfStrings(doc_comment) + : 0; + return reflection::CreateEnumVal(*builder, name__, value, union_type.struct_def ? union_type.struct_def->serialized_location : 0, - union_type.Serialize(builder), - parser.opts.binary_schema_comments - ? builder->CreateVectorOfStrings(doc_comment) - : 0); + type__, docs__); } Offset Type::Serialize(FlatBufferBuilder *builder) const { @@ -2786,9 +2784,9 @@ Definition::SerializeAttributes(FlatBufferBuilder *builder, auto it = parser.known_attributes_.find(kv->first); FLATBUFFERS_ASSERT(it != parser.known_attributes_.end()); if (parser.opts.binary_schema_builtins || !it->second) { - attrs.push_back(reflection::CreateKeyValue( - *builder, builder->CreateString(kv->first), - builder->CreateString(kv->second->constant))); + auto key = builder->CreateString(kv->first); + auto val = builder->CreateString(kv->second->constant); + attrs.push_back(reflection::CreateKeyValue(*builder, key, val)); } } if (attrs.size()) { diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index c4086e00fbd9a61c5db5490678e1df51f53c67c2..2bfda2195033133bb2b6e3f2d829b366827a9d05 100644 GIT binary patch literal 7280 zcmai(e`sFS8OKlB{CJb5Nvu(0to7P;UDsvVns%iW8EvPvmbOY8GZ8VqNp70gy}37g zf5aw;$QU9rhR7%~WXLE|%8*e+hKPtr*&pH`Qe+JA59!?Ioa;K*sq1|A`JQu6a&zz7 z?ZA_B-gBPc&vTx0&dq=^X5apO$NJ2A(`pK)+w_@!Gr(VC4guc=0-zswsbIh{rUj@0 ztAW`#vU7*;K5~qorVW^4;UfLODq~JV@H~@i`TgAW#>~OvzUz!R5A3?pn4b+8)7{Sa z2Ilx(7=#8ma1(R%(noq})Xm@ZcI5P6Xb@o@0=57*1BVyxEY60*cbq8B&XvRA!*Nut zg_UEqxKcbGvi|!jgQ=Y!EklNn$KN{g|Bc_GbOG|Bud31@Nq&uvh+-3`3rJd((beOlTB$`C*jI2+*=W**D4) z$^8ikUT)f7ESc959-0>%28QvomnWOm0_HUKKI?;{c4vo;dcXb4a#J5}{FC#q_*i}j zdXw=Cpxj&s z;g768JLM<&c^7aikl1{8Z6>T7q1qmsD^7;P`z!J6UD0H@J{6*ysnlz)LJV1at$R0gnP(fb*=qPCrV&3E=qfy882A zbYX6(Oqf-FZ8X+^CEd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h4BgZvd7u@cCc=)B|DexFB_k5pXA1ufa~E`0O2%`H1}js@l(KgbX$lOmBsrk`npX9 z{fGuRF8z3JzIsB6jDf0$ZQjan!Cd1u8bTIzRJzOl6qBxn3YV%PsiMW^^c4 zKf@V4!nSy6@skyab%pPr+uf_%)|HK{o8inZe}xNkdW6(l!)maK2wD=l?j9o%orB=Q z89wl+HpPI-y-19xl%iHnp&!oj;j9wkoE>l6C65WzyJPsNbA7Nc-z+()<>OR#Dcxjy zq-&hTKBBL1&X3R&PJI=V1@@}6tT=b_&yS23=X1laf%+9LjMt_t{rA}#h+>;g-5Qj* zijaMXe461GwPd;^)2_q&vqA$=p6MQ_d#Cgy8jtGvaxpCzEybO5wo_UrU%2boMy@%N=4-^7LZ3`K5u-+gp_(rOHv!$k;r!~1Jfpr5@; zKFDV9L1)Mo9}aNQuyIKD2r`1GocX+Y7gQe_uRNGaYe|)Q)cEl3y@YP-eNfyi@Wa6| zucx$j2W|gsa+vr139o0lFl2hJP3_`NF;O1sd5L@B?n%}wWv6%$XXA*nmG^xtXX8@N_km0|qTY!t!T-T{>Q*E1 z5!&xTWcPjK739Z=Ndt=dD~8 z`2K;{(Gc7)d%tYRH*u-{o4*~0|Fanm|7k<3FUK<6Ag{s+uRO_OaBs5DE?D{*((YF@ zHOey?R{FxK*1BfDF7Ni=I(b()X=jt>8WAuW>!h{09>2#+yO&rse<@WK_3~BY+lHtw z)tWDvpDn+Yng^paH@MJqejRA8zxv+H5%DbFB1HWZ>@Xr;)B+6{qKOX ztIz!8!E$DV2jz?8fBXAjQmgPoF-3hUcE0pu*Ygm*_ CreateStatDirect( const char *id = nullptr, int64_t val = 0, uint16_t count = 0) { + auto id__ = id ? _fbb.CreateString(id) : 0; return MyGame::Example::CreateStat( _fbb, - id ? _fbb.CreateString(id) : 0, + id__, val, count); } @@ -1923,21 +1924,40 @@ inline flatbuffers::Offset CreateMonsterDirect( AnyAmbiguousAliases any_ambiguous_type = AnyAmbiguousAliases_NONE, flatbuffers::Offset any_ambiguous = 0, 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; + auto testarrayofstring__ = testarrayofstring ? _fbb.CreateVector>(*testarrayofstring) : 0; + auto testarrayoftables__ = testarrayoftables ? _fbb.CreateVector>(*testarrayoftables) : 0; + auto testnestedflatbuffer__ = testnestedflatbuffer ? _fbb.CreateVector(*testnestedflatbuffer) : 0; + auto testarrayofbools__ = testarrayofbools ? _fbb.CreateVector(*testarrayofbools) : 0; + auto testarrayofstring2__ = testarrayofstring2 ? _fbb.CreateVector>(*testarrayofstring2) : 0; + auto testarrayofsortedstruct__ = testarrayofsortedstruct ? _fbb.CreateVectorOfStructs(*testarrayofsortedstruct) : 0; + auto flex__ = flex ? _fbb.CreateVector(*flex) : 0; + auto test5__ = test5 ? _fbb.CreateVectorOfStructs(*test5) : 0; + auto vector_of_longs__ = vector_of_longs ? _fbb.CreateVector(*vector_of_longs) : 0; + auto vector_of_doubles__ = vector_of_doubles ? _fbb.CreateVector(*vector_of_doubles) : 0; + auto vector_of_referrables__ = vector_of_referrables ? _fbb.CreateVector>(*vector_of_referrables) : 0; + auto vector_of_weak_references__ = vector_of_weak_references ? _fbb.CreateVector(*vector_of_weak_references) : 0; + 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; return MyGame::Example::CreateMonster( _fbb, pos, mana, hp, - name ? _fbb.CreateString(name) : 0, - inventory ? _fbb.CreateVector(*inventory) : 0, + name__, + inventory__, color, test_type, test, - test4 ? _fbb.CreateVectorOfStructs(*test4) : 0, - testarrayofstring ? _fbb.CreateVector>(*testarrayofstring) : 0, - testarrayoftables ? _fbb.CreateVector>(*testarrayoftables) : 0, + test4__, + testarrayofstring__, + testarrayoftables__, enemy, - testnestedflatbuffer ? _fbb.CreateVector(*testnestedflatbuffer) : 0, + testnestedflatbuffer__, testempty, testbool, testhashs32_fnv1, @@ -1948,30 +1968,30 @@ inline flatbuffers::Offset CreateMonsterDirect( testhashu32_fnv1a, testhashs64_fnv1a, testhashu64_fnv1a, - testarrayofbools ? _fbb.CreateVector(*testarrayofbools) : 0, + testarrayofbools__, testf, testf2, testf3, - testarrayofstring2 ? _fbb.CreateVector>(*testarrayofstring2) : 0, - testarrayofsortedstruct ? _fbb.CreateVectorOfStructs(*testarrayofsortedstruct) : 0, - flex ? _fbb.CreateVector(*flex) : 0, - test5 ? _fbb.CreateVectorOfStructs(*test5) : 0, - vector_of_longs ? _fbb.CreateVector(*vector_of_longs) : 0, - vector_of_doubles ? _fbb.CreateVector(*vector_of_doubles) : 0, + testarrayofstring2__, + testarrayofsortedstruct__, + flex__, + test5__, + vector_of_longs__, + vector_of_doubles__, parent_namespace_test, - vector_of_referrables ? _fbb.CreateVector>(*vector_of_referrables) : 0, + vector_of_referrables__, single_weak_reference, - vector_of_weak_references ? _fbb.CreateVector(*vector_of_weak_references) : 0, - vector_of_strong_referrables ? _fbb.CreateVector>(*vector_of_strong_referrables) : 0, + vector_of_weak_references__, + vector_of_strong_referrables__, co_owning_reference, - vector_of_co_owning_references ? _fbb.CreateVector(*vector_of_co_owning_references) : 0, + vector_of_co_owning_references__, non_owning_reference, - vector_of_non_owning_references ? _fbb.CreateVector(*vector_of_non_owning_references) : 0, + vector_of_non_owning_references__, any_unique_type, any_unique, any_ambiguous_type, any_ambiguous, - vector_of_enums ? _fbb.CreateVector(*vector_of_enums) : 0); + vector_of_enums__); } flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); @@ -2229,6 +2249,8 @@ inline flatbuffers::Offset CreateTypeAliasesDirect( double f64 = 0.0, const std::vector *v8 = nullptr, const std::vector *vf64 = nullptr) { + auto v8__ = v8 ? _fbb.CreateVector(*v8) : 0; + auto vf64__ = vf64 ? _fbb.CreateVector(*vf64) : 0; return MyGame::Example::CreateTypeAliases( _fbb, i8, @@ -2241,8 +2263,8 @@ inline flatbuffers::Offset CreateTypeAliasesDirect( u64, f32, f64, - v8 ? _fbb.CreateVector(*v8) : 0, - vf64 ? _fbb.CreateVector(*vf64) : 0); + v8__, + vf64__); } flatbuffers::Offset CreateTypeAliases(flatbuffers::FlatBufferBuilder &_fbb, const TypeAliasesT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); diff --git a/tests/union_vector/union_vector_generated.h b/tests/union_vector/union_vector_generated.h index 6645ca289..f085bbcb6 100644 --- a/tests/union_vector/union_vector_generated.h +++ b/tests/union_vector/union_vector_generated.h @@ -429,12 +429,14 @@ inline flatbuffers::Offset CreateMovieDirect( flatbuffers::Offset main_character = 0, const std::vector *characters_type = nullptr, const std::vector> *characters = nullptr) { + auto characters_type__ = characters_type ? _fbb.CreateVector(*characters_type) : 0; + auto characters__ = characters ? _fbb.CreateVector>(*characters) : 0; return CreateMovie( _fbb, main_character_type, main_character, - characters_type ? _fbb.CreateVector(*characters_type) : 0, - characters ? _fbb.CreateVector>(*characters) : 0); + characters_type__, + characters__); } flatbuffers::Offset CreateMovie(flatbuffers::FlatBufferBuilder &_fbb, const MovieT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);