mercredi 17 octobre 2018

C++ Cereal not serializing properly more than one object

I created simple class to test serialization with Cereal which is defined in main.cpp

struct someconf{
unsigned char station;
uint32_t ip_addr;
bool mnch;
bool mnch_ch;
bool tch1;
bool tch1_tg;

template<class Archive>
void load(Archive& arc){
    arc(station, ip_addr, mnch, mnch_ch, tch1, tch1_tg);
}

template<class Archive>
void save(Archive& arc) const{
    arc(station, ip_addr, mnch, mnch_ch, tch1, tch1_tg);
}
};


int main(int argc, char** argv)
{
ofstream out("archive.bin", ios_base::binary);
{
    cereal::BinaryOutputArchive oarc(out);

    someconf s1;
    s1.station=126;
    s1.ip_addr=0x7f01a8c0;
    s1.mnch=true;
    s1.mnch_ch=true;
    s1.tch1=false;
    s1.tch1_tg=false;


    someconf s2;
    s1.station=15;
    s1.ip_addr=0x00ffffff;
    s1.mnch=false;
    s1.mnch_ch=false;
    s1.tch1=true;
    s1.tch1_tg=true;

    someconf s3;
    s1.station=203;
    s1.ip_addr=0x7905a8c0;
    s1.mnch=true;
    s1.mnch_ch=true;
    s1.tch1=true;
    s1.tch1_tg=true;

    oarc(s1, s2, s3);
}

return 0;
}

and read file like this

    someconf test1,test2,test3;
{
   ifstream in("archive.bin", ios_base::binary);

   cereal::BinaryInputArchive iarc(in);

   iarc(test1, test2, test3);
}

When i write and read only one object - it works fine. All data is correct. But when i try to write and read multiple objects - only one of them is not corrupted after reading.

i tried to include other header files such as cereal/types/common.hpp i also tried to use JSONOutputArchive to see whats going on inside the resulted file. and it looks like serialization is incorrect even with JSON format.

My OS is Linux Lubuntu 18.04 gcc version 7.3.0

Aucun commentaire:

Enregistrer un commentaire