Skip to content

Conversation

@Dimi1010
Copy link
Collaborator

The PR expands the Layer construct API with two new additions:

  • constructNextLayerFromFactory
  • tryConstructNextLayerFromFactoryWithFallback

The new API mimics previous behaviour of construct*** and tryConstruct*** functions, but allows usages of custom functors to parse the layer.

The new API is intended to replace usages such as:

setNextLayer(BgpLayer::parseBgpLayer(payload, payloadLen, this, getAttachedPacket()));

with

constructNextLayerFromFactory(BgpLayer::parseBgpLayer, payload, payloadLen);

The change both reduces the boilerplate of automatically deducing this and getAttachedPacket(), and also including the standardized check for already existing next layer protecting against overwrites.

Comment on lines 117 to 122
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);
}
Copy link
Collaborator Author

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
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.83%. Comparing base (e435a1a) to head (06301a1).
⚠️ Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
Packet++/header/Layer.h 96.15% 1 Missing ⚠️
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     
Flag Coverage Δ
alpine320 76.50% <90.32%> (+0.02%) ⬆️
fedora42 76.23% <93.54%> (+<0.01%) ⬆️
macos-14 81.99% <92.30%> (+0.01%) ⬆️
macos-15 81.99% <92.30%> (+0.01%) ⬆️
mingw32 70.48% <93.54%> (?)
mingw64 70.47% <93.54%> (?)
npcap ?
rhel94 75.86% <90.32%> (+0.02%) ⬆️
ubuntu2004 59.72% <89.65%> (+0.02%) ⬆️
ubuntu2004-zstd 59.82% <89.65%> (+<0.01%) ⬆️
ubuntu2204 75.80% <90.32%> (+0.02%) ⬆️
ubuntu2204-icpx 59.12% <92.30%> (+0.07%) ⬆️
ubuntu2404 76.19% <90.32%> (+0.03%) ⬆️
ubuntu2404-arm64 76.18% <90.32%> (+0.04%) ⬆️
unittest 83.83% <97.91%> (-0.06%) ⬇️
windows-2022 85.65% <97.43%> (+0.13%) ⬆️
windows-2025 85.68% <97.43%> (+0.14%) ⬆️
winpcap 85.68% <97.43%> (-0.07%) ⬇️
xdp 51.98% <90.32%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010 Dimi1010 marked this pull request as ready for review January 26, 2026 08:27
@Dimi1010 Dimi1010 requested a review from seladb as a code owner January 26, 2026 08:27
@Dimi1010 Dimi1010 merged commit bdec00b into seladb:dev Jan 26, 2026
107 of 113 checks passed
@Dimi1010 Dimi1010 deleted the refactor/construct-api-p4 branch January 26, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants