24#include <SDL3/SDL_stdinc.h>
69 const uint8_t fragIdx =
static_cast<uint8_t
>(hdr.
fragmentInfo >> 8);
70 const uint8_t fragCount =
static_cast<uint8_t
>(hdr.
fragmentInfo & 0xFF);
72 if (fragCount == 0 || fragIdx >= fragCount)
106 active_->fragmentCount = fragCount;
107 active_->received.assign(fragCount, std::vector<uint8_t>{});
115 if (
active_->fragmentCount != fragCount) {
118 active_->fragmentCount = fragCount;
119 active_->received.assign(fragCount, std::vector<uint8_t>{});
123 auto& slot =
active_->received[fragIdx];
127 slot.assign(payload, payload + payloadLen);
135 for (
const auto& s :
active_->received)
138 assembled.reserve(total);
139 for (
const auto& s :
active_->received)
140 assembled.insert(assembled.end(), s.begin(), s.end());
155 constexpr uint16_t k_half = 32768u;
156 return ((s1 > s2) && (s1 - s2 > k_half)) || ((s2 > s1) && (s2 - s1 < k_half));
185 explicit operator bool() const noexcept {
return hasValue; }
Definition FragmentReassembler.hpp:33
void reset() noexcept
Drop any in-progress reassembly.
Definition FragmentReassembler.hpp:148
OptionalSet active_
Definition FragmentReassembler.hpp:187
static constexpr int k_maxFragments
Maximum fragments per logical message — matches the 8-bit fragment-count field in the wire header.
Definition FragmentReassembler.hpp:37
Result addFragment(const PacketHeader &hdr, const uint8_t *payload, int payloadLen, std::vector< uint8_t > &assembled)
Feed one received fragment into the reassembler.
Definition FragmentReassembler.hpp:67
Result
Result of addFragment.
Definition FragmentReassembler.hpp:41
@ Malformed
Header was malformed (bad fragment index/count).
Definition FragmentReassembler.hpp:52
@ InProgress
Fragment accepted into in-progress set, but more fragments are still needed before the message is com...
Definition FragmentReassembler.hpp:44
@ Complete
Fragment was the final missing piece — assembled is populated with the full logical message.
Definition FragmentReassembler.hpp:47
@ Stale
Fragment was older than the in-progress set and got dropped (drop-stale semantics).
Definition FragmentReassembler.hpp:50
static bool seqMoreRecent(uint16_t s1, uint16_t s2) noexcept
Glenn-Fiedler "is s2 more recent than s1?" with 16-bit wrap.
Definition FragmentReassembler.hpp:153
Definition ShotDebugReport.hpp:56
Definition FragmentReassembler.hpp:160
uint8_t fragmentCount
Definition FragmentReassembler.hpp:162
std::vector< std::vector< uint8_t > > received
Definition FragmentReassembler.hpp:164
uint8_t haveCount
Definition FragmentReassembler.hpp:163
uint16_t sequence
Definition FragmentReassembler.hpp:161
Definition FragmentReassembler.hpp:170
void reset() noexcept
Definition FragmentReassembler.hpp:180
bool hasValue
Definition FragmentReassembler.hpp:171
const ActiveSet * operator->() const
Definition FragmentReassembler.hpp:182
ActiveSet * operator->()
Definition FragmentReassembler.hpp:181
const ActiveSet & operator*() const
Definition FragmentReassembler.hpp:184
OptionalSet & emplace()
Definition FragmentReassembler.hpp:174
ActiveSet & operator*()
Definition FragmentReassembler.hpp:183
ActiveSet value
Definition FragmentReassembler.hpp:172