mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-02 00:43:57 +00:00
[Rust] Ensure unions are referenced with the correct path (#6422)
* Add codegen test for namespaced unions * [Rust] Handle cross-namespace union use * [Rust] Test namespace handling * [Rust] Drop trailing whitespace in codegen * [Rust] Set flags in generate_code.bat to match .sh * [C#] Add additional namespace test file
This commit is contained in:
@@ -64,6 +64,7 @@ struct TableInFirstNST : public flatbuffers::NativeTable {
|
||||
}
|
||||
flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST> foo_table{};
|
||||
NamespaceA::NamespaceB::EnumInNestedNS foo_enum = NamespaceA::NamespaceB::EnumInNestedNS_A;
|
||||
NamespaceA::NamespaceB::UnionInNestedNSUnion foo_union{};
|
||||
flatbuffers::unique_ptr<NamespaceA::NamespaceB::StructInNestedNS> foo_struct{};
|
||||
};
|
||||
|
||||
@@ -71,6 +72,7 @@ inline bool operator==(const TableInFirstNST &lhs, const TableInFirstNST &rhs) {
|
||||
return
|
||||
(lhs.foo_table == rhs.foo_table) &&
|
||||
(lhs.foo_enum == rhs.foo_enum) &&
|
||||
(lhs.foo_union == rhs.foo_union) &&
|
||||
(lhs.foo_struct == rhs.foo_struct);
|
||||
}
|
||||
|
||||
@@ -91,7 +93,9 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_FOO_TABLE = 4,
|
||||
VT_FOO_ENUM = 6,
|
||||
VT_FOO_STRUCT = 8
|
||||
VT_FOO_UNION_TYPE = 8,
|
||||
VT_FOO_UNION = 10,
|
||||
VT_FOO_STRUCT = 12
|
||||
};
|
||||
const NamespaceA::NamespaceB::TableInNestedNS *foo_table() const {
|
||||
return GetPointer<const NamespaceA::NamespaceB::TableInNestedNS *>(VT_FOO_TABLE);
|
||||
@@ -105,6 +109,19 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_foo_enum(NamespaceA::NamespaceB::EnumInNestedNS _foo_enum) {
|
||||
return SetField<int8_t>(VT_FOO_ENUM, static_cast<int8_t>(_foo_enum), 0);
|
||||
}
|
||||
NamespaceA::NamespaceB::UnionInNestedNS foo_union_type() const {
|
||||
return static_cast<NamespaceA::NamespaceB::UnionInNestedNS>(GetField<uint8_t>(VT_FOO_UNION_TYPE, 0));
|
||||
}
|
||||
const void *foo_union() const {
|
||||
return GetPointer<const void *>(VT_FOO_UNION);
|
||||
}
|
||||
template<typename T> const T *foo_union_as() const;
|
||||
const NamespaceA::NamespaceB::TableInNestedNS *foo_union_as_TableInNestedNS() const {
|
||||
return foo_union_type() == NamespaceA::NamespaceB::UnionInNestedNS_TableInNestedNS ? static_cast<const NamespaceA::NamespaceB::TableInNestedNS *>(foo_union()) : nullptr;
|
||||
}
|
||||
void *mutable_foo_union() {
|
||||
return GetPointer<void *>(VT_FOO_UNION);
|
||||
}
|
||||
const NamespaceA::NamespaceB::StructInNestedNS *foo_struct() const {
|
||||
return GetStruct<const NamespaceA::NamespaceB::StructInNestedNS *>(VT_FOO_STRUCT);
|
||||
}
|
||||
@@ -116,6 +133,9 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
VerifyOffset(verifier, VT_FOO_TABLE) &&
|
||||
verifier.VerifyTable(foo_table()) &&
|
||||
VerifyField<int8_t>(verifier, VT_FOO_ENUM) &&
|
||||
VerifyField<uint8_t>(verifier, VT_FOO_UNION_TYPE) &&
|
||||
VerifyOffset(verifier, VT_FOO_UNION) &&
|
||||
VerifyUnionInNestedNS(verifier, foo_union(), foo_union_type()) &&
|
||||
VerifyField<NamespaceA::NamespaceB::StructInNestedNS>(verifier, VT_FOO_STRUCT) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
@@ -124,6 +144,10 @@ struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
static flatbuffers::Offset<TableInFirstNS> Pack(flatbuffers::FlatBufferBuilder &_fbb, const TableInFirstNST* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
template<> inline const NamespaceA::NamespaceB::TableInNestedNS *TableInFirstNS::foo_union_as<NamespaceA::NamespaceB::TableInNestedNS>() const {
|
||||
return foo_union_as_TableInNestedNS();
|
||||
}
|
||||
|
||||
struct TableInFirstNSBuilder {
|
||||
typedef TableInFirstNS Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
@@ -134,6 +158,12 @@ struct TableInFirstNSBuilder {
|
||||
void add_foo_enum(NamespaceA::NamespaceB::EnumInNestedNS foo_enum) {
|
||||
fbb_.AddElement<int8_t>(TableInFirstNS::VT_FOO_ENUM, static_cast<int8_t>(foo_enum), 0);
|
||||
}
|
||||
void add_foo_union_type(NamespaceA::NamespaceB::UnionInNestedNS foo_union_type) {
|
||||
fbb_.AddElement<uint8_t>(TableInFirstNS::VT_FOO_UNION_TYPE, static_cast<uint8_t>(foo_union_type), 0);
|
||||
}
|
||||
void add_foo_union(flatbuffers::Offset<void> foo_union) {
|
||||
fbb_.AddOffset(TableInFirstNS::VT_FOO_UNION, foo_union);
|
||||
}
|
||||
void add_foo_struct(const NamespaceA::NamespaceB::StructInNestedNS *foo_struct) {
|
||||
fbb_.AddStruct(TableInFirstNS::VT_FOO_STRUCT, foo_struct);
|
||||
}
|
||||
@@ -152,10 +182,14 @@ inline flatbuffers::Offset<TableInFirstNS> CreateTableInFirstNS(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<NamespaceA::NamespaceB::TableInNestedNS> foo_table = 0,
|
||||
NamespaceA::NamespaceB::EnumInNestedNS foo_enum = NamespaceA::NamespaceB::EnumInNestedNS_A,
|
||||
NamespaceA::NamespaceB::UnionInNestedNS foo_union_type = NamespaceA::NamespaceB::UnionInNestedNS_NONE,
|
||||
flatbuffers::Offset<void> foo_union = 0,
|
||||
const NamespaceA::NamespaceB::StructInNestedNS *foo_struct = 0) {
|
||||
TableInFirstNSBuilder builder_(_fbb);
|
||||
builder_.add_foo_struct(foo_struct);
|
||||
builder_.add_foo_union(foo_union);
|
||||
builder_.add_foo_table(foo_table);
|
||||
builder_.add_foo_union_type(foo_union_type);
|
||||
builder_.add_foo_enum(foo_enum);
|
||||
return builder_.Finish();
|
||||
}
|
||||
@@ -347,6 +381,8 @@ inline void TableInFirstNS::UnPackTo(TableInFirstNST *_o, const flatbuffers::res
|
||||
(void)_resolver;
|
||||
{ auto _e = foo_table(); if (_e) _o->foo_table = flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST>(_e->UnPack(_resolver)); }
|
||||
{ auto _e = foo_enum(); _o->foo_enum = _e; }
|
||||
{ auto _e = foo_union_type(); _o->foo_union.type = _e; }
|
||||
{ auto _e = foo_union(); if (_e) _o->foo_union.value = NamespaceA::NamespaceB::UnionInNestedNSUnion::UnPack(_e, foo_union_type(), _resolver); }
|
||||
{ auto _e = foo_struct(); if (_e) _o->foo_struct = flatbuffers::unique_ptr<NamespaceA::NamespaceB::StructInNestedNS>(new NamespaceA::NamespaceB::StructInNestedNS(*_e)); }
|
||||
}
|
||||
|
||||
@@ -360,11 +396,15 @@ inline flatbuffers::Offset<TableInFirstNS> CreateTableInFirstNS(flatbuffers::Fla
|
||||
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const TableInFirstNST* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _foo_table = _o->foo_table ? CreateTableInNestedNS(_fbb, _o->foo_table.get(), _rehasher) : 0;
|
||||
auto _foo_enum = _o->foo_enum;
|
||||
auto _foo_union_type = _o->foo_union.type;
|
||||
auto _foo_union = _o->foo_union.Pack(_fbb);
|
||||
auto _foo_struct = _o->foo_struct ? _o->foo_struct.get() : 0;
|
||||
return NamespaceA::CreateTableInFirstNS(
|
||||
_fbb,
|
||||
_foo_table,
|
||||
_foo_enum,
|
||||
_foo_union_type,
|
||||
_foo_union,
|
||||
_foo_struct);
|
||||
}
|
||||
|
||||
@@ -435,20 +475,25 @@ inline const flatbuffers::TypeTable *TableInFirstNSTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 1 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 2 }
|
||||
{ flatbuffers::ET_UTYPE, 0, 2 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 2 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 3 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
NamespaceA::NamespaceB::TableInNestedNSTypeTable,
|
||||
NamespaceA::NamespaceB::EnumInNestedNSTypeTable,
|
||||
NamespaceA::NamespaceB::UnionInNestedNSTypeTable,
|
||||
NamespaceA::NamespaceB::StructInNestedNSTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"foo_table",
|
||||
"foo_enum",
|
||||
"foo_union_type",
|
||||
"foo_union",
|
||||
"foo_struct"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 3, type_codes, type_refs, nullptr, nullptr, names
|
||||
flatbuffers::ST_TABLE, 5, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user