1515
1616#include " WiresharkBundleField.h"
1717
18+ #include " Wireshark.h"
1819#include " WiresharkGenerator.h"
1920
21+ #include " commsdsl/gen/util.h"
22+ #include " commsdsl/gen/strings.h"
23+
24+ namespace strings = commsdsl::gen::strings;
25+ namespace util = commsdsl::gen::util;
26+
2027namespace commsdsl2wireshark
2128{
2229
@@ -26,4 +33,56 @@ WiresharkBundleField::WiresharkBundleField(WiresharkGenerator& generator, ParseF
2633{
2734}
2835
36+ bool WiresharkBundleField::genPrepareImpl ()
37+ {
38+ if (!GenBase::genPrepareImpl ()) {
39+ return false ;
40+ }
41+
42+ m_wiresharkFields = wiresharkTransformFieldsList (genMembers ());
43+ return true ;
44+ }
45+
46+ std::string WiresharkBundleField::wiresharkFieldRegistrationImpl (const std::string& objName, const std::string& refName) const
47+ {
48+ static const std::string Templ =
49+ " local #^#OBJ_NAME#$# = #^#CREATE_FUNC#$#(ProtoField.bytes(\" #^#REF_NAME#$#\" , \" #^#DISP_NAME#$#\" , base.SPACE, #^#DESC#$#))\n "
50+ ;
51+
52+ auto mask = wiresharkForcedIntegralFieldMask ();
53+ auto obj = genParseObj ();
54+ util::GenReplacementMap repl = {
55+ {" OBJ_NAME" , objName},
56+ {" CREATE_FUNC" , Wireshark::wiresharkCreateFieldFuncName (WiresharkGenerator::wiresharkCast (genGenerator ()))},
57+ {" REF_NAME" , refName},
58+ {" DISP_NAME" , util::genDisplayName (obj.parseDisplayName (), obj.parseName ())},
59+ {" DESC" , wiresharkFieldDescriptionStr ()},
60+ };
61+
62+ if (repl[" OBJ_NAME" ].empty ()) {
63+ repl[" OBJ_NAME" ] = wiresharkFieldObjName ();
64+ }
65+
66+ if (repl[" REF_NAME" ].empty ()) {
67+ repl[" REF_NAME" ] = wiresharkFieldRefName ();
68+ }
69+
70+ return util::genProcessTemplate (Templ, repl);
71+ }
72+
73+ std::string WiresharkBundleField::wiresharkMembersDissectCodeImpl () const
74+ {
75+ util::GenStringsList elems;
76+ for (auto * f : m_wiresharkFields) {
77+ auto str = f->wiresharkDissectCode ();
78+ if (str.empty ()) {
79+ continue ;
80+ }
81+
82+ elems.push_back (std::move (str));
83+ }
84+
85+ return util::genStrListToString (elems, " \n " , " \n " );
86+ }
87+
2988} // namespace commsdsl2wireshark
0 commit comments