I'm using Microsoft's cpprest sdk to read binary data over the internet.
My variable stream
below is of type concurrency::streams::istream
. I'm trying to read a million rows of type struct row
and process them. I see that I don't get all the bytes I request. I suspect there is a good way of coding this but I haven't been able to figure it out. I also suspect that my casting to extract a row from the buffer is not the right way to do things. Any help would be appreciated.
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
}