2021-03-17 14:49:07 +01:00
|
|
|
#ifndef SEQUENCENUMBER_H
|
|
|
|
#define SEQUENCENUMBER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-05-25 20:22:19 +02:00
|
|
|
#include <stdbool.h>
|
2021-03-17 14:49:07 +01:00
|
|
|
|
2021-05-03 21:47:02 +02:00
|
|
|
typedef uint32_t record_sequence_number_t;
|
2021-03-23 18:11:11 +01:00
|
|
|
|
2021-03-17 14:49:07 +01:00
|
|
|
/**
|
|
|
|
* Compare to sequence numbers for equality.
|
2021-04-26 15:56:00 +02:00
|
|
|
*
|
2021-03-17 14:49:07 +01:00
|
|
|
* @param a first sequence number
|
|
|
|
* @param b second sequence number
|
|
|
|
* @return 1, if sequence numbers are equal, 0 otherwise.
|
|
|
|
*/
|
2021-05-25 20:22:19 +02:00
|
|
|
bool sn_equal(record_sequence_number_t a, record_sequence_number_t b);
|
2021-03-17 14:49:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment the given sequence number. Wraps around, if 2^24 is reached.
|
|
|
|
*
|
|
|
|
* @param sn sequence number to increment
|
2021-05-14 00:31:14 +02:00
|
|
|
* @return the incremented sequence number
|
2021-03-17 14:49:07 +01:00
|
|
|
*/
|
2021-03-24 15:52:02 +01:00
|
|
|
record_sequence_number_t sn_increment(record_sequence_number_t sn);
|
2021-05-14 00:31:14 +02:00
|
|
|
|
2021-05-25 20:22:19 +02:00
|
|
|
/**
|
|
|
|
* Decrement the given sequence number. Wraps around, if 0 is reached.
|
|
|
|
*
|
|
|
|
* @param sn sequence number to increment
|
|
|
|
* @return the incremented sequence number
|
|
|
|
*/
|
|
|
|
record_sequence_number_t sn_decrement(record_sequence_number_t sn);
|
|
|
|
|
2021-05-14 00:31:14 +02:00
|
|
|
/**
|
|
|
|
* Increment the given sequence number by a given amount.
|
|
|
|
*
|
|
|
|
* @param sn sequence number to increment
|
|
|
|
* @return the incremented sequence number
|
|
|
|
*/
|
|
|
|
record_sequence_number_t sn_increment_by(record_sequence_number_t sn, uint32_t amount);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the middle between to given sequence numbers, while handling a possible wrap-around.
|
|
|
|
*
|
|
|
|
* @param older sequence number which will be treated as the older one
|
|
|
|
* @param newer sequence number which will be treated as the newer one
|
|
|
|
* @return the sequence number in the middle
|
|
|
|
*/
|
|
|
|
record_sequence_number_t sn_get_middle_sn(record_sequence_number_t older, record_sequence_number_t newer);
|
2021-03-17 14:49:07 +01:00
|
|
|
#endif
|