forked from blue/lmdbal
finally, first working prototype
This commit is contained in:
parent
d67a3c32eb
commit
5f90a21fe6
11 changed files with 193 additions and 112 deletions
|
@ -14,57 +14,73 @@
|
|||
// 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 CORE_DATABASE_SERIALIZER_HPP
|
||||
#define CORE_DATABASE_SERIALIZER_HPP
|
||||
|
||||
#include "serializer.h"
|
||||
|
||||
template<class T>
|
||||
Core::DataBase::Serializer<T>::Serializer() :
|
||||
DataBase::Serializer<T>::Serializer() :
|
||||
bytes(),
|
||||
buffer(&bytes),
|
||||
stream(&buffer)
|
||||
{
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
buffer.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Core::DataBase::Serializer<T>::Serializer(const T& value) :
|
||||
DataBase::Serializer<T>::Serializer(const T& value) :
|
||||
bytes(),
|
||||
buffer(&bytes),
|
||||
stream(&buffer)
|
||||
{
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
buffer.open(QIODevice::ReadWrite);
|
||||
_setValue(value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Core::DataBase::Serializer<T>::~Serializer() {
|
||||
DataBase::Serializer<T>::~Serializer() {
|
||||
buffer.close();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
MDB_val Core::DataBase::Serializer<T>::setData(const T& value) {
|
||||
MDB_val DataBase::Serializer<T>::setData(const T& value) {
|
||||
clear();
|
||||
_setValue(value);
|
||||
return getValue();
|
||||
_setData(value);
|
||||
return getData();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Core::DataBase::Serializer<T>::_setData(const T& value) {
|
||||
T DataBase::Serializer<T>::deserialize(const MDB_val& value) {
|
||||
clear();
|
||||
bytes.setRawData((char*)value.mv_data, value.mv_size);
|
||||
T result;
|
||||
stream >> result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DataBase::Serializer<T>::_setData(const T& value) {
|
||||
stream << value;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Core::DataBase::Serializer<T>::clear() {
|
||||
void DataBase::Serializer<T>::clear() {
|
||||
if (buffer.pos() > 0) {
|
||||
buffer.seek(0);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
MDB_val Core::DataBase::Serializer<T>::getData() {
|
||||
MDB_val DataBase::Serializer<T>::getData() {
|
||||
MDB_val val;
|
||||
|
||||
val.mv_size = buffer.pos();
|
||||
val.mv_data = (uint8_t*)bytes.data();
|
||||
val.mv_data = (char*)bytes.data();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif //CORE_DATABASE_SERIALIZER_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue