1

I have a simple classe here :

template <typename T>
class clDaughter
{
public:

  T*        __pData;
  uint16_t  __u16Size;

  clDaughter() [...]

  ~clDaughter() [...]

  clDaughter(uint16_t const ku16Size)
  {
    this->__pData = (T*)malloc(ku16Size * sizeof(T));
    this->__u16Size = ku16Size;
  }

  template<class Archive>
  void save(Archive & ar) const
  {
    ar(this->__u16Size);
    ar(cereal::binary_data(this->__pData, this->__u16Size * sizeof(T)));
  }

  template<class Archive>
  void load(Archive & ar)
  {
    uint16_t u16LoadedSize;
    ar(u16LoadedSize);

    this->__pData = (T*)malloc(u16LoadedSize * sizeof(T));
    this->__u16Size = u16LoadedSize;
    ar(cereal::binary_data(this->__pData, this->__u16Size * sizeof(T)));
  }
};

This is working fine, I mean, serialization in and out is tested ok.

Trouble starts when I want to use polymorphism here. This daughter class inherits from a pure virtual mother class, as well as other "daugter-like" classes.

class clDaugter_A : public clMother
{
  [...]
}
class clDaugter_B : public clMother
{
  [...]
}

And, when I want to register my clDaughter class using the CEREAL_REGISTER_TYPE(...) macro,

CEREAL_REGISTER_TYPE(clDaugter_A<int>)   
CEREAL_REGISTER_TYPE(clDaugter_B<int>)

compiler crashes with

"cereal could not find any output serialization functions for the provided type and archive combination"

It really seems the problem comes from this binary_data(...) method because if I serialize the __pData array in a loop (ugly-style)

for (u16Idx = 0;..;..)
{
  ar(this->__pData[u16Idx];
}

I have no error and it works fine. It is only when I use binary_data() and CEREAL_REGISTER_TYPE() together.

What did I miss ?

(to pre-empt the question, I do want to use binary_data() because it's something like 20-30 times faster than the loop and I need to be fast here)

Thank for your help

Daemon Pulsar
  • 13
  • 1
  • 5
  • There's definitely a subtle polymorphic registration bug at work here; I can get your example to work properly if I use a binary archive (which supports `binary_data`), but _only if_ I do not have the header for a text based archive (e.g. json) included. I'm still looking into this and will likely post back with a bug report on the github page. – Azoth Dec 15 '15 at 19:12
  • Here's the first bug related to this, which may not fully encompass the problem here: https://github.com/USCiLab/cereal/issues/253 – Azoth Dec 16 '15 at 19:23

0 Answers0