Skip to content

Commit fa0b73a

Browse files
committed
Field creation functionality for <bundle> in commsdsl2wireshark.
1 parent 898c199 commit fa0b73a

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

app/commsdsl2wireshark/src/WiresharkBitfieldField.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ bool WiresharkBitfieldField::genPrepareImpl()
116116
}
117117

118118
m_wiresharkFields = wiresharkTransformFieldsList(genMembers());
119-
// TODO: force mask
120119
return true;
121120
}
122121

app/commsdsl2wireshark/src/WiresharkBitfieldField.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class WiresharkBitfieldField final : public commsdsl::gen::GenBitfieldField, pub
4040

4141
protected:
4242
virtual bool genPrepareImpl() override;
43+
4344
virtual std::string wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const override;
4445
virtual std::string wiresharkMembersDissectCodeImpl() const override;
4546

app/commsdsl2wireshark/src/WiresharkBundleField.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
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+
2027
namespace 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

app/commsdsl2wireshark/src/WiresharkBundleField.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ class WiresharkBundleField final : public commsdsl::gen::GenBundleField, public
3333
using GenElem = commsdsl::gen::GenElem;
3434

3535
WiresharkBundleField(WiresharkGenerator& generator, ParseField parseObj, GenElem* parent);
36+
37+
protected:
38+
virtual bool genPrepareImpl() override;
39+
40+
virtual std::string wiresharkFieldRegistrationImpl(const std::string& objName, const std::string& refName) const override;
41+
virtual std::string wiresharkMembersDissectCodeImpl() const override;
42+
43+
private:
44+
WiresharkFieldsList m_wiresharkFields;
3645
};
3746

3847
} // namespace commsdsl2wireshark

0 commit comments

Comments
 (0)