【发布时间】:2017-02-01 08:37:33
【问题描述】:
我在序列化数据时遇到了很多麻烦。我做错了什么?
std::string serialize(ContactsList& obj, std::string filename) {
shared_ptr<TMemoryBuffer> transportOut(new TMemoryBuffer());
shared_ptr<TBinaryProtocol> protocolOut(new TBinaryProtocol(transportOut));
obj.write(protocolOut);
std::string serialized_string = transportOut->getBufferAsString();
return serialized_string;
}
这是我从另一个方法调用的方法。我希望得到一个序列化的二进制字符串,我可以将其写入磁盘。在这个序列化方法中,我创建了一个 TMemory 缓冲区,然后我将它包装在一个 TBinaryProtocol 中,然后是对象的 write 方法,它将自己写入内存缓冲区。然后,我将该缓冲区作为字符串返回。然后我会将序列化的字符串写入磁盘。
我收到此错误:
error: no matching function for call to ‘addressbook::ContactsList::write(boost::shared_ptr<apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport> >&)
还有这个注释:
note: no known conversion for argument 1 from ‘boost::shared_ptr<apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport> >’ to ‘apache::thrift::protocol::TProtocol*
我正在使用 Apache Thrift 1.0-dev、C++ 98,如果这些东西有所作为的话。
【问题讨论】:
标签: c++ serialization thrift