C ++ Cereal: serialize a C-style array

Can / How do you serialize an array using the cereal library .

those.

void save(Archive & ar, const unsigned int version) const
{
    unsigned int l  = g1_size_bin(g,POINT_COMPRESS);
    uint8_t data[l];
    memset(data, 0, l);
    g1_write_bin(data, l, g,POINT_COMPRESS);
    ar(l);
    ar(data); // what should be here
}

This does not work (and I did not expect this either). Does not

ar(cereal::binary_data(data,l)); 

(which I thought would work, as it looks like the promotion code to be used), which causes a compilation error:

/usr/local/include/cereal/cereal.hpp:79:17: note: candidate template is ignored: replacement failed: changed type 'unsigned char (&) [l]' cannot be used as a template argument BinaryData binary_data (T & data, size_t size)

Does not

ar.saveBinaryValue(data,l);

Since this method is only supported for XML / Json, and I need a binary archive.

+4
source share
1

cereal::binary_data - , POD. , binary_data ( portable_binary). binary_data , - , .

, C:

#include <cereal/archives/binary.hpp>
#include <iostream>

int main()
{
  std::stringstream ss;

  {
    cereal::BinaryOutputArchive ar(ss);
    std::uint8_t data[] = {1, 2, 3};
    ar( cereal::binary_data( data, sizeof(std::uint8_t) * 3 ) );
  }

  {
    cereal::BinaryInputArchive ar(ss);
    std::uint8_t data[3];
    ar( cereal::binary_data( data, sizeof(std::uint8_t) * 3 ) );

    for( int i : data )
      std::cout << i << " ";
  }

  return 0;
}

C POD, .

+6

All Articles