0

我正在使用 Microsoft 的 cpprest sdk 通过 Internet 读取二进制数据。我下面的变量stream是类型concurrency::streams::istream。我正在尝试读取一百万行类型struct row并处理它们。我看到我没有得到我请求的所有字节。我怀疑有一种很好的编码方法,但我无法弄清楚。我还怀疑我从缓冲区中提取一行的强制转换不是正确的做事方式。任何帮助,将不胜感激。

struct row {
    unsigned long long tag_id : 32, day : 32;
    unsigned long long time;
    double value;
};

size_t row_count = 1000000;
concurrency::streams::container_buffer<vector<uint8_t>> buffer;
size_t bytes_requested = sizeof(row) * row_count;
size_t bytes_received = stream.read(buffer, bytes_requested).get();
// bytes_received does not always match bytes requested
for (size_t i = 0; i < row_count; ++i) {
    row &r = *(row *) &buffer.collection()[i * sizeof(row)];
    // do something with row here
}
4

0 回答 0