Expand description
32-bit wrap-safe sequence-number arithmetic for SRT ARQ.
SRT data packet sequence numbers occupy the low 31 bits of the header’s
first word (draft-sharabayko-srt-01 §3.1, Figure 3: Packet Sequence Number (31); the top bit is the header F packet-type flag, reused
bit-for-bit as the NAK loss-list range marker, Appendix A) — see the
crate-internal crate::packet::SEQ_NUMBER_MASK.
specs/rules/srt-arq.md does not specify a sequence-number comparison or
arithmetic algorithm for ARQ purposes (it is not one of the curated
rules). This module resolves that gap the standard way for a modular
sequence space — comparable to RFC 1982 serial number arithmetic:
circular over the 31-bit space, picking the shorter of the two
directions between two numbers as “before”/“after”. This is
implementation-defined, not spec-cited, and is needed for the send/
receive buffers to behave correctly once a stream’s sequence numbers
wrap past 0x7FFF_FFFF back to 0.
Functions§
- seq_add
- Add
nto a sequence number, wrapping at the 31-bit boundary. - seq_
diff - Signed circular distance
a - bin the 31-bit sequence space, in(-SEQ_HALF, SEQ_HALF]. Positive meansais ahead ofb. - seq_geq
afollows or equalsb.- seq_gt
afollowsbin circular sequence order.- seq_leq
aprecedes or equalsb.- seq_lt
aprecedesbin circular sequence order.- seq_
next - The next sequence number after
seq(wraps0x7FFF_FFFF->0).