@@ -703,6 +703,44 @@ std::string WiresharkField::wiresharkDissectCodeImpl(const WiresharkField* refFi
703703 return util::genProcessTemplate (Templ, repl);
704704}
705705
706+ std::string WiresharkField::wiresharkValidCheckCodeImpl (const WiresharkField* refField) const
707+ {
708+ static const std::string Templ =
709+ " local valid, print_warn = #^#VALID_FUNC#$#(#^#FIELD#$#)\n "
710+ " if not valid then\n "
711+ " #^#CODE#$#\n "
712+ " end\n "
713+ ;
714+
715+ auto & wiresharkGenerator = WiresharkGenerator::wiresharkCast (m_genField.genGenerator ());
716+ util::GenReplacementMap repl = {
717+ {" VALID_FUNC" , wiresharkValidFuncName (refField)},
718+ {" SUBTREE" , wiresharkFieldSubtreeStr ()},
719+ {" FIELD" , wiresharkFieldStr ()},
720+ {" ERROR" , Wireshark::wiresharkStatusCodeStr (wiresharkGenerator, Wireshark::WiresharkStatusCode::InvalidMsgData)},
721+ {" OFFSET" , wiresharkOffsetStr ()},
722+ };
723+
724+ if (m_genField.genParseObj ().parseIsFailOnInvalid ()) {
725+ static const std::string FailTempl =
726+ " #^#SUBTREE#$#:set_hidden(true)\n "
727+ " return #^#ERROR#$#, #^#OFFSET#$#\n "
728+ ;
729+
730+ repl[" CODE" ] = util::genProcessTemplate (FailTempl, repl);
731+ }
732+ else {
733+ static const std::string FailTempl =
734+ " if print_warn then\n "
735+ " #^#SUBTREE#$#:add_expert_info(PI_PROTOCOL, PI_WARN, \" Invalid field value\" )\n "
736+ " end"
737+ ;
738+ repl[" CODE" ] = util::genProcessTemplate (FailTempl, repl);
739+ }
740+
741+ return util::genProcessTemplate (Templ, repl);
742+ }
743+
706744std::string WiresharkField::wiresharkExtractorsRegCodeImpl (const WiresharkField* refField) const
707745{
708746 static const std::string Templ =
@@ -1265,37 +1303,7 @@ std::string WiresharkField::wiresharkDissectValidCheckInternal(const WiresharkFi
12651303 return strings::genEmptyString ();
12661304 }
12671305
1268- static const std::string Templ =
1269- " local valid, print_warn = #^#VALID_FUNC#$#(#^#FIELD#$#)\n "
1270- " if not valid then\n "
1271- " #^#CODE#$#\n "
1272- " end\n "
1273- ;
1274-
1275- util::GenReplacementMap repl = {
1276- {" VALID_FUNC" , wiresharkValidFuncName (refField)},
1277- {" SUBTREE" , wiresharkFieldSubtreeStr ()},
1278- {" FIELD" , wiresharkFieldStr ()}
1279- };
1280-
1281- if (m_genField.genParseObj ().parseIsFailOnInvalid ()) {
1282- static const std::string FailTempl =
1283- " #^#SUBTREE#$#:set_hidden(true)\n "
1284- " return result, offset"
1285- ;
1286-
1287- repl[" CODE" ] = util::genProcessTemplate (FailTempl, repl);
1288- }
1289- else {
1290- static const std::string FailTempl =
1291- " if print_warn then\n "
1292- " #^#SUBTREE#$#:add_expert_info(PI_PROTOCOL, PI_WARN, \" Invalid field value\" )\n "
1293- " end"
1294- ;
1295- repl[" CODE" ] = util::genProcessTemplate (FailTempl, repl);
1296- }
1297-
1298- return util::genProcessTemplate (Templ, repl);
1306+ return wiresharkValidCheckCodeImpl (refField);
12991307}
13001308
13011309std::string WiresharkField::wiresharkValidFuncCodeInternal (const WiresharkField* refField) const
0 commit comments