a bug fix, reorganization and 0.5.1
Some checks failed
Main LMDBAL workfow / Archlinux (push) Failing after 38s

This commit is contained in:
Blue 2023-10-21 16:41:41 -03:00
parent 6b348023bb
commit 0079f6e96e
Signed by: blue
GPG key ID: 9B203B252A63EE38
22 changed files with 37 additions and 31 deletions

View file

@ -0,0 +1,21 @@
set(HEADERS
serializer.h
serializer.hpp
serializer_uint8.hpp
serializer_uint16.hpp
serializer_uint32.hpp
serializer_uint64.hpp
serializer_int8.hpp
serializer_int16.hpp
serializer_int32.hpp
serializer_int64.hpp
serializer_float.hpp
serializer_double.hpp
serializer_stdstring.hpp
serializer_qstring.hpp
serializer_qbytearray.hpp
)
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_LOW})

View file

@ -0,0 +1,72 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_H
#define LMDBAL_SERIALIZER_H
#include <cstring>
#include <QByteArray>
#include <QBuffer>
#include <QDataStream>
#include <lmdb.h>
namespace LMDBAL {
template<class T>
class Serializer {
public:
Serializer();
Serializer(const T& value);
~Serializer();
T deserialize(const MDB_val& value);
void deserialize(const MDB_val& value, T& result);
MDB_val setData(const T& value);
MDB_val getData();
void clear();
private:
void _setData(const T& value);
private:
QByteArray bytes;
QBuffer buffer;
QDataStream stream;
};
}
#include "serializer.hpp"
#include "serializer_uint64.hpp"
#include "serializer_uint32.hpp"
#include "serializer_uint16.hpp"
#include "serializer_uint8.hpp"
#include "serializer_int64.hpp"
#include "serializer_int32.hpp"
#include "serializer_int16.hpp"
#include "serializer_int8.hpp"
#include "serializer_float.hpp"
#include "serializer_double.hpp"
#include "serializer_stdstring.hpp"
#include "serializer_qstring.hpp"
#include "serializer_qbytearray.hpp"
#endif // LMDBAL_SERIALIZER_H

View file

@ -0,0 +1,163 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_HPP
#define LMDBAL_SERIALIZER_HPP
#include "serializer.h"
/**
* \class LMDBAL::Serializer
* \brief A class handling serialization/deserialization
*
* A class that is constructed in every LMDBAL::Storage
* to serialize or deserialize keys and values.
*
* It serializes to and deserializes from <a class="el" href="http://www.lmdb.tech/doc/group__mdb.html#structMDB__val">MDB_val</a>
*
* \tparam K type of the keys of the storage
* \tparam V type of the values of the storage
*/
/**
* \brief Creates an empty Serializer
*/
template<class T>
LMDBAL::Serializer<T>::Serializer() :
bytes(),
buffer(&bytes),
stream(&buffer)
{
buffer.open(QIODevice::ReadWrite);
}
/**
* \brief Creates a Serializer with some data in it
*
* The data automatically gets serialized
*
* \param[in] value - a value that is assigned to the serializer
*/
template<class T>
LMDBAL::Serializer<T>::Serializer(const T& value) :
bytes(),
buffer(&bytes),
stream(&buffer)
{
buffer.open(QIODevice::ReadWrite);
_setData(value);
}
/**
* \brief Destoys the serializer
*/
template<class T>
LMDBAL::Serializer<T>::~Serializer() {
buffer.close();
}
/**
* \brief Sets the data to the seriazer
*
* This is a normal way to seriaze value
*
* \param[in] value - a value you want to serialize
*
* \returns serialized value
*/
template<class T>
MDB_val LMDBAL::Serializer<T>::setData(const T& value) {
clear();
_setData(value);
return getData();
}
/**
* \brief Deserializes value
*
* This is a normal way to deseriaze value
*
* \param[in] value - a value you want to deserialize
*
* \returns deserialized value
*/
template<class T>
T LMDBAL::Serializer<T>::deserialize(const MDB_val& value) {
T result;
deserialize(value, result);
return result;
}
/**
* \brief Deserializes value
*
* This is a normal way to deseriaze value
*
* \param[in] value - a value you want to deserialize
* \param[out] result - deserialized value
*/
template<class T>
void LMDBAL::Serializer<T>::deserialize(const MDB_val& value, T& result) {
clear();
bytes.setRawData((char*)value.mv_data, value.mv_size);
stream >> result;
}
/**
* \brief Private function that handles serialization
*
* \param[in] value - a value you want to serialize
*/
template<class T>
void LMDBAL::Serializer<T>::_setData(const T& value) {
stream << value;
}
/**
* \brief Clears the state of serializer
*
* Normally you don't need to call this function
*/
template<class T>
void LMDBAL::Serializer<T>::clear() {
if (buffer.pos() > 0) {
buffer.seek(0);
}
}
/**
* \brief Returns the data if it already was serialized
*
* Normally you don't need to call this function
*
* This may be usefull if you called LMDBAL::Serilizer::setData() but lost the result
*
* \returns Serialized data
*/
template<class T>
MDB_val LMDBAL::Serializer<T>::getData() {
MDB_val val;
val.mv_size = buffer.pos();
val.mv_data = (char*)bytes.data();
return val;
}
#endif //LMDBAL_SERIALIZER_HPP

View file

@ -0,0 +1,59 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_DOUBLE_HPP
#define LMDBAL_SERIALIZER_DOUBLE_HPP
namespace LMDBAL {
template<>
class Serializer<double> {
public:
Serializer():value(0) {};
Serializer(const double& p_value):value(p_value) {};
~Serializer() {};
double deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, double& result) {
std::memcpy(&result, data.mv_data, 8);
}
MDB_val setData(const double& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 8;
return result;
};
void clear() {}; //not possible;
private:
double value;
};
}
#endif //LMDBAL_SERIALIZER_DOUBLE_HPP

View file

@ -0,0 +1,59 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_FLOAT_HPP
#define LMDBAL_SERIALIZER_FLOAT_HPP
namespace LMDBAL {
template<>
class Serializer<float> {
public:
Serializer():value(0) {};
Serializer(const float& p_value):value(p_value) {};
~Serializer() {};
float deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, float& result) {
std::memcpy(&result, data.mv_data, 4);
}
MDB_val setData(const float& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 4;
return result;
};
void clear() {}; //not possible;
private:
float value;
};
}
#endif //LMDBAL_SERIALIZER_FLOAT_HPP

View file

@ -0,0 +1,58 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_INT16_HPP
#define LMDBAL_SERIALIZER_INT16_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<int16_t> {
public:
Serializer():value(0) {};
Serializer(const int16_t& p_value):value(p_value) {};
~Serializer() {};
int16_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, int16_t& result) {
std::memcpy(&result, data.mv_data, 2);
}
MDB_val setData(const int16_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 2;
return result;
};
void clear() {}; //not possible;
private:
int16_t value;
};
}
#endif //LMDBAL_SERIALIZER_INT16_HPP

View file

@ -0,0 +1,61 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_INT32_HPP
#define LMDBAL_SERIALIZER_INT32_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<int32_t> {
public:
Serializer():value(0) {};
Serializer(const int32_t& p_value):value(p_value) {};
~Serializer() {};
int32_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, int32_t& result) {
std::memcpy(&result, data.mv_data, 4);
}
MDB_val setData(const int32_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 4;
return result;
};
void clear() {}; //not possible;
private:
int32_t value;
};
}
#endif //LMDBAL_SERIALIZER_INT32_HPP

View file

@ -0,0 +1,61 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_INT64_HPP
#define LMDBAL_SERIALIZER_INT64_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<int64_t> {
public:
Serializer():value(0) {};
Serializer(const int64_t& p_value):value(p_value) {};
~Serializer() {};
int64_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, int64_t& result) {
std::memcpy(&result, data.mv_data, 8);
}
MDB_val setData(const int64_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 8;
return result;
};
void clear() {}; //not possible;
private:
int64_t value;
};
}
#endif //LMDBAL_SERIALIZER_INT64_HPP

View file

@ -0,0 +1,61 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_INT8_HPP
#define LMDBAL_SERIALIZER_INT8_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<int8_t> {
public:
Serializer():value(0) {};
Serializer(const int8_t& p_value):value(p_value) {};
~Serializer() {};
int8_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, int8_t& result) {
std::memcpy(&result, data.mv_data, 1);
}
MDB_val setData(const int8_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 1;
return result;
};
void clear() {}; //not possible;
private:
int8_t value;
};
}
#endif //LMDBAL_SERIALIZER_INT8_HPP

View file

@ -0,0 +1,64 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_QBYTEARRAY_HPP
#define LMDBAL_SERIALIZER_QBYTEARRAY_HPP
#include <QByteArray>
namespace LMDBAL {
template<>
class Serializer<QByteArray> {
public:
Serializer():value() {};
Serializer(const QByteArray& p_value):value(p_value) {};
~Serializer() {};
QByteArray deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, QByteArray& result) {
result.setRawData((char*)data.mv_data, data.mv_size);
}
MDB_val setData(const QByteArray& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = value.data();
result.mv_size = value.size();
return result;
};
void clear() {
value.clear();
};
private:
QByteArray value;
};
}
#endif //LMDBAL_SERIALIZER_QBYTEARRAY_HPP

