@@ -51,22 +51,22 @@ const std::string& Wireshark::wiresharkProtocolObjName(const WiresharkGenerator&
5151
5252std::string Wireshark::wiresharkCreateFieldFuncName (const WiresharkGenerator& generator)
5353{
54- return wiresharkProtocolObjName (generator) + " _createField " ;
54+ return wiresharkLocalNamespaceName (generator) + " .createField " ;
5555}
5656
5757std::string Wireshark::wiresharkCreateExtractorFuncName (const WiresharkGenerator& generator)
5858{
59- return wiresharkProtocolObjName (generator) + " _createExtractor " ;
59+ return wiresharkLocalNamespaceName (generator) + " .createExtractor " ;
6060}
6161
6262std::string Wireshark::wiresharkFieldsListName (const WiresharkGenerator& generator)
6363{
64- return wiresharkProtocolObjName (generator) + " _fields_list " ;
64+ return wiresharkLocalNamespaceName (generator) + " .fields_list " ;
6565}
6666
6767std::string Wireshark::wiresharkExtractorsMapName (const WiresharkGenerator& generator)
6868{
69- return wiresharkProtocolObjName (generator) + " _extractors_map " ;
69+ return wiresharkLocalNamespaceName (generator) + " .extractors_map " ;
7070}
7171
7272std::string Wireshark::wiresharkStatusCodeStr (const WiresharkGenerator& generator, WiresharkStatusCode code)
@@ -89,7 +89,12 @@ std::string Wireshark::wiresharkOptModeValsName(const WiresharkGenerator& genera
8989
9090std::string Wireshark::wiresharkFieldValueFuncName (const WiresharkGenerator& generator)
9191{
92- return wiresharkProtocolObjName (generator) + " _field_value" ;
92+ return wiresharkLocalNamespaceName (generator) + " .field_value" ;
93+ }
94+
95+ std::string Wireshark::wiresharkLocalNamespaceName (const WiresharkGenerator& generator)
96+ {
97+ return wiresharkProtocolObjName (generator) + " _local" ;
9398}
9499
95100bool Wireshark::wiresharkWriteInternal () const
@@ -108,6 +113,7 @@ bool Wireshark::wiresharkWriteInternal() const
108113 const std::string Templ =
109114 " #^#GEN_COMMENT#$#\n "
110115 " #^#PROTOCOL#$#\n "
116+ " #^#LOCAL#$#\n "
111117 " #^#STATUS_CODE#$#\n "
112118 " #^#OPT_MODE#$#\n "
113119 " #^#FIELDS_REG#$#\n "
@@ -124,6 +130,7 @@ bool Wireshark::wiresharkWriteInternal() const
124130 util::GenReplacementMap repl = {
125131 {" GEN_COMMENT" , m_wiresharkGenerator.wiresharkFileGeneratedComment ()},
126132 {" PROTOCOL" , wiresharkProtocolDefInternal ()},
133+ {" LOCAL" , wiresharkLocalInternal ()},
127134 {" FIELDS_REG" , wiresharkFieldsRegistrationInternal ()},
128135 {" DISSECT_FUNC" , wiresharkDissectFuncInternal ()},
129136 {" NAME" , wiresharkProtocolObjName (m_wiresharkGenerator)},
@@ -164,6 +171,19 @@ std::string Wireshark::wiresharkProtocolDefInternal() const
164171 return util::genProcessTemplate (Templ, repl);
165172}
166173
174+ std::string Wireshark::wiresharkLocalInternal () const
175+ {
176+ const std::string Templ =
177+ " local #^#NAME#$# = {}\n "
178+ ;
179+
180+ util::GenReplacementMap repl = {
181+ {" NAME" , wiresharkLocalNamespaceName (m_wiresharkGenerator)},
182+ };
183+
184+ return util::genProcessTemplate (Templ, repl);
185+ }
186+
167187std::string Wireshark::wiresharkDissectFuncInternal () const
168188{
169189 const std::string Templ =
@@ -194,10 +214,10 @@ std::string Wireshark::wiresharkFieldsRegistrationInternal() const
194214{
195215 const std::string Templ =
196216 " -- Field Management\n "
197- " local #^#LIST#$# = {}\n "
217+ " #^#LIST#$# = {}\n "
198218 " \n "
199219 " -- Invoke this function every time the field is created\n "
200- " local function #^#NAME#$#(obj)\n "
220+ " function #^#NAME#$#(obj)\n "
201221 " table.insert(#^#LIST#$#, obj)\n "
202222 " return obj\n "
203223 " end\n "
@@ -284,7 +304,7 @@ std::string Wireshark::wiresharkDissectFuncBodyInternal() const
284304
285305std::string Wireshark::wiresharkStatusCodeNameInternal () const
286306{
287- return wiresharkProtocolObjName (m_wiresharkGenerator) + " _StatusCode " ;
307+ return wiresharkLocalNamespaceName (m_wiresharkGenerator) + " .StatusCode " ;
288308}
289309
290310std::string Wireshark::wiresharkStatusCodeDefInternal () const
@@ -296,7 +316,7 @@ std::string Wireshark::wiresharkStatusCodeDefInternal() const
296316 }
297317
298318 const std::string Templ =
299- " local #^#NAME#$# = {\n "
319+ " #^#NAME#$# = {\n "
300320 " #^#VALS#$#\n "
301321 " }\n "
302322 ;
@@ -311,7 +331,7 @@ std::string Wireshark::wiresharkStatusCodeDefInternal() const
311331
312332std::string Wireshark::wiresharkOptModeNameInternal () const
313333{
314- return wiresharkProtocolObjName (m_wiresharkGenerator) + " _OptMode " ;
334+ return wiresharkLocalNamespaceName (m_wiresharkGenerator) + " .OptMode " ;
315335}
316336
317337std::string Wireshark::wiresharkOptionalModeDefInternal () const
@@ -340,11 +360,11 @@ std::string Wireshark::wiresharkOptionalModeDefInternal() const
340360 }
341361
342362 const std::string Templ =
343- " local #^#NAME#$# = {\n "
363+ " #^#NAME#$# = {\n "
344364 " #^#VALS#$#\n "
345365 " }\n "
346366 " \n "
347- " local #^#VALS_NAME#$# = {\n "
367+ " #^#VALS_NAME#$# = {\n "
348368 " #^#VAL_NAMES#$#\n "
349369 " }\n "
350370 ;
@@ -363,10 +383,10 @@ std::string Wireshark::wiresharkExtractorsDeclInternal() const
363383{
364384 const std::string Templ =
365385 " -- Extractors Management\n "
366- " local #^#MAP#$# = {}\n "
386+ " #^#MAP#$# = {}\n "
367387 " \n "
368388 " -- Invoke this function every time the extractor needs to be created\n "
369- " local function #^#NAME#$#(name, field)\n "
389+ " function #^#NAME#$#(name, field)\n "
370390 " #^#MAP#$#[field] = Field.new(name)\n "
371391 " end\n "
372392 ;
@@ -397,7 +417,7 @@ std::string Wireshark::wiresharkExtractorsRegCodeInternal() const
397417std::string Wireshark::wiresharkFieldValueFuncInternal () const
398418{
399419 const std::string Templ =
400- " local function #^#NAME#$#(field)\n "
420+ " function #^#NAME#$#(field)\n "
401421 " local extractor = #^#MAP#$#[field]\n "
402422 " local info = {extractor()}\n "
403423 " local last = info[#info]\n "
0 commit comments