17static constexpr uint32_t UNTRUSTED_SESSION_FINGERPRINT = 0;
21 return session_present && trusted != UNTRUSTED_SESSION_FINGERPRINT && trusted == current;
25static constexpr uint8_t SUBACK_FAILURE = 0x80;
28constexpr bool subscribe_granted(uint8_t return_code) {
return return_code < SUBACK_FAILURE; }
41 this->
received_.store(0, std::memory_order_relaxed);
42 this->
granted_.store(0, std::memory_order_relaxed);
44 void add(uint8_t return_code) {
46 this->
granted_.store(this->
granted_.load(std::memory_order_relaxed) + 1, std::memory_order_relaxed);
48 this->
received_.store(this->
received_.load(std::memory_order_relaxed) + 1, std::memory_order_release);
57 return received == sent && this->
granted_.load(std::memory_order_relaxed) == sent
68static constexpr size_t INBOUND_SLOTS_PER_SUBSCRIBE = 2;
70static constexpr size_t INBOUND_SLOTS_PER_SUBSCRIBE_WITH_ACK = INBOUND_SLOTS_PER_SUBSCRIBE + 1;
73constexpr bool subscribe_fits(uint16_t sent, uint16_t answered,
size_t free_slots,
74 size_t slots_per_subscribe = INBOUND_SLOTS_PER_SUBSCRIBE) {
75 const auto diff =
static_cast<int16_t
>(sent - answered);
76 const size_t unanswered = diff > 0 ? diff : 0;
77 return (unanswered + 1) * slots_per_subscribe <= free_slots;
81constexpr uint16_t
rebase_sent(uint16_t sent, uint16_t answered) {
82 return static_cast<int16_t
>(answered - sent) > 0 ? answered : sent;
SUBACKs received on the current connection.
std::atomic< uint16_t > received_
void add(uint8_t return_code)
SubackTally tally(uint16_t sent) const
Compares the SUBACKs received with the number of SUBSCRIBEs sent on this connection.
std::atomic< uint16_t > granted_
uint16_t received() const
@ SUBACK_TALLY_NOT_ALL_GRANTED
@ SUBACK_TALLY_ALL_GRANTED
constexpr uint16_t rebase_sent(uint16_t sent, uint16_t answered)
The sent count raised to the SUBACKs counted, so stray SUBACKs give no credit; wrap safe.
uint32_t add_subscription_fingerprint(uint32_t fingerprint, const char *topic, uint8_t qos)
Adds one subscription to a fingerprint of a set of subscriptions; the order they are added in does no...
constexpr bool session_has_subscriptions(bool session_present, uint32_t trusted, uint32_t current)
True when a resumed session holds in full the subscriptions it is trusted with, and they are the curr...
constexpr bool subscribe_granted(uint8_t return_code)
True when a SUBACK return code grants the subscription.
constexpr bool subscribe_fits(uint16_t sent, uint16_t answered, size_t free_slots, size_t slots_per_subscribe=INBOUND_SLOTS_PER_SUBSCRIBE)
Whether one more SUBSCRIBE fits; wrap safe.
constexpr uint32_t fnv1a_hash_extend(uint32_t hash, const char *str)
Extend a FNV-1a hash with additional string data.
constexpr uint32_t fnv1a_hash(const char *str)
Calculate a FNV-1a hash of str.