I am writing an application using Boost asio in which the client and server exchange messages that are serialized using Google protobuffers. I do not know what size serialized message is sent over the network. It seems that proto-buf objects do not have a separator.
Here is the contents of the .proto file.
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
}
This is how I write from the server
tutorial::Person p;
p.set_name("abcd pqrs");
p.set_id(123456);
p.set_email("abcdpqrs@gmail.com");
write(p);
boost::asio::streambuf b;
std::ostream os(&b);
p.SerializeToOstream(&os);
boost::asio::async_write(socket_, b,
boost::bind(&Server::handle_write, this,
boost::asio::placeholders::error));
In the client, I read the message sent above using boost :: asio :: async_read. How to find the value argas an argument to boost::asio::transfer_at_leastin the code below?
boost::asio::async_read(socket_, response_,
boost::asio::transfer_at_least(arg),
boost::bind(&Client::handle_read_header, this,
boost::asio::placeholders::error));
Or how can I make sure boost :: async_read is returned after reading the entire object?
source
share