我发现了一个特定的 100MB bin 文件(最小示例中的 CarveObj_k5_rgbThreshold10_triangleCameraMatches.bin),其中谷物无法加载并抛出异常“无法从输入流读取 368 字节!读取 288”
根据相同数据构建的相应 900MB XML 文件(在最小示例中为 CarveObj_k5_rgbThreshold10_triangleCameraMatches.xml)可以正常加载。
XML 文件是由
// {
// std::ofstream outFile(base + "_triangleCameraMatches.xml");
// cereal::XMLOutputArchive oarchive(outFile);
// oarchive(m_triangleCameraMatches);
// }
Run Code Online (Sandbox Code Playgroud)
二进制版本是由
// {
// std::ofstream outFile(base + "_triangleCameraMatches.bin");
// cereal::BinaryOutputArchive oarchive(outFile);
// oarchive(m_triangleCameraMatches);
// }
Run Code Online (Sandbox Code Playgroud)
最小示例:https://www.dropbox.com/sh/fu9e8km0mwbhxvu/AAAfrbqn_9Tnokj4BVXB8miea?dl= 0
使用的谷物版本:1.3.0
2017年MSVS
Windows 10
这是一个错误吗?我错过了一些明显的东西吗?同时创建了一个错误报告:https ://github.com/USCiLab/cereal/issues/607
ios::binary在此特定实例中,由于构造函数调用中缺少标志,因此出现了从 binary.hpp 第 105 行抛出的“无法从输入流读取异常” ifstream。(这是必需的,否则ifstream将尝试将某些文件内容解释为回车符和换行符。有关更多信息,请参阅此问题。)
因此,从 .bin 文件读取的最小示例中的几行代码应如下所示:
vector<vector<float>> testInBinary;
{
std::ifstream is("CarveObj_k5_rgbThreshold10_triangleCameraMatches.bin", ios::binary);
cereal::BinaryInputArchive iarchive(is);
iarchive(testInBinary);
}
Run Code Online (Sandbox Code Playgroud)
然而,即使在修复此问题之后,该特定 .bin 文件中的数据似乎还存在另一个问题,因为当我尝试读取它时,我会抛出一个不同的异常,似乎是由错误编码的大小值引起的。我不知道这是否是从 Dropbox 复制到/从 Dropbox 复制的结果。
Cereal 二进制文件似乎没有 100MB 的基本限制。以下最小示例创建一个大约 256MB 的二进制文件并正常读取:
#include <iostream>
#include <fstream>
#include <vector>
#include <cereal/types/vector.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/binary.hpp>
using namespace std;
int main(int argc, char* argv[])
{
vector<vector<double>> test;
test.resize(32768, vector<double>(1024, -1.2345));
{
std::ofstream outFile("test.bin");
cereal::BinaryOutputArchive oarchive(outFile, ios::binary);
oarchive(test);
}
vector<vector<double>> testInBinary;
{
std::ifstream is("test.bin", ios::binary);
cereal::BinaryInputArchive iarchive(is);
iarchive(testInBinary);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
可能值得注意的是,在 Dropbox 上的示例代码中,当您编写 .bin 文件时,构造函数ios::binary上也缺少标志:ofstream
/// Produced by:
// {
// std::ofstream outFile(base + "_triangleCameraMatches.bin");
// cereal::BinaryOutputArchive oarchive(outFile);
// oarchive(m_triangleCameraMatches);
// }
Run Code Online (Sandbox Code Playgroud)
设置标志可能值得尝试。希望有些帮助。
| 归档时间: |
|
| 查看次数: |
1082 次 |
| 最近记录: |