View file

@ -0,0 +1,65 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_QSTRING_HPP
#define LMDBAL_SERIALIZER_QSTRING_HPP
#include <QString>
#include <QByteArray>
namespace LMDBAL {
template<>
class Serializer<QString> {
public:
Serializer():value() {};
Serializer(const QString& p_value):value(p_value.toUtf8()) {};
~Serializer() {};
QString deserialize(const MDB_val& data) {
value = QByteArray((char*)data.mv_data, data.mv_size);
return QString::fromUtf8(value);
};
void deserialize(const MDB_val& data, QString& result) {
value = QByteArray((char*)data.mv_data, data.mv_size);
result = QString::fromUtf8(value);
}
MDB_val setData(const QString& data) {
value = data.toUtf8();
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = value.data();
result.mv_size = value.size();
return result;
};
void clear() {}; //not possible;
private:
QByteArray value;
};
}
#endif //LMDBAL_SERIALIZER_QSTRING_HPP

View file

@ -0,0 +1,62 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_STDSTRING_HPP
#define LMDBAL_SERIALIZER_STDSTRING_HPP
#include <string>
namespace LMDBAL {
template<>
class Serializer<std::string> {
public:
Serializer():value() {};
Serializer(const std::string& p_value):value(p_value) {};
~Serializer() {};
std::string deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, std::string& result) {
result.assign((char*)data.mv_data, data.mv_size);
}
MDB_val setData(const std::string& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = (char*)value.c_str();
result.mv_size = value.size();
return result;
};
void clear() {}; //not possible;
private:
std::string value;
};
}
#endif //LMDBAL_SERIALIZER_STDSTRING_HPP

View file

@ -0,0 +1,60 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_UINT16_HPP
#define LMDBAL_SERIALIZER_UINT16_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<uint16_t> {
public:
Serializer():value(0) {};
Serializer(const uint16_t& p_value):value(p_value) {};
~Serializer() {};
uint16_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, uint16_t& result) {
std::memcpy(&result, data.mv_data, 2);
}
MDB_val setData(const uint16_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 2;
return result;
};
void clear() {}; //not possible;
private:
uint16_t value;
};
}
#endif //LMDBAL_SERIALIZER_UINT16_HPP

View file

@ -0,0 +1,58 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_UINT32_HPP
#define LMDBAL_SERIALIZER_UINT32_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<uint32_t> {
public:
Serializer():value(0) {};
Serializer(const uint32_t& p_value):value(p_value) {};
~Serializer() {};
uint32_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, uint32_t& result) {
std::memcpy(&result, data.mv_data, 4);
}
MDB_val setData(const uint32_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 4;
return result;
};
void clear() {}; //not possible;
private:
uint32_t value;
};
}
#endif //LMDBAL_SERIALIZER_UINT32_HPP

View file

@ -0,0 +1,59 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_UINT64_HPP
#define LMDBAL_SERIALIZER_UINT64_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<uint64_t> {
public:
Serializer():value(0) {};
Serializer(const uint64_t& p_value):value(p_value) {};
~Serializer() {};
uint64_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, uint64_t& result) {
std::memcpy(&result, data.mv_data, 8);
}
MDB_val setData(const uint64_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 8;
return result;
};
void clear() {}; //not possible;
private:
uint64_t value;
};
}
#endif //LMDBAL_SERIALIZER_UINT64_HPP

View file

@ -0,0 +1,61 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LMDBAL_SERIALIZER_UINT8_HPP
#define LMDBAL_SERIALIZER_UINT8_HPP
#include <stdint.h>
namespace LMDBAL {
template<>
class Serializer<uint8_t> {
public:
Serializer():value(0) {};
Serializer(const uint8_t& p_value):value(p_value) {};
~Serializer() {};
uint8_t deserialize(const MDB_val& data) {
deserialize(data, value);
return value;
};
void deserialize(const MDB_val& data, uint8_t& result) {
std::memcpy(&result, data.mv_data, 1);
}
MDB_val setData(const uint8_t& data) {
value = data;
return getData();
};
MDB_val getData() {
MDB_val result;
result.mv_data = &value;
result.mv_size = 1;
return result;
};
void clear() {}; //not possible;
private:
uint8_t value;
};
}
#endif //LMDBAL_SERIALIZER_UINT8_HPP