I am using boost::asio::streambuf to write a ostream to my boost socket.
Name name;
name.set_name("platzhirsch");
boost::asio::streambuf b;
std::ostream os(&b);
ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os);
CodedOutputStream *coded_output = new CodedOutputStream(raw_output);
coded_output->WriteVarint32(name.ByteSize());
name.SerializeToCodedStream(coded_output);
socket.send(b.data());
However, size_t returned by send is 0. I am suspicious that no data is sent at all. Also because the client socket throws horrible exceptions. I am asking, if there is something strange about my code.
In other words, can I test if streambuf is empty or if the data written to it is really there.
Not sure about your code. This works for me:
It was no problem of boost::asio, it was a problem of Google protobuf.
In order to flush the CodedOutputStream, they have to be deleted: