Inconsistency in stream/streambuf size() (size_t or size64_t

Nov 20, 2013 at 11:18 PM
It would appear that ostream::write needs a size64_t... stream sizes are being returned in size64_t and taken as size_t.

Here's my example...
return  Concurrency::streams::file_stream<uint8_t>::open_ostream(fullname)
.then([=](Concurrency::streams::ostream stream)
     std::stringstream strstr;
     auto strx = Concurrency::streams::stringstream::open_istream(strstr.str());
     return stream.write(strx.streambuf(), static_cast<size_t>(strx.streambuf().size()));
Nov 21, 2013 at 12:49 AM
Hi evangineer,

Yes you are absolutely correct we have an inconsistency here! We probably should just be using size64_t throughout the streams library. We use size64_t to represent content length in our http library. We will fix this up for one of our next releases. In the meantime you can continue to utilize a cast like you have in your example.

Thanks for reporting the issue.
Nov 21, 2013 at 3:31 PM
As an aside... looking at the code in my initial post, is there an easier way to serialize a json::value to a concurrency::stream? The serialize method takes std::streams which explains the std::stringstream in the code.
Nov 21, 2013 at 5:54 PM
No we didn't originally include an overload for serializing or parsing to/from a concurrency::stream. We originally chose to do this because we didn't want to give the false appearance that we were actually asynchronously serializing/parsing in that case. If we had an overload that serialized synchronously even though given an asynchronous stream would that be valuable or match your expectations?

Even though we don't have an overload for concurrency::stream there is another feature that can accomplish exactly what you want. We have a set of streams for interop between the standard streams and our asynchronous streams in cpprest\interopstream.h. Using the concurrency::streams::async_ostream you code would look something like the following:
return concurrency::streams::file_stream::open_ostream(fullname)
.then([=](concurrency::streams::ostream stream)
    concurrency::streams::async_ostream interop_stream(stream);