exception: boost::archive::archive_exception at memory location
我发现了这个但没有用,因为他正在为文件做,而我只想做矢量。
问题:我在服务器端进行了向量的序列化并解析到客户端,然后我正在进行反序列化。所以一切都适合1/2记录。
但如果我插入超过2条记录并通过向量解析它在客户端给我这个错误,我反序列化数据:Microsoft C ++异常:在内存位置的boost :: archive :: archive_exception
这是我的代码:
服务器端:
通过将Vector作为输入来serializeData
//I think these headers are enough !!!
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include<boost/serialization/vector.hpp>
#include<boost/serialization/map.hpp>
template<class input>
void UdpServer::serializeData(input &vector) { // Here i use vector in parameter
std::ostringstream archive_stream;
boost::archive::text_oarchive archive(archive_stream);
archive << vector;
sendMessageToClients(archive_stream.str());//sending to client
}
我收到错误的客户端
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include<boost/serialization/vector.hpp>
#include<boost/serialization/map.hpp>
//this is what i received from the server
size_t const len = m_socket.receive_from(
boost::asio::buffer(recv_buf), m_sender_endpoint);
std::string const received_message(recv_buf.data(), len);
std::string archive_data(received_message);// receive from server
std::istringstream archive_stream(archive_data);
boost::archive::text_iarchive archive(archive_stream);
archive >> map;
displayCarData(map); //i'm passing this to function for printing the values
我尝试添加Boost io二进制库,但错误是: c ++超出范围的内存位置 //这是我尝试使用io二进制库
std::string archive_data(received_message);
std::istringstream archive_stream(archive_data);
boost::archive::text_iarchive archive(archive_stream, boost::io::binary);
archive >> map;
displayCarData(map);
任何帮助将不胜感激,
先谢谢,
答案 0 :(得分:3)
//this is what i received from the server
size_t const len = m_socket.receive_from(
boost::asio::buffer(recv_buf,1024), m_sender_endpoint);
我认为你必须在
中给出尺寸 boost::asio::buffer(recv_buf,1024), m_sender_endpoint);
在这一行中也适用于服务器端。
答案 1 :(得分:1)
archive << vector;
建议您确实序列化std::vector
archive >> map;
建议您反序列化std::map
那不会奏效。确实可能是Undefined Behaviour。