我有这个 C++ 函数,它使用 AWS SDK C++将 S3 文件下载为istream :
std::istream& s3read(std::string bucket, std::string key) {
Aws::Client::ClientConfiguration aws_conf;
aws_conf.region = Aws::Environment::GetEnv("AWS_REGION");
aws_conf.caFile = "/etc/pki/tls/certs/ca-bundle.crt";
Aws::S3::S3Client s3_client(aws_conf);
Aws::S3::Model::GetObjectRequest object_request;
object_request.WithBucket(bucket.c_str()).WithKey(key.c_str());
auto get_object_outcome = s3_client.GetObject(object_request);
if (get_object_outcome.IsSuccess()) {
std::istream& res = get_object_outcome.GetResult().GetBody();
return res;
} else {
...
};
};
我从main.cpp调用它并尝试用Jsoncpp解析它:
std::istream& stream = s3read(bucket, key);
Json::Value json;
Json::Reader reader;
reader.parse(stream, json);
但是,我不断收到分段错误。为什么?
我认为问题在于reader.parse需要二进制数据而istream不需要。但是,如果我是对的,如何将流解析为二进制?