LMDBAL 0.6.0
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
serializer_qstring.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 <QString>
22#include <QByteArray>
23
24namespace LMDBAL {
25
26template<>
27class Serializer<QString> {
28public:
29 Serializer():value() {};
30 Serializer(const QString& p_value):value(p_value.toUtf8()) {};
31 ~Serializer() {};
32
33 QString deserialize(const MDB_val& data) {
34 value = QByteArray((char*)data.mv_data, data.mv_size);
35 return QString::fromUtf8(value);
36 };
37 void deserialize(const MDB_val& data, QString& result) {
38 value = QByteArray((char*)data.mv_data, data.mv_size);
39 result = QString::fromUtf8(value);
40 }
41 MDB_val setData(const QString& data) {
42 value = data.toUtf8();
43 return getData();
44 };
45 MDB_val getData() {
46 MDB_val result;
47 result.mv_data = value.data();
48 result.mv_size = value.size();
49 return result;
50 };
51 void clear() {}; //not possible;
52
53private:
54 QByteArray value;
55};
56
57}
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