1#ifndef OSI_LAYER_HPP_C4VTEZJP
2#define OSI_LAYER_HPP_C4VTEZJP
4#include <boost/range/iterator_range.hpp>
11enum class OsiLayer : uint8_t
22constexpr OsiLayer min_osi_layer() {
return OsiLayer::Physical; }
23constexpr OsiLayer max_osi_layer() {
return OsiLayer::Application; }
25constexpr std::array<OsiLayer, 7> osi_layers {{
31 OsiLayer::Presentation,
36
37
38
39
40
41constexpr int distance(OsiLayer from, OsiLayer to)
43 return static_cast<
int>(to) -
static_cast<
int>(from);
46constexpr std::size_t num_osi_layers(OsiLayer from, OsiLayer to)
48 return (from <= to ? distance(from, to) + 1 : 0);
51template<OsiLayer FROM, OsiLayer TO>
52std::array<OsiLayer, num_osi_layers(FROM, TO)> osi_layer_range()
54 static_assert(FROM <= TO,
"FROM layer is above TO layer");
55 typedef typename std::underlying_type<OsiLayer>::type num_type;
57 num_type num =
static_cast<num_type>(FROM);
58 std::array<OsiLayer, num_osi_layers(FROM, TO)> layers;
59 for (
auto& layer : layers) {
60 layer =
static_cast<OsiLayer>(num++);
65inline boost::iterator_range<
decltype(osi_layers)::const_iterator>
66osi_layer_range(OsiLayer from, OsiLayer to)
69 auto begin = osi_layers.cbegin() + distance(min_osi_layer(), from);
70 auto end = osi_layers.cend() - distance(to, max_osi_layer());
71 return boost::make_iterator_range(begin, end);
73 return boost::make_iterator_range(osi_layers.cend(), osi_layers.cend());
ChunckPacket is a packet consisting of several memory chunks.
ByteBufferConvertible & operator[](OsiLayer ol)
ChunkPacket & merge(ChunkPacket &packet, OsiLayer from, OsiLayer to)
const ByteBufferConvertible & layer(OsiLayer ol) const
const ByteBufferConvertible & operator[](OsiLayer ol) const
ByteBufferConvertible & layer(OsiLayer ol)
std::size_t size(OsiLayer from, OsiLayer to) const
ChunkPacket extract(OsiLayer from, OsiLayer to)
std::size_t size(OsiLayer from, OsiLayer to) const
std::size_t size(OsiLayer single_layer) const
value_type operator[](size_type) const
byte_view_range(ByteBuffer &&)
byte_view_range(const ByteBuffer::const_iterator &, const ByteBuffer::const_iterator &)
ByteBuffer::const_pointer data() const