I try to send and receive a protobuf object by using Microsoft REST SDK. If you are not familiar with protobuf, imagine that it can be any other raw data. On the client side the vector is empty. I think that I do not create correctly the streams on the server side.
The get method of the server looks like this:
void MyServer::handle_get(http_request message)
{
// a class created with protobuf
ns::user *user = new ns::user();
ns::user->set_id(-1);
ns::user->set_name("Dark");
ns::user->set_email("[email protected]");
// this schould be fine
int size = user->ByteSize();
void *buffer = malloc(size);
user->SerializeToArray(buffer, size);
// how to do?
concurrency::streams::container_buffer<std::vector<char>> inBuffer;
concurrency::streams::istream bodyStream = message.body();
inBuffer.putn((char*)buffer, size);
Concurrency::task<size_t> read = bodyStream.read_to_end(inBuffer);
message.reply(status_codes::OK, bodyStream, size, L"application/octet-stream");
delete user;
};
The client method like this:
utility::ostringstream_t buf;
buf << "Dark" << "/" << "Foo" << "?" << "id=" << "1";
http_response response = CheckResponse("server/user", server.request(methods::GET, buf.str()).get());
if (response.status_code() == status_codes::OK)
{
cout << "STATUS OK" << endl;
Concurrency::streams::istream iStream = response.body();
auto rslt0 = response.extract_vector();
auto rslt = rslt0.get();
cout << "Result has size: <" << rslt.size() << ">" << endl;
for (unsigned int i = 0; i < rslt.size(); i++)
{
cout << "Data" << i << ": <" << rslt.at(i) << ">" << endl;
}
I answer my own question. There is no need for stream; I can use the binary data by this way:
Server:
Client: