pub struct SubscribeIdAllocator {
next_id: u64,
max_id: u64,
}Expand description
Allocates the Subscribe IDs this endpoint sends.
Section 7.4 defines the field: “Subscribe ID is a variable length integer that MUST be unique and monotonically increasing within a session and MUST be less than the session’s Maximum Subscribe ID.” SUBSCRIBE and FETCH draw from the same sequence, so one allocator serves both.
This draft states no parity rule - the client’s and the server’s ids are not separated by their least significant bit, as they are from draft-11 on - so the sequence simply starts at 0 and steps by one.
The ceiling is exclusive. Section 7.20 gives the Maximum Subscribe ID a starting value of 0 and reads that as “the peer MUST NOT create subscriptions”, which holds only if a ceiling of 0 forbids the id 0 as well.
The ceiling here is the one the peer granted this endpoint. The ceiling a peer’s ids are measured against is the one this endpoint advertised, which is a different number and lives on the endpoint rather than here.
Fields§
§next_id: u64§max_id: u64Implementations§
Source§impl SubscribeIdAllocator
impl SubscribeIdAllocator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an allocator starting at subscribe ID 0, blocked until a peer raises the maximum.
Sourcepub fn allocate(&mut self) -> Result<VarInt, SubscribeIdError>
pub fn allocate(&mut self) -> Result<VarInt, SubscribeIdError>
Allocate the next Subscribe ID.
§Errors
SubscribeIdError::Blocked if the next id would reach the ceiling.
Sourcepub fn update_max(&mut self, new_max: u64) -> Result<(), SubscribeIdError>
pub fn update_max(&mut self, new_max: u64) -> Result<(), SubscribeIdError>
Raise the maximum Subscribe ID this endpoint may use.
Section 7.20: “The Maximum Subscribe ID MUST only increase within a session, and receipt of a MAX_SUBSCRIBE_ID message with an equal or smaller Subscribe ID value is a ‘Protocol Violation’.”
§Errors
SubscribeIdError::Decreased if the value does not strictly increase.
Sourcepub fn is_blocked(&self) -> bool
pub fn is_blocked(&self) -> bool
Whether the next allocation would reach the ceiling.