I am having trouble to make this line here right:
boost::asio::async_write(serialPort,
boost::asio::buffer(
boost::asio::buffer_cast<const void*>(vector_.front()),
boost::asio::buffer_size(vector_.front())))
vector_
holds a number of boost::asio::const_buffers
std::vector<boost::asio::const_buffer> vector_;
This stuff works, but I am quite sure that there is a way more elegant way to do this, and if not, I would like to here that from someone with a bit more experience.
So, can this solution be improved? If so, how?
I think you're looking for this:
boost::asio::async_write(serialPort, make_buffer(vector_.front()) );
where make_buffer
is defined as:
template<typename TBuffer>
boost::asio::buffer make_buffer(TBuffer & data)
{
auto buf = boost::asio::buffer_cast<const void*>(data);
auto size= boost::asio::buffer_size(data);
return boost::asio::buffer(buf, size);
}
which is a generic function by the way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With