不能使用boost :: stream和std :: string <unsigned char =“”>来实现boost :: binary_oarchive或boost :: binary_iarchive

时间:2016-02-18 10:04:50

标签: c++ boost stream boost-serialization unsigned-char

欢呼开发者,

我遇到了下一个代码(visual studio 2015编译器)的问题:

template<typename SERIALIZABLE_TYPE, typename BUFFER_TYPE>
inline void Serialize::IntoStringBuffer(const SERIALIZABLE_TYPE& object, BUFFER_TYPE& strBuffer)
{
    back_insert_device<BUFFER_TYPE> inserter(strBuffer);
    stream<back_insert_device<BUFFER_TYPE>> aStream(inserter);

    binary_oarchive binaryOutArchive(aStream);
    binaryOutArchive & object;

    aStream.flush();
}

template<typename SERIALIZABLE_TYPE, typename BUFFER_TYPE>
inline void Types::Serialize::FromStringBuffer(const BUFFER_TYPE& strBuffer, SERIALIZABLE_TYPE& object)
{
    basic_array_source<typename BUFFER_TYPE::value_type> arraySource(strBuffer.data(), strBuffer.size());
    stream<basic_array_source<typename BUFFER_TYPE::value_type>> aStream(arraySource);

    binary_iarchive binaryInArchive(aStream);
    binaryInArchive & object;
}

当我使用带有序列化对象和std :: string缓冲区的这些助手时,解决方案构建。

但是,我必须使用带有unsigned char类型的std :: basic_string作为缓冲区。然后,该解决方案不再编译:

error C2664: 'boost::archive::binary_iarchive::binary_iarchive(const boost::archive::binary_iarchive &)' : impossible de convertir l'argument 1 de 'boost::iostreams::stream<boost::iostreams::basic_array_source<unsigned char>,std::char_traits<_Elem>,std::allocator<_Ty>>' en 'std::istream &' with[_Elem=unsigned char,_Ty=unsigned char]

error C2664: 'boost::archive::binary_oarchive::binary_oarchive(const boost::archive::binary_oarchive &)' : impossible de convertir l'argument 1 de 'boost::iostreams::stream<boost::iostreams::back_insert_device<BUFFER_TYPE>,std::char_traits<_Elem>,std::allocator<_Ty>>' en 'std::ostream &' with [ BUFFER_TYPE=std::basic_string<unsigned char>, _Elem=unsigned char, _Ty=unsigned char]

我无法确定究竟是哪个问题?以及如何解决它?

有人建议吗?

最好的问候。

1 个答案:

答案 0 :(得分:0)

问题是不支持无符号字符流。

也没有必要这样做。事情是二进制的。 std::ios::binary模式下的任何流缓冲区都可以。