Skip to main content

Module seq

Module seq 

Source
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 n to a sequence number, wrapping at the 31-bit boundary.
seq_diff
Signed circular distance a - b in the 31-bit sequence space, in (-SEQ_HALF, SEQ_HALF]. Positive means a is ahead of b.
seq_geq
a follows or equals b.
seq_gt
a follows b in circular sequence order.
seq_leq
a precedes or equals b.
seq_lt
a precedes b in circular sequence order.
seq_next
The next sequence number after seq (wraps 0x7FFF_FFFF -> 0).