This repository has been archived on 2022-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
LEFTONE/core/locommon/counter.c
falsycat 80b3b82332 [RELEASE] u22-v04
This version is submitted for U22 final presentation. (squashed 158 commits)
2021-02-07 00:00:00 +00:00

52 lines
1017 B
C

#include "./counter.h"
#include <assert.h>
#include <stddef.h>
#include <msgpack.h>
#include "util/mpkutil/get.h"
void locommon_counter_initialize(locommon_counter_t* counter, size_t first) {
assert(counter != NULL);
*counter = (typeof(*counter)) {
.next = first,
};
}
void locommon_counter_deinitialize(locommon_counter_t* counter) {
assert(counter != NULL);
}
size_t locommon_counter_count(locommon_counter_t* counter) {
assert(counter != NULL);
return counter->next++;
}
void locommon_counter_reset(locommon_counter_t* counter) {
assert(counter != NULL);
counter->next = 0;
}
void locommon_counter_pack(
const locommon_counter_t* counter, msgpack_packer* packer) {
assert(counter != NULL);
assert(packer != NULL);
msgpack_pack_uint64(packer, counter->next);
}
bool locommon_counter_unpack(
locommon_counter_t* counter, const msgpack_object* obj) {
assert(counter != NULL);
if (!mpkutil_get_uint64(obj, &counter->next)) {
return false;
}
return true;
}