Skip to content

Commit d3ed486

Browse files
thejtshowJustin Davis
authored andcommitted
fix file load order
fix root type arguments fix union dependency collection start on fixing bit flags now that bfbs-builtins are required.
1 parent 2d8b99b commit d3ed486

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/bfbs_gen_wireshark.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
271271
code += "-- Enum: " + object_names.full_name + "\n";
272272
code += "" + enum_lookup_table_name + " = {\n";
273273

274+
// TODO: we now know if an enum is bit_flags, we need to add new entries
275+
// for each flag if this is set for now, just make sure to add NONE if we
276+
// are a bit_flags enum
277+
if (auto attrs = enum_def->attributes();
278+
attrs && attrs->LookupByKey("bit_flags") != nullptr) {
279+
code += " [0] = \"NONE\",\n";
280+
}
281+
274282
// add each enum value entry
275283
ForAllEnumValues(enum_def, [&](const r::EnumVal *enum_val) {
276284
const std::string name = enum_val->name()->str();
@@ -360,7 +368,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
360368
// write lookup files to disk
361369
for (const auto &file : files) {
362370
const std::string file_name =
363-
options_.output_path + "01_" + file.first + "_lookup.lua";
371+
options_.output_path + "02_" + file.first + "_lookup.lua";
364372
SaveFile(file_name.c_str(), file.second, false);
365373
}
366374

@@ -492,7 +500,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
492500
"the parser, not a TvbRange (or anything else!)\")\n\n";
493501
code += " FB_VERBOSE = verbose and verbose or false\n\n";
494502
code += " local subtree = tree:add(" + proto_name +
495-
", buffer(offset), buffer(offset):raw(), file_name)\n\n";
503+
", buffer(offset))\n\n";
496504

497505
code +=
498506
" offset = offset + Parse_Root_Offset(buffer, offset, "
@@ -534,7 +542,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
534542
// write all files to disk
535543
for (const auto &file : files) {
536544
const std::string file_name =
537-
options_.output_path + "02_" + file.first + ".lua";
545+
options_.output_path + "03_" + file.first + ".lua";
538546
SaveFile(file_name.c_str(), file.second, false);
539547
}
540548

@@ -807,9 +815,10 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
807815
[&](const r::EnumVal *enum_val) {
808816
// for each enum value, get the target object and its
809817
// parser function
810-
int32_t union_type_index = enum_val->value();
818+
int32_t union_type_index =
819+
enum_val->union_type()->index();
811820

812-
if (union_type_index == 0) {
821+
if (union_type_index == -1) {
813822
// skip the NONE entry, as it doesn't have a parser
814823
return;
815824
}
@@ -821,7 +830,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
821830
enum_target_object->name()->str();
822831
to_underscore(enum_target_name_underscore);
823832

824-
code += " [" + NumToString(union_type_index) +
833+
code += " [" + NumToString(enum_val->value()) +
825834
"] = " + "Parse_" +
826835
enum_target_name_underscore + ",\n";
827836
});
@@ -893,14 +902,21 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
893902

894903
for (const auto field : *obj->fields()) {
895904
const auto type = field->type();
896-
if (type->base_type() == r::BaseType::Obj ||
897-
type->base_type() == r::BaseType::Union) {
898-
const auto *dep = schema->objects()->Get(type->index());
899-
collect(dep);
905+
if (type->base_type() == r::BaseType::Obj) {
906+
const auto idx = type->index();
907+
collect(schema->objects()->Get(idx));
900908
} else if (type->base_type() == r::BaseType::Vector &&
901909
type->element() == r::BaseType::Obj) {
902910
const auto *dep = schema->objects()->Get(type->index());
903911
collect(dep);
912+
} else if (type->base_type() == r::BaseType::Union) {
913+
// unions can have multiple types, so we need to collect all of them
914+
ForAllEnumValues(schema->enums()->Get(type->index()),
915+
[&](const r::EnumVal *enum_val) {
916+
const auto idx = enum_val->union_type()->index();
917+
if (idx == -1) { return; }
918+
collect(schema->objects()->Get(idx));
919+
});
904920
}
905921
}
906922
};

0 commit comments

Comments
 (0)