@@ -271,6 +271,14 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
271
271
code += " -- Enum: " + object_names.full_name + " \n " ;
272
272
code += " " + enum_lookup_table_name + " = {\n " ;
273
273
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
+
274
282
// add each enum value entry
275
283
ForAllEnumValues (enum_def, [&](const r::EnumVal *enum_val) {
276
284
const std::string name = enum_val->name ()->str ();
@@ -360,7 +368,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
360
368
// write lookup files to disk
361
369
for (const auto &file : files) {
362
370
const std::string file_name =
363
- options_.output_path + " 01_ " + file.first + " _lookup.lua" ;
371
+ options_.output_path + " 02_ " + file.first + " _lookup.lua" ;
364
372
SaveFile (file_name.c_str (), file.second , false );
365
373
}
366
374
@@ -492,7 +500,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
492
500
" the parser, not a TvbRange (or anything else!)\" )\n\n " ;
493
501
code += " FB_VERBOSE = verbose and verbose or false\n\n " ;
494
502
code += " local subtree = tree:add(" + proto_name +
495
- " , buffer(offset), buffer(offset):raw(), file_name )\n\n " ;
503
+ " , buffer(offset))\n\n " ;
496
504
497
505
code +=
498
506
" offset = offset + Parse_Root_Offset(buffer, offset, "
@@ -534,7 +542,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
534
542
// write all files to disk
535
543
for (const auto &file : files) {
536
544
const std::string file_name =
537
- options_.output_path + " 02_ " + file.first + " .lua" ;
545
+ options_.output_path + " 03_ " + file.first + " .lua" ;
538
546
SaveFile (file_name.c_str (), file.second , false );
539
547
}
540
548
@@ -807,9 +815,10 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
807
815
[&](const r::EnumVal *enum_val) {
808
816
// for each enum value, get the target object and its
809
817
// parser function
810
- int32_t union_type_index = enum_val->value ();
818
+ int32_t union_type_index =
819
+ enum_val->union_type ()->index ();
811
820
812
- if (union_type_index == 0 ) {
821
+ if (union_type_index == - 1 ) {
813
822
// skip the NONE entry, as it doesn't have a parser
814
823
return ;
815
824
}
@@ -821,7 +830,7 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
821
830
enum_target_object->name ()->str ();
822
831
to_underscore (enum_target_name_underscore);
823
832
824
- code += " [" + NumToString (union_type_index ) +
833
+ code += " [" + NumToString (enum_val-> value () ) +
825
834
" ] = " + " Parse_" +
826
835
enum_target_name_underscore + " ,\n " ;
827
836
});
@@ -893,14 +902,21 @@ class WiresharkBfbsGenerator : public BaseBfbsGenerator {
893
902
894
903
for (const auto field : *obj->fields ()) {
895
904
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));
900
908
} else if (type->base_type () == r::BaseType::Vector &&
901
909
type->element () == r::BaseType::Obj) {
902
910
const auto *dep = schema->objects ()->Get (type->index ());
903
911
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
+ });
904
920
}
905
921
}
906
922
};
0 commit comments