Vinnie Falco
2014-06-29 15:53:00 UTC
I'm wrapping a C based HTTP parser up in a class interface and I want
to support parsing from ConstBufferSequence and ConstBuffers. But
there's nothing about this that technical "needs" asio. Except that I
am stuck bringing in asio just for buffer_cast and buffer_size. How
can I remove the dependence on asio? Here's the code in question:
https://github.com/ripple/rippled/blob/develop/src/beast/beast/http/message_parser.h#L120
Here's an excerpt of the relevant sections.
class parser
{
//...
/** Write data to the parser.
The return value includes the error code if any,
and the number of bytes consumed in the input sequence.
*/
std::pair <error_code, std::size_t>
write_one (void const* in, std::size_t bytes);
template <class ConstBuffer>
std::pair <error_code, std::size_t>
write_one (ConstBuffer const& buffer)
{
return write_one (boost::asio::buffer_cast <void const*> (buffer),
boost::asio::buffer_size (buffer));
}
template <class ConstBufferSequence>
std::pair <error_code, std::size_t>
write (ConstBufferSequence const& buffers)
{
std::pair <error_code, std::size_t> result (error_code(), 0);
for (auto const& buffer : buffers)
{
std::size_t bytes_consumed;
std::tie (result.first, bytes_consumed) = write_one (buffer);
if (result.first)
break;
result.second += bytes_consumed;
}
return result;
}
//...
};
to support parsing from ConstBufferSequence and ConstBuffers. But
there's nothing about this that technical "needs" asio. Except that I
am stuck bringing in asio just for buffer_cast and buffer_size. How
can I remove the dependence on asio? Here's the code in question:
https://github.com/ripple/rippled/blob/develop/src/beast/beast/http/message_parser.h#L120
Here's an excerpt of the relevant sections.
class parser
{
//...
/** Write data to the parser.
The return value includes the error code if any,
and the number of bytes consumed in the input sequence.
*/
std::pair <error_code, std::size_t>
write_one (void const* in, std::size_t bytes);
template <class ConstBuffer>
std::pair <error_code, std::size_t>
write_one (ConstBuffer const& buffer)
{
return write_one (boost::asio::buffer_cast <void const*> (buffer),
boost::asio::buffer_size (buffer));
}
template <class ConstBufferSequence>
std::pair <error_code, std::size_t>
write (ConstBufferSequence const& buffers)
{
std::pair <error_code, std::size_t> result (error_code(), 0);
for (auto const& buffer : buffers)
{
std::size_t bytes_consumed;
std::tie (result.first, bytes_consumed) = write_one (buffer);
if (result.first)
break;
result.second += bytes_consumed;
}
return result;
}
//...
};
--
Follow me on Github: https://github.com/vinniefalco
Follow me on Github: https://github.com/vinniefalco