7#if !defined(ASYNC_MQTT_PACKET_PACKET_ITERATOR_HPP)
8#define ASYNC_MQTT_PACKET_PACKET_ITERATOR_HPP
14#include <boost/asio/buffer.hpp>
15#include <boost/asio/buffers_iterator.hpp>
17#include <async_mqtt/buffer.hpp>
21namespace as = boost::asio;
23template <
template <
typename...>
typename Container,
typename Buffer>
24using packet_iterator = as::buffers_iterator<Container<Buffer>>;
26template <
template <
typename...>
typename Container,
typename Buffer>
27std::pair<packet_iterator<Container, Buffer>, packet_iterator<Container, Buffer>>
28make_packet_range(Container<Buffer>
const& cbs) {
30 packet_iterator<Container, Buffer>::begin(cbs),
31 packet_iterator<Container, Buffer>::end(cbs)
35template <
template <
typename...>
typename Container,
typename Buffer>
37to_string(Container<Buffer>
const& cbs) {
38 auto [b, e] = make_packet_range(cbs);
39 return std::string(b, e);
42template <
template <
typename...>
typename Container,
typename Buffer>
44to_buffer(Container<Buffer>
const& cbs) {
46 case 0:
return buffer{};
47 case 1:
return cbs.front();
49 auto [b, e] = make_packet_range(cbs);
50 return allocate_buffer(b, e);