0

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
}
Greg Clinton
  • 365
  • 1
  • 7
  • 18
  • Sdk is on GitHub at https://github.com/Microsoft/cpprestsdk – Brian Erickson Apr 07 '17 at 01:04
  • The documentation is a little vague. It says it will return up to bytes_requested, but doesn't say when it will return less. The only thing that seems to be guaranteed is that the task will hold the number zero if the end of the stream is reached. It's probably up to you to read again and stitch things together if you don't get as many bytes as you wanted. – Brian Erickson Apr 07 '17 at 01:44

0 Answers0