4

I am trying to serialize some data structures using Cereal.

The class structure is shown below. I removed everything I deemed irrelevant and marked everything I added to the original file with //added (primarily some default constructors and serialize fn).

The original file can be found here.

#include <cereal/types/polymorphic.hpp>

namespace gadgetlib2 {

typedef ::std::unique_ptr<FElemInterface> FElemInterfacePtr;

class FElemInterface {
  ...
}

class FElem {
private:
    FElemInterfacePtr elem_;
public:
    ...
    template<class Archive>
    void serialize(Archive& ar) // added
    {
      ar( elem_ );
    }
};

class FConst : public FElemInterface {
private:
    long contents_;
    explicit FConst(const long n) : contents_(n) {}
    FConst(const FConst& c) = default;
public:
    FConst(); // added
    ...
    template<class Archive>
    void serialize(Archive& ar) // added
    {
      ar( contents_ );
    }
};

class R1P_Elem : public FElemInterface {
private:
    Fp elem_;
public:
    R1P_Elem(); // added
    ...
    template<class Archive>
    void serialize(Archive& ar) // added
    {
      ar( elem_ );
    }
};

class LinearCombination {
protected:
    ...
    FElem constant_;
public: 
    ...
    template<class Archive>
    void serialize(Archive& ar) // added
    {
      ar( constant_ );
    }
};

}

#include <cereal/archives/binary.hpp>

CEREAL_REGISTER_TYPE(gadgetlib2::FConst);
CEREAL_REGISTER_TYPE(gadgetlib2::R1P_Elem);
CEREAL_REGISTER_POLYMORPHIC_RELATION(gadgetlib2::FElemInterface, gadgetlib2::FConst)
CEREAL_REGISTER_POLYMORPHIC_RELATION(gadgetlib2::FElemInterface, gadgetlib2::R1P_Elem)

Unfortunately, I can't get it to work. I tried a few things and this is my latest version. It yields the following exception:

In file included from .../libff/cereal/archives/binary.hpp:32:
.../libff/cereal/cereal.hpp:853:15: fatal error: no matching member function for call to 'processImpl'
        self->processImpl( head );
        ~~~~~~^~~~~~~~~~~
.../libff/cereal/cereal.hpp:861:9: note: in instantiation of function template specialization 'cereal::InputArchive<cereal::BinaryInputArchive, 1>::process<const libff::bigint<4> &>' requested here
        process( std::forward<T>( head ) );
        ^
...

.../libff/cereal/access.hpp:246:18: note: (skipping 16 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
      { return t.CEREAL_SERIALIZE_FUNCTION_NAME(ar); }
                 ^
.../libff/cereal/macros.hpp:78:40: note: expanded from macro 'CEREAL_SERIALIZE_FUNCTION_NAME'
#define CEREAL_SERIALIZE_FUNCTION_NAME serialize
                                       ^
...
                                  
.../libff/cereal/details/polymorphic_impl.hpp:799:9: note: in instantiation of member function 'cereal::detail::bind_to_archives<gadgetlib2::R1P_Elem>::bind' requested here
        bind( std::is_abstract<T>() );
        ^
...libsnark/gadgetlib2/variable.hpp:641:1: note: in instantiation of member function 'cereal::detail::bind_to_archives<gadgetlib2::R1P_Elem>::bind' requested here
CEREAL_REGISTER_TYPE(gadgetlib2::R1P_Elem);
^
.../libff/cereal/types/polymorphic.hpp:91:3: note: expanded from macro 'CEREAL_REGISTER_TYPE'
  CEREAL_BIND_TO_ARCHIVES(__VA_ARGS__)
  ^
.../libff/cereal/details/polymorphic_impl.hpp:81:26: note: expanded from macro 'CEREAL_BIND_TO_ARCHIVES'
        >::getInstance().bind();                                        
                         ^
...
                   
.../libff/cereal/cereal.hpp:891:21: note: candidate template ignored: could not match 'DeferredData' against 'bigint'
      ArchiveType & processImpl(DeferredData<T> const & d)
                    ^
...
                  
.../libff/cereal/cereal.hpp:1088:21: note: candidate template ignored: substitution failure [with T = const libff::bigint<4>]: no type named 'type' in 'cereal::traits::detail::EnableIfHelper<false, true, false>'
      ArchiveType & processImpl(T & t)
                ^

Questions:

  • Did I add the serialize function used by Cereal correctly, considering FElemInterface is polymorphic and FElem has a pointer?
  • How can the self->processImpl( head ); exception be addressed?
UTF-8
  • 575
  • 1
  • 5
  • 23
Scholle
  • 1,521
  • 2
  • 23
  • 44

0 Answers0