pub struct SequenceManager { /* private fields */ }Expand description
Manages sequence numbers for a FIX session.
Uses atomic operations for thread-safe access without locks.
Implementations§
Source§impl SequenceManager
impl SequenceManager
Sourcepub const fn with_initial(
sender_seq: NonZeroU64,
target_seq: NonZeroU64,
) -> Self
pub const fn with_initial( sender_seq: NonZeroU64, target_seq: NonZeroU64, ) -> Self
Creates a new sequence manager seeded with the given starting values.
Both counters are NonZeroU64: FIX numbers messages from 1, and a
MsgSeqNum (34) of 0 is rejected by every conforming counterparty.
Taking NonZeroU64 makes a zero seed unrepresentable at the type
level, so a 34=0 can never be seeded onto the wire — the invalid
state is refused at the call site rather than caught at runtime.
§Arguments
sender_seq- Next outgoing sequence number,>= 1target_seq- Next expected incoming sequence number,>= 1
Sourcepub fn next_sender_seq(&self) -> SeqNum
pub fn next_sender_seq(&self) -> SeqNum
Returns the next sender sequence number without incrementing.
Sourcepub fn next_target_seq(&self) -> SeqNum
pub fn next_target_seq(&self) -> SeqNum
Returns the next target sequence number without incrementing.
Sourcepub fn allocate_sender_seq(&self) -> SeqNum
👎Deprecated since 0.4.0: wraps silently on overflow, which corrupts a live session; use try_allocate_sender_seq. Removed in the next breaking release.
pub fn allocate_sender_seq(&self) -> SeqNum
wraps silently on overflow, which corrupts a live session; use try_allocate_sender_seq. Removed in the next breaking release.
Allocates and returns the next sender sequence number.
This atomically increments the sequence number and returns the value before the increment.
Note: wraps silently on u64 overflow. Prefer
try_allocate_sender_seq for
venue-grade sessions where exhaustion must be an explicit error.
Sourcepub fn try_allocate_sender_seq(&self) -> Result<SeqNum, SequenceExhausted>
pub fn try_allocate_sender_seq(&self) -> Result<SeqNum, SequenceExhausted>
Allocates and returns the next sender sequence number, failing instead of wrapping when the counter is exhausted.
On success this atomically increments the counter and returns the
value before the increment. On exhaustion the counter is left
untouched; the session must perform a sequence reset (see
SequenceExhausted) before more numbers can be allocated.
§Errors
Returns SequenceExhausted if the counter has reached u64::MAX.
Sourcepub fn increment_target_seq(&self)
👎Deprecated since 0.4.0: wraps silently on overflow, which corrupts a live session; use try_increment_target_seq. Removed in the next breaking release.
pub fn increment_target_seq(&self)
wraps silently on overflow, which corrupts a live session; use try_increment_target_seq. Removed in the next breaking release.
Increments the target sequence number.
Call this after successfully processing an incoming message.
Note: wraps silently on u64 overflow. Prefer
try_increment_target_seq for
venue-grade sessions where exhaustion must be an explicit error.
Sourcepub fn try_increment_target_seq(&self) -> Result<SeqNum, SequenceExhausted>
pub fn try_increment_target_seq(&self) -> Result<SeqNum, SequenceExhausted>
Increments the target sequence number, failing instead of wrapping when the counter is exhausted.
On success returns the new next expected target sequence number.
On exhaustion the counter is left untouched; the session must
perform a sequence reset (see SequenceExhausted) before more
messages can be accepted.
§Errors
Returns SequenceExhausted if the counter has reached u64::MAX.
Sourcepub fn set_sender_seq(&self, seq: u64)
pub fn set_sender_seq(&self, seq: u64)
Sets the next sender sequence number.
§Arguments
seq- The new sequence number,>= 1(seeSequenceManager::with_initialfor the contract)
Sourcepub fn set_target_seq(&self, seq: u64)
pub fn set_target_seq(&self, seq: u64)
Sets the next target sequence number.
§Arguments
seq- The new sequence number,>= 1(seeSequenceManager::with_initialfor the contract)
Sourcepub fn validate_incoming(&self, received: u64) -> SequenceResult
pub fn validate_incoming(&self, received: u64) -> SequenceResult
Validates an incoming MsgSeqNum (34) against the next expected
target sequence number.
This only classifies; it moves no counter. Acting on the answer —
a ResendRequest for a gap, a PossDupFlag check for a duplicate — is
the engine’s job.
§Arguments
received- The received sequence number
§Returns
SequenceResult::Okwhen it is exactly the expected numberSequenceResult::TooLowwhen it is lower (a possible duplicate)SequenceResult::Gapwhen it is higher (messages were missed)