LMDBAL 0.6.0
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
serializer_uint64.hpp
1/*
2 * LMDB Abstraction Layer.
3 * Copyright (C) 2023 Yury Gubich <blue@macaw.me>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <stdint.h>
22
23namespace LMDBAL {
24
25template<>
26class Serializer<uint64_t> {
27public:
28 Serializer():value(0) {};
29 Serializer(const uint64_t& p_value):value(p_value) {};
30 ~Serializer() {};
31
32 uint64_t deserialize(const MDB_val& data) {
33 deserialize(data, value);
34 return value;
35 };
36 void deserialize(const MDB_val& data, uint64_t& result) {
37 std::memcpy(&result, data.mv_data, 8);
38 }
39 MDB_val setData(const uint64_t& data) {
40 value = data;
41 return getData();
42 };
43 MDB_val getData() {
44 MDB_val result;
45 result.mv_data = &value;
46 result.mv_size = 8;
47 return result;
48 };
49 void clear() {}; //not possible;
50
51private:
52 uint64_t value;
53};
54
55}
A class handling serialization/deserialization.
Definition serializer.h:33
~Serializer()
Destoys the serializer.
Definition serializer.hpp:69
Serializer()
Creates an empty Serializer.
Definition serializer.hpp:40
MDB_val getData()
Returns the data if it already was serialized.
Definition serializer.hpp:153
T deserialize(const MDB_val &value)
Deserializes value.
Definition serializer.hpp:99
void clear()
Clears the state of serializer.
Definition serializer.hpp:137
MDB_val setData(const T &value)
Sets the data to the seriazer.
Definition serializer.hpp:83