2

I want to give a shot to cereal serialization library . I am at beginner level c++ and retired level at java :)

I try to serialize vector with it but cant.

Any suggestion ? I have below codes and gives an error. What am I missing here ?

struct personv1 {
    matrix<float, 0, 1 > _descriptor;
    string person_name;
    string notes;
    matrix<rgb_pixel> s_chips;
    template<class Archive>
    void serialize(Archive & archive)
    {
        // serialize things by passing them to the archive
        archive( _descriptor, person_name,notes , s_chips );
    }
};

std::vector<personv1> person;

and:

std::stringstream ss;

{
    cereal::BinaryOutputArchive oarchive(ss); // Create an output archive

    oarchive(person); // Write the data to the archive
} // archive goes out of scope, ensuring all contents are flushed

{
    cereal::BinaryInputArchive iarchive(ss); // Create an input archive
    iarchive(person); // Read the data from the archive
}

But it gives error:

    ---GUI-master-MAC/cereal/cereal.hpp:462: error: static_assert failed "cereal could not find any output serialization functions for the provided type and archive combination. 

    Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). 
    Serialize functions generally have the following signature: 

     template<class Archive> 
       void serialize(Archive & ar) 
       { 
         ar( member1, member2, member3 ); 
       } 

static_assert(traits::detail::count_output_serializers<T, ArchiveType>::value != 0,
            ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gkamal
  • 20,777
  • 4
  • 60
  • 57
2adnielsenx xx
  • 488
  • 1
  • 5
  • 22
  • Did you forget to put the error? I put all the code together, and tried it myself, and got a bunch of errors about `matrix` and `rgb_pixel`, just due to them being undefined in the code. Didn't see any special errors beyond that. – Shalom Craimer Feb 12 '18 at 20:50
  • Error updated ... matrix coming from dlib https://github.com/davisking/dlib – 2adnielsenx xx Feb 12 '18 at 21:51
  • 1
    It doesn't look like dlib makes any reference to any `Archive` objects from the cereal library (see https://github.com/davisking/dlib/search?q=Archive). That suggests that you would have to write your own `serialize` methods for those included classes to get your code to work. – PaSTE Feb 12 '18 at 22:11
  • The problem is due to the matrix. Try removing the the matrix elements from the serialize. If it works you will need implement the LOAD/SAVE methods for matrix. https://uscilab.github.io/cereal/serialization_functions.html - look at the "External serialize function" example – gkamal Feb 14 '18 at 10:24
  • Please create a [Minimal, Complete, Verifiable Example](https://stackoverflow.com/help/mcve) so we can reproduce the issue, and also - so that you remove any "noise" and parts of your code that are not necessary for you to reproduce it. – einpoklum Feb 14 '18 at 10:33
  • @gkamal is correct. Every type that cereal touches needs to have serialization support. If it isn't included in cereal (via `#include `) it needs to be written, either by you or someone else (like in another library). On that note, make sure you include `` before you serialize your vector of `personv1`. – Azoth Mar 12 '18 at 03:21
  • I will. if I wrote the new type will share with cereal. thx – 2adnielsenx xx Mar 12 '18 at 12:53

0 Answers0