Vanetza
 
Loading...
Searching...
No Matches
chunk_packet.hpp
1#ifndef CHUNK_PACKET_HPP_AT4GYSLD
2#define CHUNK_PACKET_HPP_AT4GYSLD
3
4#include <vanetza/common/byte_buffer_convertible.hpp>
5#include <vanetza/net/osi_layer.hpp>
6#include <cstddef>
7#include <map>
8
9namespace vanetza
10{
11
12/**
13 * \brief ChunckPacket is a packet consisting of several memory chunks
14 *
15 * ChunkPacket is the preferred packet type when it is getting assembled step by step.
16 * Each layer can easily add further bytes without caring about other layers at all.
17 */
19{
20public:
22
23 // copy semantics
25 ChunkPacket& operator=(const ChunkPacket&);
26
27 // move semantics
28 ChunkPacket(ChunkPacket&&) = default;
29 ChunkPacket& operator=(ChunkPacket&&) = default;
30
31 /**
32 * Access ByteBufferConvertible of specific layer
33 * \param layer ol Access this layer's data
34 * \return ByteBufferConvertible, might be empty
35 */
36 ByteBufferConvertible& layer(OsiLayer ol);
37 /** \copydoc ChunkPacket::layer */
38 const ByteBufferConvertible& layer(OsiLayer ol) const;
39
40 /** \copydoc ChunkPacket::layer */
41 inline ByteBufferConvertible& operator[](OsiLayer ol)
42 {
43 return layer(ol);
44 }
45
46 /** \copydoc ChunkPacket::layer */
47 inline const ByteBufferConvertible& operator[](OsiLayer ol) const
48 {
49 return layer(ol);
50 }
51
52 /**
53 * Get size of whole payload
54 * \return payload size in bytes
55 */
56 std::size_t size() const;
57
58 /**
59 * Get size of payload from specified layer range
60 * \param from start counting including this layer
61 * \param to stop counting including this layer
62 * \return payload size in bytes
63 */
64 std::size_t size(OsiLayer from, OsiLayer to) const;
65
66 /**
67 * Extract a range of layers from this packet to a new one.
68 * The respective layers of this ChunkPacket are empty afterwards.
69 * \param from start at this layer (inclusive)
70 * \param to stop at this layer (inclusive)
71 * \return new packet containing layers of specified range
72 */
73 ChunkPacket extract(OsiLayer from, OsiLayer to);
74
75 /**
76 * Merge layers from another packet
77 * \param packet source packet (layers will be moved from there)
78 * \param from start at this layer (inclusive)
79 * \param to stop at this layer (inclusive)
80 * \return reference to this packet
81 */
82 ChunkPacket& merge(ChunkPacket& packet, OsiLayer from, OsiLayer to);
83
84private:
85 typedef std::map<OsiLayer, ByteBufferConvertible> map_type;
86 map_type m_layers;
87};
88
89} // namespace vanetza
90
91#endif /* CHUNK_PACKET_HPP_AT4GYSLD */
92
ChunckPacket is a packet consisting of several memory chunks.
ByteBufferConvertible & operator[](OsiLayer ol)
ChunkPacket & merge(ChunkPacket &packet, OsiLayer from, OsiLayer to)
std::size_t size() const
const ByteBufferConvertible & operator[](OsiLayer ol) const
ByteBufferConvertible & layer(OsiLayer ol)
ChunkPacket extract(OsiLayer from, OsiLayer to)