LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
MdbxKeyUtils.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_DETAIL_MDBXKEYUTILS_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_DETAIL_MDBXKEYUTILS_HPP_INCLUDED
4
7
8#include <cstdint>
9#include <string>
10#include <limits>
11
12namespace logit {
13namespace detail {
14
15inline void mdbx_write_record_key_be(std::string& key, uint64_t value, size_t offset) {
16 for (int shift = 56; shift >= 0; shift -= 8) {
17 key[offset++] = static_cast<char>((value >> shift) & 0xFFu);
18 }
19}
20
21inline void mdbx_write_record_sequence_be(std::string& key, uint32_t value, size_t offset) {
22 for (int shift = 24; shift >= 0; shift -= 8) {
23 key[offset++] = static_cast<char>((value >> shift) & 0xFFu);
24 }
25}
26
27inline std::string make_mdbx_record_key(int64_t timestamp_ms, uint32_t sequence) {
28 std::string key(12, '\0');
29 const uint64_t sortable_ts = static_cast<uint64_t>(timestamp_ms) ^ 0x8000000000000000ULL;
30 mdbx_write_record_key_be(key, sortable_ts, 0);
31 mdbx_write_record_sequence_be(key, sequence, 8);
32 return key;
33}
34
35} // namespace detail
36} // namespace logit
37
38#endif // LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_DETAIL_MDBXKEYUTILS_HPP_INCLUDED
std::string make_mdbx_record_key(int64_t timestamp_ms, uint32_t sequence)
void mdbx_write_record_sequence_be(std::string &key, uint32_t value, size_t offset)
void mdbx_write_record_key_be(std::string &key, uint64_t value, size_t offset)
The primary namespace for the LogIt++ library.