26 lines
824 B
C
Raw Normal View History

2020-01-27 02:21:39 +01:00
#pragma once
#include <cstdint>
namespace ts::protocol {
class generation_estimator {
public:
generation_estimator();
void reset();
2020-03-31 22:01:46 +02:00
[[nodiscard]] uint16_t visit_packet(uint16_t /* packet id */);
[[nodiscard]] uint16_t generation() const;
2020-01-27 02:21:39 +01:00
void set_last_state(uint16_t last_packet, uint16_t generation) {
this->last_packet_id = last_packet;
this->last_generation = generation;
}
private:
constexpr static uint16_t overflow_window{1024};
constexpr static uint16_t overflow_area_begin{0xFFFF - overflow_window};
constexpr static uint16_t overflow_area_end{overflow_window};
uint16_t last_generation{0};
uint16_t last_packet_id{0};
};
}