Binary serialization / deserialization

Here is the gnerated code for std stream:

/////////////////////////////////////////////////////////////////////////////////////
//  
// Gepard ORM generated file!
// GORM Version : 1.4.0.1002

#include"../myserializationbase.h"

void MySerializationBase::serialize(std::ostream& ser)
{
    ser.write(reinterpret_cast<char*>(&_bool1),sizeof(bool));
    ser.write(reinterpret_cast<char*>(&_num1),sizeof(int));
    ser.write(reinterpret_cast<char*>(&_num2),sizeof(uint32_t));
    ser.write(reinterpret_cast<char*>(&_num3),sizeof(uint64_t));
    ser.write(reinterpret_cast<char*>(&_num4),sizeof(long));
    ser.write(reinterpret_cast<char*>(&_num5),sizeof(long long));
    ser.write(reinterpret_cast<char*>(&_num6),sizeof(float));
    ser.write(reinterpret_cast<char*>(&_num7),sizeof(double));
    {unsigned len = _text1.length();ser.write(reinterpret_cast<char*>(&len),sizeof(unsigned));ser << _text1;};
    {int len = _text2.length();ser.write(reinterpret_cast<char*>(&len),sizeof(int));ser << _text2.toStdString();};
    {qint64 val =_date1.toJulianDay();ser.write(reinterpret_cast<char*>(&val),sizeof(qint64));};
    {int val =_time1.msecsSinceStartOfDay();ser.write(reinterpret_cast<char*>(&val),sizeof(int));};
    {qint64 val = _datetime1.toMSecsSinceEpoch();ser.write(reinterpret_cast<char*>(&val),sizeof(qint64));};
    {
        unsigned size = _contNum1.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::vector<int>::const_iterator it = _contNum1.begin() ; it != _contNum1.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it)),sizeof(int));
        }
    }
    {
        unsigned size = _contNum2.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::list<int>::const_iterator it = _contNum2.begin() ; it != _contNum2.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it)),sizeof(int));
        }
    }
    {
        unsigned size = _contNum3.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::set<int>::const_iterator it = _contNum3.begin() ; it != _contNum3.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it)),sizeof(int));
        }
    }
    {
        unsigned size = _contNum4.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::map<int, int>::const_iterator it = _contNum4.begin() ; it != _contNum4.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it).first),sizeof(int));
            ser.write(reinterpret_cast<const char*>(&(*it).second),sizeof(int));
        }
    }
    ser.write(reinterpret_cast<char*>(&std::get<0>(_contNum5)),sizeof(int));
    ser.write(reinterpret_cast<char*>(&std::get<1>(_contNum5)),sizeof(int));
    {unsigned len = std::get<2>(_contNum5).length();ser.write(reinterpret_cast<char*>(&len),sizeof(unsigned));ser << std::get<2>(_contNum5);};
    {
        unsigned size = _contNum6.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (QVector<int>::const_iterator it = _contNum6.begin() ; it != _contNum6.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it)),sizeof(int));
        }
    }
    {
        unsigned size = _contNum7.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (QList<int>::const_iterator it = _contNum7.begin() ; it != _contNum7.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it)),sizeof(int));
        }
    }
    {
        unsigned size = _contNum8.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (QSet<int>::const_iterator it = _contNum8.begin() ; it != _contNum8.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&(*it)),sizeof(int));
        }
    }
    {
        unsigned size = _contNum9.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (QMap<int, int>::const_iterator it = _contNum9.begin() ; it != _contNum9.end() ; ++it){
            ser.write(reinterpret_cast<const char*>(&it.key()),sizeof(int));
            ser.write(reinterpret_cast<const char*>(&it.value()),sizeof(int));
        }
    }
    ser.write(reinterpret_cast<char*>(&(*_smart1)),sizeof(int));
    ser.write(reinterpret_cast<char*>(&(*_smart2)),sizeof(int));
    ser.write(reinterpret_cast<char*>(&(*_smart3)),sizeof(int));
    ser.write(reinterpret_cast<char*>(&(*_smart4)),sizeof(int));
    _link1.serialize(ser);
    _link2->serialize(ser);
    {
        unsigned size = _link3.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::vector<MySerializationChild>::iterator it = _link3.begin() ; it != _link3.end() ; ++it){
            (*it).serialize(ser);
        }
    }
    {
        unsigned size = _link4.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::vector<MySerializationChild *>::const_iterator it = _link4.begin() ; it != _link4.end() ; ++it){
            (*it)->serialize(ser);
        }
    }
    {
        unsigned size = _link5.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (QList<class MySerializationChild>::iterator it = _link5.begin() ; it != _link5.end() ; ++it){
            (*it).serialize(ser);
        }
    }
    {
        unsigned size = _link6.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (QList<class MySerializationChild *>::const_iterator it = _link6.begin() ; it != _link6.end() ; ++it){
            (*it)->serialize(ser);
        }
    }
    {
        unsigned size = _link7.size();
        ser.write(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (std::vector<std::shared_ptr<MySerializationChild> >::const_iterator it = _link7.begin() ; it != _link7.end() ; ++it){
            (*(*it)).serialize(ser);
        }
    }
}
void MySerializationBase::deserialize(std::istream& des)
{
    des.read(reinterpret_cast<char*>(&_bool1),sizeof(bool));
    des.read(reinterpret_cast<char*>(&_num1),sizeof(int));
    des.read(reinterpret_cast<char*>(&_num2),sizeof(uint32_t));
    des.read(reinterpret_cast<char*>(&_num3),sizeof(uint64_t));
    des.read(reinterpret_cast<char*>(&_num4),sizeof(long));
    des.read(reinterpret_cast<char*>(&_num5),sizeof(long long));
    des.read(reinterpret_cast<char*>(&_num6),sizeof(float));
    des.read(reinterpret_cast<char*>(&_num7),sizeof(double));
    {unsigned len; des.read(reinterpret_cast<char*>(&len),sizeof(unsigned));for (;len>0;--len)_text1.push_back(des.get());};
    {int len; des.read(reinterpret_cast<char*>(&len),sizeof(int));for (;len>0;--len)_text2.push_back(des.get());};
    {qint64 val;des.read(reinterpret_cast<char*>(&val),sizeof(qint64));_date1 = QDate::fromJulianDay(val);};
    {int val;des.read(reinterpret_cast<char*>(&val),sizeof(int));_time1 = QTime::fromMSecsSinceStartOfDay(val);};
    {qint64 val;des.read(reinterpret_cast<char*>(&val),sizeof(qint64));_datetime1.setMSecsSinceEpoch(val);};
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int ContNum1Item;
            des.read(reinterpret_cast<char*>(&ContNum1Item),sizeof(int));
            _contNum1.push_back(ContNum1Item);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int ContNum2Item;
            des.read(reinterpret_cast<char*>(&ContNum2Item),sizeof(int));
            _contNum2.push_back(ContNum2Item);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int ContNum3Item;
            des.read(reinterpret_cast<char*>(&ContNum3Item),sizeof(int));
            _contNum3.insert(ContNum3Item);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int key;
            des.read(reinterpret_cast<char*>(&key),sizeof(int));
            int value;
            des.read(reinterpret_cast<char*>(&value),sizeof(int));
            _contNum4.insert(std::pair<int, int>(key,value));
        }
    }
    {
        int var_0;
        des.read(reinterpret_cast<char*>(&var_0),sizeof(int));
        int var_1;
        des.read(reinterpret_cast<char*>(&var_1),sizeof(int));
        std::string var_2;
        {unsigned len; des.read(reinterpret_cast<char*>(&len),sizeof(unsigned));for (;len>0;--len)var_2.push_back(des.get());};
        _contNum5 = std::make_tuple(var_0,var_1,var_2);
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int ContNum6Item;
            des.read(reinterpret_cast<char*>(&ContNum6Item),sizeof(int));
            _contNum6.append(ContNum6Item);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int ContNum7Item;
            des.read(reinterpret_cast<char*>(&ContNum7Item),sizeof(int));
            _contNum7.append(ContNum7Item);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int ContNum8Item;
            des.read(reinterpret_cast<char*>(&ContNum8Item),sizeof(int));
            _contNum8.insert(ContNum8Item);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            int key;
            des.read(reinterpret_cast<char*>(&key),sizeof(int));
            int value;
            des.read(reinterpret_cast<char*>(&value),sizeof(int));
            _contNum9.insert(key,value);
        }
    }
    {int val;des.read(reinterpret_cast<char*>(&val),sizeof(int));_smart1 = std::make_shared<int>(((val)));
    }{int val;des.read(reinterpret_cast<char*>(&val),sizeof(int));_smart2 = std::auto_ptr<int>(new int((val)));
    }{int val;des.read(reinterpret_cast<char*>(&val),sizeof(int));_smart3 = std::move(std::unique_ptr<int>(new int(val)));
    }{int val;des.read(reinterpret_cast<char*>(&val),sizeof(int));_smart4 = QSharedPointer<int>::create(((val)));
    }_link1.deserialize(des);
    _link2  = new MySerializationChild();
    _link2->deserialize(des);
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            MySerializationChild myField ;
            myField.deserialize(des);
            _link3.push_back(myField);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            MySerializationChild * myField  = new MySerializationChild();
            myField->deserialize(des);
            _link4.push_back(myField);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            MySerializationChild myField ;
            myField.deserialize(des);
            _link5.append(myField);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            MySerializationChild * myField  = new MySerializationChild();
            myField->deserialize(des);
            _link6.append(myField);
        }
    }
    {
        unsigned size;
        des.read(reinterpret_cast<char*>(&size),sizeof(unsigned));
        for (unsigned i = 0 ; i < size ; ++i){
            std::shared_ptr<MySerializationChild> myField = std::make_shared<MySerializationChild>(((MySerializationChild())));
            myField->deserialize(des);
            _link7.push_back(myField);
        }
    }
}

Get GORM click here

Date modified: 
Sunday, January 29, 2017 - 23:15
Date published: 
Keywords: 
C++,Serialization,Binary Stream,Tutorial
Author: 
Publisher: 
Mega-Siraj Bt