提高property_tree :: json_parser :: read_json&安培;输入输出流:: filtering_streambuf [英] boost property_tree::json_parser::read_json & iostreams::filtering_streambuf
问题描述
我试着去阅读瘪JSON和体验型转换的问题,这里是code
Im trying to read deflated json and experiencing type conversion problems, here is the code
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
std::istringstream iss(std::ios::binary);
iss.rdbuf()->pubsetbuf(buf, len);
iss.imbue( std::locale("ru_RU.CP1251") );
in.push( boost::iostreams::zlib_decompressor() );
in.push( iss );
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json(in, pt); // <-- Compile error
编译器说:
的src / ABPacking.cpp:48:错误:调用没有匹配的功能
read_json(升压::输入输出流:: filtering_streambuf,性病::分配器,
提高::输入输出流::公共_>&放;,提振:: property_tree :: ptree中与放大器;)
src/ABPacking.cpp:48: error: no matching function for call to ‘read_json(boost::iostreams::filtering_streambuf, std::allocator, boost::iostreams::public_>&, boost::property_tree::ptree&)’
现在的问题是如何通过的 filtering_streambuf 为 read_json 避免不必要的数据拷贝?
The question is how to pass filtering_streambuf to read_json without unnecessary data copying?
推荐答案
read_json
期望无论是文件名或流的使用JSON内容。你试图通过流的缓存的,它会不知道该怎么办。
read_json
expects either a file name or a stream with the JSON content. You're trying to pass a stream buffer, and it won't know what to do with it.
作为一个解决方案,只是通过流缓冲区的的IStream
消耗,并传递给 read_json
:
As a solution, just pass the stream buffer to an istream
that consumes it and pass that to read_json
:
std::istream input(&in_buf);
read_json(input, pt);
这篇关于提高property_tree :: json_parser :: read_json&安培;输入输出流:: filtering_streambuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!