-
Notifications
You must be signed in to change notification settings - Fork 734
Add constructFromFactory API to accommodate parsing layers from custom functions.
#2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| else if (SipLayer::isSipPort(portDst) || SipLayer::isSipPort(portSrc)) | ||
| { | ||
| setNextLayer(SipLayer::parseSipLayer(udpData, udpDataLen, this, getAttachedPacket(), portSrc, portDst)); | ||
| if (!hasNextLayer()) | ||
| { | ||
| constructNextLayer<PayloadLayer>(udpData, udpDataLen, getAttachedPacket()); | ||
| } | ||
| // Resolves the overload of parseSipLayer, without static_casting a function pointer. | ||
| auto* (*fac)(uint8_t*, size_t, Layer*, Packet*, uint16_t, uint16_t) = SipLayer::parseSipLayer; | ||
| tryConstructNextLayerFromFactoryWithFallback<PayloadLayer>(fac, udpData, udpDataLen, portSrc, portDst); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit ugly, but it is the most readable way I could figure out to disambiguate the overloads of SipLayer::parseSipLayer.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #2052 +/- ##
==========================================
- Coverage 83.89% 83.83% -0.06%
==========================================
Files 312 312
Lines 55550 55630 +80
Branches 11513 11839 +326
==========================================
+ Hits 46603 46638 +35
- Misses 7769 8333 +564
+ Partials 1178 659 -519
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The PR expands the Layer construct API with two new additions:
constructNextLayerFromFactorytryConstructNextLayerFromFactoryWithFallbackThe new API mimics previous behaviour of
construct***andtryConstruct***functions, but allows usages of custom functors to parse the layer.The new API is intended to replace usages such as:
with
constructNextLayerFromFactory(BgpLayer::parseBgpLayer, payload, payloadLen);The change both reduces the boilerplate of automatically deducing
thisandgetAttachedPacket(), and also including the standardized check for already existing next layer protecting against overwrites.